Exemplo n.º 1
0
 public override void MouseMove(CameraState state, Vector2 delta)
 {
     var mouse = Mouse.GetState();
     if (mouse.IsButtonDown(MouseButton.Left))
     {
         HandleFreeLook(state, delta);
     }
 }
Exemplo n.º 2
0
 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;
 }
Exemplo 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();
     }
 }
Exemplo 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;
 }
Exemplo 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;
 }
Exemplo 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);
     }
 }
Exemplo n.º 7
0
 public virtual void UpdateFrame(CameraState state, float step)
 {
 }
Exemplo n.º 8
0
 public virtual void MouseWheelChanged(CameraState state, float delta)
 {
 }
Exemplo n.º 9
0
 public virtual void MouseMove(CameraState state, Vector2 delta)
 {
 }
Exemplo n.º 10
0
 public virtual void Initialize(CameraState state)
 {
 }
Exemplo n.º 11
0
 public Camera()
 {
     State = new CameraState();
     DefaultState = new CameraState();
 }
Exemplo n.º 12
0
 protected void UpdateDistance(CameraState state, float scale)
 {
     state.Position = Origin - (state.Position - Origin).Length * (1 + scale) * state.LookAt;
 }
Exemplo n.º 13
0
 public override void MouseWheelChanged(CameraState state, float delta)
 {
     if (delta > 100) delta = 100;
     UpdateDistance(state, -delta);
 }
Exemplo n.º 14
0
 public override void Initialize(CameraState state)
 {
     // recalculate look at direction
     state.LookAt = Origin - state.Position;
     state.LookAt.Normalize();
 }