forked from bepu/bepuphysics1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FixedOffsetCameraControlScheme.cs
61 lines (48 loc) · 2.19 KB
/
FixedOffsetCameraControlScheme.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using BEPUphysics.Entities;
using BEPUutilities;
namespace BEPUphysicsDemos
{
public class FixedOffsetCameraControlScheme : CameraControlScheme
{
/// <summary>
/// Gets or sets the offset from the position of the entity to the camera.
/// </summary>
public Vector3 CameraOffset { get; set; }
/// <summary>
/// Gets the character associated with the control scheme.
/// </summary>
public Entity Entity { get; private set; }
/// <summary>
/// Gets or sets whether or not to smooth the motion of the camera when the character moves discontinuously.
/// </summary>
public bool UseCameraSmoothing { get; set; }
public FixedOffsetCameraControlScheme(Entity entity, Camera camera, DemosGame game)
: base(camera, game)
{
Entity = entity;
UseCameraSmoothing = true;
CameraOffset = new Vector3(0, 0.7f, 0);
}
public override void Update(float dt)
{
base.Update(dt);
////Rotate the camera of the character based on the support velocity, if a support with velocity exists.
////This can be very disorienting in some cases; that's why it is off by default!
//if (Character.SupportFinder.HasSupport)
//{
// SupportData? data;
// if (Character.SupportFinder.HasTraction)
// data = Character.SupportFinder.TractionData;
// else
// data = Character.SupportFinder.SupportData;
// var support = data.Value.SupportObject as EntityCollidable;
// if (support != null && !support.Entity.IsDynamic) //Having the view turned by dynamic entities is extremely confusing for the most part.
// {
// float dot = Vector3.Dot(support.Entity.AngularVelocity, Character.Body.OrientationMatrix.Up);
// Camera.Yaw(dot * dt);
// }
//}
Camera.Position = Entity.Position + Matrix3x3.Transform(CameraOffset, Entity.OrientationMatrix);
}
}
}