Esempio n. 1
0
 public override void MouseMove(CameraState state, Vector2 delta)
 {
     var mouse = Mouse.GetState();
     if (mouse.IsButtonDown(MouseButton.Left))
     {
         HandleFreeLook(state, delta);
     }
 }
 public override void UpdateFrame(CameraState state, float step)
 {
     base.UpdateFrame(state, step);
     // update the up direction to always point away from the alignment point
     var up = state.Position - AlignmentPoint;
     up.Normalize();
     // if the angle between the old and new up directions is larger than 90°
     // we assume that the camera is upside down and keep it that way
     state.Up = Vector3.Dot(state.Up, up) < 0 ? -up : up;
 }
Esempio n. 3
0
 public override void MouseMove(CameraState state, Vector2 delta)
 {
     var mouse = Mouse.GetState();
     if (mouse.IsButtonDown(MouseButton.Left))
     {
         base.MouseMove(state, delta);
         var leftRight = Vector3.Cross(state.Up, state.LookAt);
         Vector3.Cross(ref state.LookAt, ref leftRight, out state.Up);
         state.Up.Normalize();
     }
 }
Esempio n. 4
0
 /// <summary>
 /// TODO: add possibility to limit the pitch and prevent "flipping over"
 /// </summary>
 protected void HandleFreeLook(CameraState state, Vector2 delta)
 {
     var leftRight = Vector3.Cross(state.Up, state.LookAt);
     var forward = Vector3.Cross(leftRight, state.Up);
     // rotate look at direction
     var rot = Matrix4.CreateFromAxisAngle(state.Up, -delta.X) * Matrix4.CreateFromAxisAngle(leftRight, delta.Y);
     Vector3.Transform(ref state.LookAt, ref rot, out state.LookAt);
     // renormalize to prevent summing up of floating point errors
     state.LookAt.Normalize();
     // flip up vector when pitched more than +/-90° from the forward direction
     if (Vector3.Dot(state.LookAt, forward) < 0) state.Up *= -1;
 }
Esempio n. 5
0
 public override void UpdateFrame(CameraState state, float step)
 {
     var keyboard = Keyboard.GetState();
     var dir = Vector3.Zero;
     var leftRight = Vector3.Cross(state.Up, state.LookAt).Normalized();
     if (keyboard.IsKeyDown(Key.W)) dir += state.LookAt;
     if (keyboard.IsKeyDown(Key.S)) dir -= state.LookAt;
     if (keyboard.IsKeyDown(Key.A)) dir += leftRight;
     if (keyboard.IsKeyDown(Key.D)) dir -= leftRight;
     if (keyboard.IsKeyDown(Key.Space)) dir += state.Up;
     if (keyboard.IsKeyDown(Key.LControl)) dir -= state.Up;
     // normalize dir to enforce consistent movement speed, independent of the number of keys pressed
     if (dir.LengthSquared > 0) state.Position += dir.Normalized() * step;
 }
Esempio n. 6
0
 public override void MouseMove(CameraState state, Vector2 delta)
 {
     var mouse = Mouse.GetState();
     if (mouse.IsButtonDown(MouseButton.Left))
     {
         // rotate look direction with mouse
         HandleFreeLook(state, delta);
         // recalculate the position
         UpdateDistance(state, 0);
     }
     if (mouse.IsButtonDown(MouseButton.Right))
     {
         UpdateDistance(state, delta.Y);
     }
 }
Esempio n. 7
0
 public virtual void UpdateFrame(CameraState state, float step)
 {
 }
Esempio n. 8
0
 public virtual void MouseWheelChanged(CameraState state, float delta)
 {
 }
Esempio n. 9
0
 public virtual void MouseMove(CameraState state, Vector2 delta)
 {
 }
Esempio n. 10
0
 public virtual void Initialize(CameraState state)
 {
 }
Esempio n. 11
0
 public Camera()
 {
     State = new CameraState();
     DefaultState = new CameraState();
 }
Esempio n. 12
0
 protected void UpdateDistance(CameraState state, float scale)
 {
     state.Position = Origin - (state.Position - Origin).Length * (1 + scale) * state.LookAt;
 }
Esempio n. 13
0
 public override void MouseWheelChanged(CameraState state, float delta)
 {
     if (delta > 100) delta = 100;
     UpdateDistance(state, -delta);
 }
Esempio n. 14
0
 public override void Initialize(CameraState state)
 {
     // recalculate look at direction
     state.LookAt = Origin - state.Position;
     state.LookAt.Normalize();
 }