Ejemplo n.º 1
0
        public void OverheadUpdate(DwarfTime time, ChunkManager chunks, float diffPhi, float diffTheta, float diffRadius)
        {
            Vector3 forward = (Target - Position);

            forward.Normalize();
            Vector3 right = Vector3.Cross(forward, UpVector);
            Vector3 up    = Vector3.Cross(right, forward);

            right.Normalize();
            up.Normalize();
            MouseState    mouse  = Mouse.GetState();
            KeyboardState keys   = Keyboard.GetState();
            var           bounds = new BoundingBox(World.ChunkManager.Bounds.Min, World.ChunkManager.Bounds.Max + Vector3.UnitY * 20).Expand(VoxelConstants.ChunkSizeX * 8);

            if (ZoomTargets.Count > 0)
            {
                var target = ZoomTargets.First();
                var tVoxel = World.ChunkManager.CreateVoxelHandle(GlobalVoxelCoordinate.FromVector3(target));

                if (tVoxel.IsValid && tVoxel.Coordinate.Y > World.Renderer.PersistentSettings.MaxViewingLevel) // Unslice to make it visible.
                {
                    World.Renderer.SetMaxViewingLevel(tVoxel.Coordinate.Y + 1);
                }
                else
                {
                    var skyVoxel = World.ChunkManager.CreateVoxelHandle(new GlobalVoxelCoordinate(tVoxel.Coordinate.X, World.WorldSizeInVoxels.Y - 1, tVoxel.Coordinate.Z));
                    var sVoxel   = VoxelHelpers.FindFirstVoxelBelow(skyVoxel);

                    if (tVoxel.Coordinate.Y < sVoxel.Coordinate.Y) // Zooming below the surface - slice.
                    {
                        World.Renderer.SetMaxViewingLevel(tVoxel.Coordinate.Y + 1);
                    }
                }

                var currTarget = MathFunctions.Clamp(ProjectToSurface(ZoomTargets.First()), bounds);

                if (MathFunctions.Dist2D(Target, currTarget) > 5 && _zoomTime < 3)
                {
                    Vector3 newTarget = 0.8f * Target + 0.2f * currTarget;
                    Vector3 d         = newTarget - Target;
                    if (bounds.Contains(Target + d) != ContainmentType.Contains)
                    {
                        _zoomTime = 0;
                        ZoomTargets.RemoveAt(0);
                    }
                    else
                    {
                        Target    += d;
                        Position  += d;
                        _zoomTime += (float)time.ElapsedRealTime.TotalSeconds;
                    }
                }
                else
                {
                    _zoomTime = 0;
                    ZoomTargets.RemoveAt(0);
                }
            }

            Target = MathFunctions.Clamp(Target, bounds);
            int edgePadding = -10000;

            if (GameSettings.Current.EnableEdgeScroll)
            {
                edgePadding = 100;
            }

            float diffX, diffY = 0;
            float dt = (float)time.ElapsedRealTime.TotalSeconds;

            SnapToBounds(bounds);
            if (KeyManager.RotationEnabled(this))
            {
                World.UserInterface.Gui.MouseVisible = false;
                if (!shiftPressed)
                {
                    shiftPressed   = true;
                    mouseOnRotate  = new Point(mouse.X, mouse.Y);
                    mousePrerotate = new Point(mouse.X, mouse.Y);
                }

                if (!isLeftPressed && mouse.LeftButton == ButtonState.Pressed)
                {
                    isLeftPressed = true;
                }
                else if (mouse.LeftButton == ButtonState.Released)
                {
                    isLeftPressed = false;
                }

                if (!isRightPressed && mouse.RightButton == ButtonState.Pressed)
                {
                    isRightPressed = true;
                }
                else if (mouse.RightButton == ButtonState.Released)
                {
                    isRightPressed = false;
                }

                Mouse.SetPosition(mouseOnRotate.X, mouseOnRotate.Y);

                diffX = mouse.X - mouseOnRotate.X;
                diffY = mouse.Y - mouseOnRotate.Y;


                if (!isRightPressed)
                {
                    float filterDiffX = (float)(diffX * dt);
                    float filterDiffY = (float)(diffY * dt);

                    diffTheta = (filterDiffX);
                    diffPhi   = -(filterDiffY);
                }
                KeyManager.TrueMousePos = mousePrerotate;
            }
            else
            {
                if (shiftPressed)
                {
                    Mouse.SetPosition(mousePrerotate.X, mousePrerotate.Y);
                    KeyManager.TrueMousePos = new Point(mousePrerotate.X, mousePrerotate.Y);
                }
                else
                {
                    KeyManager.TrueMousePos = new Point(mouse.X, mouse.Y);
                }
                shiftPressed = false;
                World.UserInterface.Gui.MouseVisible = true;
            }

            Vector3 velocityToSet = Vector3.Zero;

            //if (EnableControl)
            {
                if (keys.IsKeyDown(ControlSettings.Mappings.Forward) || keys.IsKeyDown(Keys.Up))
                {
                    Vector3 mov = forward;
                    mov.Y = 0;
                    mov.Normalize();
                    velocityToSet += mov * CameraMoveSpeed * dt;
                }
                else if (keys.IsKeyDown(ControlSettings.Mappings.Back) || keys.IsKeyDown(Keys.Down))
                {
                    Vector3 mov = forward;
                    mov.Y = 0;
                    mov.Normalize();
                    velocityToSet += -mov * CameraMoveSpeed * dt;
                }

                if (keys.IsKeyDown(ControlSettings.Mappings.Left) || keys.IsKeyDown(Keys.Left))
                {
                    Vector3 mov = right;
                    mov.Y = 0;
                    mov.Normalize();
                    velocityToSet += -mov * CameraMoveSpeed * dt;
                }
                else if (keys.IsKeyDown(ControlSettings.Mappings.Right) || keys.IsKeyDown(Keys.Right))
                {
                    Vector3 mov = right;
                    mov.Y = 0;
                    mov.Normalize();
                    velocityToSet += mov * CameraMoveSpeed * dt;
                }
            }
            //else
            if (FollowAutoTarget)
            {
                Vector3 prevTarget = Target;
                float   damper     = MathFunctions.Clamp((Target - AutoTarget).Length() - 5, 0, 1);
                float   smooth     = 0.1f * damper;
                Target    = AutoTarget * (smooth) + Target * (1.0f - smooth);
                Position += (Target - prevTarget);
            }

            if (velocityToSet.LengthSquared() > 0)
            {
                World.Tutorial("camera");
                Velocity = velocityToSet;
            }


            if (!KeyManager.RotationEnabled(this))
            {
                if (!World.UserInterface.IsMouseOverGui)
                {
                    if (mouse.X < edgePadding || mouse.X > GameState.Game.GraphicsDevice.Viewport.Width - edgePadding)
                    {
                        moveTimer.Update(time);
                        if (moveTimer.HasTriggered)
                        {
                            float dir = 0.0f;

                            if (mouse.X < edgePadding)
                            {
                                dir = edgePadding - mouse.X;
                            }
                            else
                            {
                                dir = (GameState.Game.GraphicsDevice.Viewport.Width - edgePadding) - mouse.X;
                            }

                            dir *= 0.01f;
                            Vector3 delta = right * CameraMoveSpeed * dir * dt;
                            delta.Y  = 0;
                            Velocity = -delta;
                        }
                    }
                    else if (mouse.Y < edgePadding ||
                             mouse.Y > GameState.Game.GraphicsDevice.Viewport.Height - edgePadding)
                    {
                        moveTimer.Update(time);
                        if (moveTimer.HasTriggered)
                        {
                            float dir = 0.0f;

                            if (mouse.Y < edgePadding)
                            {
                                dir = -(edgePadding - mouse.Y);
                            }
                            else
                            {
                                dir = -((GameState.Game.GraphicsDevice.Viewport.Height - edgePadding) - mouse.Y);
                            }

                            dir *= 0.01f;

                            Vector3 delta = up * CameraMoveSpeed * dir * dt;
                            delta.Y  = 0;
                            Velocity = -delta;
                        }
                    }
                    else
                    {
                        moveTimer.Reset(moveTimer.TargetTimeSeconds);
                    }
                }
            }

            int scroll = mouse.ScrollWheelValue;

            if (isRightPressed && KeyManager.RotationEnabled(this))
            {
                scroll = (int)(diffY * 10) + LastWheel;
            }

            if (scroll != LastWheel && !World.UserInterface.IsMouseOverGui)
            {
                int change = scroll - LastWheel;

                if (!(keys.IsKeyDown(Keys.LeftAlt) || keys.IsKeyDown(Keys.RightAlt)))
                {
                    if (!keys.IsKeyDown(Keys.LeftControl))
                    {
                        var delta = change * -1;

                        if (GameSettings.Current.InvertZoom)
                        {
                            delta *= -1;
                        }

                        diffRadius = delta * CameraZoomSpeed * dt;

                        if (diffRadius < 0 && !FollowAutoTarget && GameSettings.Current.ZoomCameraTowardMouse && !shiftPressed)
                        {
                            float diffxy =
                                (new Vector3(Target.X, 0, Target.Z) -
                                 new Vector3(World.Renderer.CursorLightPos.X, 0, World.Renderer.CursorLightPos.Z)).Length();

                            if (diffxy > 5)
                            {
                                Vector3 slewTarget = Target * 0.9f + World.Renderer.CursorLightPos * 0.1f;
                                Vector3 slewDiff   = slewTarget - Target;
                                Target   += slewDiff;
                                Position += slewDiff;
                            }
                        }
                    }
                    else
                    {
                        World.Renderer.SetMaxViewingLevel(World.Renderer.PersistentSettings.MaxViewingLevel + (int)((float)change * 0.01f));
                    }
                }
            }

            LastWheel = mouse.ScrollWheelValue;

            if (!CollidesWithChunks(World.ChunkManager, Position + Velocity, false, false, 0.5f, 1.0f))
            {
                MoveTarget(Velocity);
                PushVelocity = Vector3.Zero;
            }
            else
            {
                PushVelocity += Vector3.Up * 0.1f;
                Position     += PushVelocity;
            }


            Velocity *= 0.8f;
            UpdateBasisVectors();

            bool    projectTarget   = GameSettings.Current.CameraFollowSurface || (!GameSettings.Current.CameraFollowSurface && (keys.IsKeyDown(Keys.LeftControl) || keys.IsKeyDown(Keys.RightControl)));
            Vector3 projectedTarget = projectTarget ? ProjectToSurface(Target) : Target;
            Vector3 diffTarget      = projectedTarget - Target;

            if (diffTarget.LengthSquared() > 25)
            {
                diffTarget.Normalize();
                diffTarget *= 5;
            }
            Position = (Position + diffTarget) * 0.05f + Position * 0.95f;
            Target   = (Target + diffTarget) * 0.05f + Target * 0.95f;
            float currRadius = (Position - Target).Length();
            float newRadius  = Math.Max(currRadius + diffRadius, 3.0f);

            Position = MathFunctions.ProjectOutOfHalfPlane(MathFunctions.ProjectOutOfCylinder(MathFunctions.ProjectToSphere(Position - right * diffTheta * 2 - up * diffPhi * 2, newRadius, Target), Target, 3.0f), Target, 2.0f);
            UpdateViewMatrix();
        }
Ejemplo n.º 2
0
 public bool IsCameraRotationModeActive()
 {
     return(KeyManager.RotationEnabled(World.Camera));
 }
Ejemplo n.º 3
0
        public void OverheadUpdate(DwarfTime time, ChunkManager chunks)
        {
            // Don't attempt any camera control if the user is trying to type intoa focus item.
            if (World.Gui.FocusItem != null && !World.Gui.FocusItem.IsAnyParentTransparent() && !World.Gui.FocusItem.IsAnyParentHidden())
            {
                return;
            }
            float   diffPhi    = 0;
            float   diffTheta  = 0;
            float   diffRadius = 0;
            Vector3 forward    = (Target - Position);

            forward.Normalize();
            Vector3 right = Vector3.Cross(forward, UpVector);
            Vector3 up    = Vector3.Cross(right, forward);

            right.Normalize();
            up.Normalize();
            MouseState    mouse  = Mouse.GetState();
            KeyboardState keys   = Keyboard.GetState();
            var           bounds = new BoundingBox(World.ChunkManager.Bounds.Min, World.ChunkManager.Bounds.Max + Vector3.UnitY * 20);

            if (ZoomTargets.Count > 0)
            {
                Vector3 currTarget = MathFunctions.Clamp(ProjectToSurface(ZoomTargets.First()), bounds);
                if (Vector3.DistanceSquared(Target, currTarget) > 5)
                {
                    Vector3 newTarget = 0.8f * Target + 0.2f * currTarget;
                    Vector3 d         = newTarget - Target;
                    if (bounds.Contains(Target + d) != ContainmentType.Contains)
                    {
                        ZoomTargets.RemoveAt(0);
                    }
                    else
                    {
                        Target   += d;
                        Position += d;
                    }
                }
                else
                {
                    ZoomTargets.RemoveAt(0);
                }
            }

            Target = MathFunctions.Clamp(Target, bounds);

            int edgePadding = -10000;

            if (GameSettings.Default.EnableEdgeScroll)
            {
                edgePadding = 100;
            }

            float diffX, diffY = 0;
            float dt = (float)time.ElapsedRealTime.TotalSeconds;

            SnapToBounds(new BoundingBox(World.ChunkManager.Bounds.Min, World.ChunkManager.Bounds.Max + Vector3.UnitY * 20));
            if (KeyManager.RotationEnabled(this))
            {
                World.Gui.MouseVisible = false;
                if (!shiftPressed)
                {
                    shiftPressed   = true;
                    mouseOnRotate  = new Point(mouse.X, mouse.Y);
                    mousePrerotate = new Point(mouse.X, mouse.Y);
                }

                if (!isLeftPressed && mouse.LeftButton == ButtonState.Pressed)
                {
                    isLeftPressed = true;
                }
                else if (mouse.LeftButton == ButtonState.Released)
                {
                    isLeftPressed = false;
                }

                if (!isRightPressed && mouse.RightButton == ButtonState.Pressed)
                {
                    isRightPressed = true;
                }
                else if (mouse.RightButton == ButtonState.Released)
                {
                    isRightPressed = false;
                }

                Mouse.SetPosition(mouseOnRotate.X, mouseOnRotate.Y);

                diffX = mouse.X - mouseOnRotate.X;
                diffY = mouse.Y - mouseOnRotate.Y;


                if (!isRightPressed)
                {
                    float filterDiffX = (float)(diffX * dt);
                    float filterDiffY = (float)(diffY * dt);

                    diffTheta = (filterDiffX);
                    diffPhi   = -(filterDiffY);
                }
                KeyManager.TrueMousePos = mousePrerotate;
            }
            else
            {
                if (shiftPressed)
                {
                    Mouse.SetPosition(mousePrerotate.X, mousePrerotate.Y);
                    KeyManager.TrueMousePos = new Point(mousePrerotate.X, mousePrerotate.Y);
                }
                else
                {
                    KeyManager.TrueMousePos = new Point(mouse.X, mouse.Y);
                }
                shiftPressed           = false;
                World.Gui.MouseVisible = true;
            }

            Vector3 velocityToSet = Vector3.Zero;

            if (EnableControl)
            {
                if (keys.IsKeyDown(ControlSettings.Mappings.Forward) || keys.IsKeyDown(Keys.Up))
                {
                    Vector3 mov = forward;
                    mov.Y = 0;
                    mov.Normalize();
                    velocityToSet += mov * CameraMoveSpeed * dt;
                }
                else if (keys.IsKeyDown(ControlSettings.Mappings.Back) || keys.IsKeyDown(Keys.Down))
                {
                    Vector3 mov = forward;
                    mov.Y = 0;
                    mov.Normalize();
                    velocityToSet += -mov * CameraMoveSpeed * dt;
                }

                if (keys.IsKeyDown(ControlSettings.Mappings.Left) || keys.IsKeyDown(Keys.Left))
                {
                    Vector3 mov = right;
                    mov.Y = 0;
                    mov.Normalize();
                    velocityToSet += -mov * CameraMoveSpeed * dt;
                }
                else if (keys.IsKeyDown(ControlSettings.Mappings.Right) || keys.IsKeyDown(Keys.Right))
                {
                    Vector3 mov = right;
                    mov.Y = 0;
                    mov.Normalize();
                    velocityToSet += mov * CameraMoveSpeed * dt;
                }
            }
            else if (FollowAutoTarget)
            {
                Vector3 prevTarget = Target;
                float   damper     = MathFunctions.Clamp((Target - AutoTarget).Length() - 5, 0, 1);
                float   smooth     = 0.1f * damper;
                Target    = AutoTarget * (smooth) + Target * (1.0f - smooth);
                Position += (Target - prevTarget);
            }

            if (velocityToSet.LengthSquared() > 0)
            {
                World.Tutorial("camera");
                Velocity = velocityToSet;
            }


            if (!KeyManager.RotationEnabled(this))
            {
                if (!World.IsMouseOverGui)
                {
                    if (mouse.X < edgePadding || mouse.X > GameState.Game.GraphicsDevice.Viewport.Width - edgePadding)
                    {
                        moveTimer.Update(time);
                        if (moveTimer.HasTriggered)
                        {
                            float dir = 0.0f;

                            if (mouse.X < edgePadding)
                            {
                                dir = edgePadding - mouse.X;
                            }
                            else
                            {
                                dir = (GameState.Game.GraphicsDevice.Viewport.Width - edgePadding) - mouse.X;
                            }

                            dir *= 0.01f;
                            Vector3 delta = right * CameraMoveSpeed * dir * dt;
                            delta.Y  = 0;
                            Velocity = -delta;
                        }
                    }
                    else if (mouse.Y < edgePadding ||
                             mouse.Y > GameState.Game.GraphicsDevice.Viewport.Height - edgePadding)
                    {
                        moveTimer.Update(time);
                        if (moveTimer.HasTriggered)
                        {
                            float dir = 0.0f;

                            if (mouse.Y < edgePadding)
                            {
                                dir = -(edgePadding - mouse.Y);
                            }
                            else
                            {
                                dir = -((GameState.Game.GraphicsDevice.Viewport.Height - edgePadding) - mouse.Y);
                            }

                            dir *= 0.01f;

                            Vector3 delta = up * CameraMoveSpeed * dir * dt;
                            delta.Y  = 0;
                            Velocity = -delta;
                        }
                    }
                    else
                    {
                        moveTimer.Reset(moveTimer.TargetTimeSeconds);
                    }
                }
            }

            int scroll = mouse.ScrollWheelValue;

            if (isRightPressed && KeyManager.RotationEnabled(this))
            {
                scroll = (int)(diffY * 10) + LastWheel;
            }

            if (scroll != LastWheel && !World.IsMouseOverGui)
            {
                int change = scroll - LastWheel;

                if (!(keys.IsKeyDown(Keys.LeftAlt) || keys.IsKeyDown(Keys.RightAlt)))
                {
                    if (!keys.IsKeyDown(Keys.LeftControl))
                    {
                        var delta = change * -1;

                        if (GameSettings.Default.InvertZoom)
                        {
                            delta *= -1;
                        }

                        diffRadius = delta * CameraZoomSpeed * dt;

                        if (diffRadius < 0 && !FollowAutoTarget && GameSettings.Default.ZoomCameraTowardMouse && !shiftPressed)
                        {
                            float diffxy =
                                (new Vector3(Target.X, 0, Target.Z) -
                                 new Vector3(World.CursorLightPos.X, 0, World.CursorLightPos.Z)).Length();

                            if (diffxy > 5)
                            {
                                Vector3 slewTarget = Target * 0.9f + World.CursorLightPos * 0.1f;
                                Vector3 slewDiff   = slewTarget - Target;
                                Target   += slewDiff;
                                Position += slewDiff;
                            }
                        }
                    }
                    else
                    {
                        World.Master.SetMaxViewingLevel(World.Master.MaxViewingLevel + (int)((float)change * 0.01f));
                    }
                }
            }

            LastWheel = mouse.ScrollWheelValue;

            if (!CollidesWithChunks(World.ChunkManager, Position + Velocity, false, false, 0.5f, 1.0f))
            {
                MoveTarget(Velocity);
                PushVelocity = Vector3.Zero;
            }
            else
            {
                PushVelocity += Vector3.Up * 0.1f;
                Position     += PushVelocity;
            }


            Velocity *= 0.8f;
            UpdateBasisVectors();
            Vector3 projectedTarget = GameSettings.Default.CameraFollowSurface ? ProjectToSurface(Target) : Target;

            if (!GameSettings.Default.CameraFollowSurface && (keys.IsKeyDown(Keys.LeftControl) || keys.IsKeyDown(Keys.RightControl)))
            {
                projectedTarget = ProjectToSurface(Target);
            }
            Vector3 diffTarget = projectedTarget - Target;

            Position = (Position + diffTarget) * 0.05f + Position * 0.95f;
            Target   = projectedTarget * 0.05f + Target * 0.95f;
            float currRadius = (Position - Target).Length();
            float newRadius  = Math.Max(currRadius + diffRadius, 3.0f);

            Position = MathFunctions.ProjectOutOfHalfPlane(MathFunctions.ProjectOutOfCylinder(MathFunctions.ProjectToSphere(Position - right * diffTheta * 2 - up * diffPhi * 2, newRadius, Target), Target, 3.0f), Target, 2.0f);
            UpdateViewMatrix();
        }
Ejemplo n.º 4
0
        public void WalkUpdate(DwarfTime time, ChunkManager chunks)
        {
            {
                var mouseState = Mouse.GetState();
                if (!GameState.Game.GraphicsDevice.Viewport.Bounds.Contains(mouseState.X, mouseState.Y))
                {
                    return;
                }
            }
            // Don't attempt any camera control if the user is trying to type intoa focus item.
            if (World.UserInterface.Gui.FocusItem != null && !World.UserInterface.Gui.FocusItem.IsAnyParentTransparent() && !World.UserInterface.Gui.FocusItem.IsAnyParentHidden())
            {
                return;
            }

            if (GameSettings.Current.FogofWar)
            {
                var currentCoordinate = GlobalVoxelCoordinate.FromVector3(Position);
                if (currentCoordinate != _prevVoxelCoord)
                {
                    VoxelHelpers.RadiusReveal(chunks, new VoxelHandle(chunks, currentCoordinate), 10);
                    _prevVoxelCoord = currentCoordinate;
                }
            }

            float   diffPhi   = 0;
            float   diffTheta = 0;
            Vector3 forward   = (Target - Position);

            forward.Normalize();
            Vector3 right = Vector3.Cross(forward, UpVector);
            Vector3 up    = Vector3.Cross(right, forward);

            right.Normalize();
            up.Normalize();
            MouseState    mouse  = Mouse.GetState();
            KeyboardState keys   = Keyboard.GetState();
            var           bounds = new BoundingBox(World.ChunkManager.Bounds.Min, World.ChunkManager.Bounds.Max + Vector3.UnitY * 20);

            ZoomTargets.Clear();

            Target = MathFunctions.Clamp(Target, bounds);

            float diffX, diffY = 0;
            float dt = (float)time.ElapsedRealTime.TotalSeconds;

            SnapToBounds(new BoundingBox(World.ChunkManager.Bounds.Min, World.ChunkManager.Bounds.Max + Vector3.UnitY * 20));

            bool switchState = false;

            bool isAnyRotationKeyActive = keys.IsKeyDown(ControlSettings.Mappings.CameraMode) ||
                                          keys.IsKeyDown(Keys.RightShift) || Mouse.GetState().MiddleButton == ButtonState.Pressed;

            if (isAnyRotationKeyActive && !shiftPressed)
            {
                shiftPressed      = true;
                mouseOnRotate     = GameState.Game.GraphicsDevice.Viewport.Bounds.Center;
                mousePrerotate    = new Point(mouse.X, mouse.Y);
                switchState       = true;
                mouseActiveInWalk = !mouseActiveInWalk;
            }
            else if (!isAnyRotationKeyActive && shiftPressed)
            {
                shiftPressed = false;
            }

            if (shiftPressed)
            {
                Mouse.SetPosition(mousePrerotate.X, mousePrerotate.Y);
                KeyManager.TrueMousePos = new Point(mousePrerotate.X, mousePrerotate.Y);
            }
            else
            {
                KeyManager.TrueMousePos = new Point(mouse.X, mouse.Y);
            }

            if (KeyManager.RotationEnabled(this))
            {
                World.UserInterface.Gui.MouseVisible = false;
                Mouse.SetPosition(mouseOnRotate.X, mouseOnRotate.Y);

                if (!switchState)
                {
                    diffX = mouse.X - mouseOnRotate.X;
                    diffY = mouse.Y - mouseOnRotate.Y;
                }
                else
                {
                    diffX = 0;
                    diffY = 0;
                }

                if (!isLeftPressed && mouse.LeftButton == ButtonState.Pressed)
                {
                    isLeftPressed = true;
                }
                else if (mouse.LeftButton == ButtonState.Released)
                {
                    isLeftPressed = false;
                }

                if (!isRightPressed && mouse.RightButton == ButtonState.Pressed)
                {
                    isRightPressed = true;
                }
                else if (mouse.RightButton == ButtonState.Released)
                {
                    isRightPressed = false;
                }



                if (!isRightPressed)
                {
                    float filterDiffX = (float)(diffX * dt);
                    float filterDiffY = (float)(diffY * dt);

                    diffTheta = (filterDiffX);
                    diffPhi   = -(filterDiffY);
                }
                KeyManager.TrueMousePos = mousePrerotate;
            }
            else
            {
                World.UserInterface.Gui.MouseVisible = true;
            }

            Vector3 velocityToSet = Vector3.Zero;

            //if (EnableControl)
            {
                if (keys.IsKeyDown(ControlSettings.Mappings.Forward) || keys.IsKeyDown(Keys.Up))
                {
                    Vector3 mov = forward;
                    mov.Normalize();
                    velocityToSet += mov * CameraMoveSpeed;
                }
                else if (keys.IsKeyDown(ControlSettings.Mappings.Back) || keys.IsKeyDown(Keys.Down))
                {
                    Vector3 mov = forward;
                    mov.Normalize();
                    velocityToSet += -mov * CameraMoveSpeed;
                }

                if (keys.IsKeyDown(ControlSettings.Mappings.Left) || keys.IsKeyDown(Keys.Left))
                {
                    Vector3 mov = right;
                    mov.Normalize();
                    velocityToSet += -mov * CameraMoveSpeed;
                }
                else if (keys.IsKeyDown(ControlSettings.Mappings.Right) || keys.IsKeyDown(Keys.Right))
                {
                    Vector3 mov = right;
                    mov.Normalize();
                    velocityToSet += mov * CameraMoveSpeed;
                }
            }

            if (keys.IsKeyDown(ControlSettings.Mappings.Fly))
            {
                flyKeyPressed = true;
            }
            else
            {
                if (flyKeyPressed)
                {
                    flying = !flying;
                }
                flyKeyPressed = false;
            }

            if (velocityToSet.LengthSquared() > 0)
            {
                if (!flying)
                {
                    float y = Velocity.Y;
                    Velocity = Velocity * 0.5f + 0.5f * velocityToSet;
                    Velocity = new Vector3(Velocity.X, y, Velocity.Z);
                }
                else
                {
                    Velocity = Velocity * 0.5f + 0.5f * velocityToSet;
                }
            }


            LastWheel = mouse.ScrollWheelValue;
            float ymult = flying ? 0.9f : 1.0f;

            Velocity = new Vector3(Velocity.X * 0.9f, Velocity.Y * ymult, Velocity.Z * 0.9f);

            float subSteps      = 10.0f;
            float subStepLength = 1.0f / subSteps;

            crouched = false;
            for (int i = 0; i < subSteps; i++)
            {
                VoxelHandle currentVoxel = new VoxelHandle(World.ChunkManager, GlobalVoxelCoordinate.FromVector3(Position));

                var below = VoxelHelpers.GetNeighbor(currentVoxel, new GlobalVoxelOffset(0, -1, 0));
                var above = VoxelHelpers.GetNeighbor(currentVoxel, new GlobalVoxelOffset(0, 1, 0));
                if (above.IsValid && !above.IsEmpty)
                {
                    crouched = true;
                }

                if (!flying)
                {
                    if (!below.IsValid || below.IsEmpty)
                    {
                        Velocity += dt * Gravity * subStepLength;
                    }
                    else if (keys.IsKeyDown(ControlSettings.Mappings.Jump))
                    {
                        Velocity += -dt * Gravity * subStepLength * 4;
                    }

                    if (currentVoxel.IsValid && currentVoxel.LiquidLevel > 0)
                    {
                        Velocity += -dt * Gravity * subStepLength * 0.999f;

                        if (keys.IsKeyDown(ControlSettings.Mappings.Jump))
                        {
                            Velocity += -dt * Gravity * subStepLength * 0.5f;
                        }
                        Velocity *= 0.99f;
                    }
                }

                if (!CollidesWithChunks(World.ChunkManager, Position, true, true, 0.4f, 0.9f))
                {
                    MoveTarget(Velocity * dt * subStepLength);
                    PushVelocity = Vector3.Zero;
                }
                else
                {
                    MoveTarget(Velocity * dt * subStepLength);
                }
            }
            VoxelHandle voxelAfterMove = new VoxelHandle(World.ChunkManager, GlobalVoxelCoordinate.FromVector3(Position));

            if (voxelAfterMove.IsValid && !voxelAfterMove.IsEmpty)
            {
                float distCenter = (voxelAfterMove.GetBoundingBox().Center() - Position).Length();
                if (distCenter < 0.5f)
                {
                    float       closest      = float.MaxValue;
                    VoxelHandle closestVoxel = VoxelHandle.InvalidHandle;
                    foreach (var voxel in VoxelHelpers.EnumerateAllNeighbors(voxelAfterMove.Coordinate).Select(c => new VoxelHandle(World.ChunkManager, c)).Where(v => v.IsEmpty))
                    {
                        float d = (voxel.GetBoundingBox().Center() - Position).Length();
                        if (d < closest)
                        {
                            closest      = d;
                            closestVoxel = voxel;
                        }
                    }

                    if (closestVoxel.IsValid)
                    {
                        var newPosition = closestVoxel.GetBoundingBox().Center();
                        var diff        = (newPosition - Position);
                        MoveTarget(diff);
                    }
                }
            }

            Target += right * diffTheta * 0.1f;
            var newTarget  = up * diffPhi * 0.1f + Target;
            var newForward = (Target - Position);

            if (Math.Abs(Vector3.Dot(newForward, UpVector)) < 0.99f)
            {
                Target = newTarget;
            }
            var diffTarget = Target - Position;

            diffTarget.Normalize();
            Target = Position + diffTarget * 1.0f;


            UpdateBasisVectors();

            UpdateViewMatrix();
        }
Ejemplo n.º 5
0
        public void WalkUpdate(DwarfTime time, ChunkManager chunks)
        {
            // Don't attempt any camera control if the user is trying to type intoa focus item.
            if (World.Gui.FocusItem != null && !World.Gui.FocusItem.IsAnyParentTransparent() && !World.Gui.FocusItem.IsAnyParentHidden())
            {
                return;
            }
            float   diffPhi    = 0;
            float   diffTheta  = 0;
            float   diffRadius = 0;
            Vector3 forward    = (Target - Position);

            forward.Normalize();
            Vector3 right = Vector3.Cross(forward, UpVector);
            Vector3 up    = Vector3.Cross(right, forward);

            right.Normalize();
            up.Normalize();
            MouseState    mouse  = Mouse.GetState();
            KeyboardState keys   = Keyboard.GetState();
            var           bounds = new BoundingBox(World.ChunkManager.Bounds.Min, World.ChunkManager.Bounds.Max + Vector3.UnitY * 20);

            ZoomTargets.Clear();

            Target = MathFunctions.Clamp(Target, bounds);

            int edgePadding = -10000;

            if (GameSettings.Default.EnableEdgeScroll)
            {
                edgePadding = 100;
            }

            float diffX, diffY = 0;
            float dt = (float)time.ElapsedRealTime.TotalSeconds;

            SnapToBounds(new BoundingBox(World.ChunkManager.Bounds.Min, World.ChunkManager.Bounds.Max + Vector3.UnitY * 20));
            if (KeyManager.RotationEnabled(this))
            {
                World.Gui.MouseVisible = false;
                if (!shiftPressed)
                {
                    shiftPressed   = true;
                    mouseOnRotate  = new Point(mouse.X, mouse.Y);
                    mousePrerotate = new Point(mouse.X, mouse.Y);
                }

                if (!isLeftPressed && mouse.LeftButton == ButtonState.Pressed)
                {
                    isLeftPressed = true;
                }
                else if (mouse.LeftButton == ButtonState.Released)
                {
                    isLeftPressed = false;
                }

                if (!isRightPressed && mouse.RightButton == ButtonState.Pressed)
                {
                    isRightPressed = true;
                }
                else if (mouse.RightButton == ButtonState.Released)
                {
                    isRightPressed = false;
                }

                Mouse.SetPosition(mouseOnRotate.X, mouseOnRotate.Y);

                diffX = mouse.X - mouseOnRotate.X;
                diffY = mouse.Y - mouseOnRotate.Y;


                if (!isRightPressed)
                {
                    float filterDiffX = (float)(diffX * dt);
                    float filterDiffY = (float)(diffY * dt);

                    diffTheta = (filterDiffX);
                    diffPhi   = -(filterDiffY);
                }
                KeyManager.TrueMousePos = mousePrerotate;
            }
            else
            {
                if (shiftPressed)
                {
                    Mouse.SetPosition(mousePrerotate.X, mousePrerotate.Y);
                    KeyManager.TrueMousePos = new Point(mousePrerotate.X, mousePrerotate.Y);
                }
                else
                {
                    KeyManager.TrueMousePos = new Point(mouse.X, mouse.Y);
                }
                shiftPressed           = false;
                World.Gui.MouseVisible = true;
            }

            Vector3 velocityToSet = Vector3.Zero;

            if (EnableControl)
            {
                if (keys.IsKeyDown(ControlSettings.Mappings.Forward) || keys.IsKeyDown(Keys.Up))
                {
                    Vector3 mov = forward;
                    mov.Normalize();
                    velocityToSet += mov * CameraMoveSpeed;
                }
                else if (keys.IsKeyDown(ControlSettings.Mappings.Back) || keys.IsKeyDown(Keys.Down))
                {
                    Vector3 mov = forward;
                    mov.Normalize();
                    velocityToSet += -mov * CameraMoveSpeed;
                }

                if (keys.IsKeyDown(ControlSettings.Mappings.Left) || keys.IsKeyDown(Keys.Left))
                {
                    Vector3 mov = right;
                    mov.Normalize();
                    velocityToSet += -mov * CameraMoveSpeed;
                }
                else if (keys.IsKeyDown(ControlSettings.Mappings.Right) || keys.IsKeyDown(Keys.Right))
                {
                    Vector3 mov = right;
                    mov.Normalize();
                    velocityToSet += mov * CameraMoveSpeed;
                }
            }

            if (keys.IsKeyDown(ControlSettings.Mappings.Fly))
            {
                flyKeyPressed = true;
            }
            else
            {
                if (flyKeyPressed)
                {
                    flying = !flying;
                }
                flyKeyPressed = false;
            }

            if (velocityToSet.LengthSquared() > 0)
            {
                if (!flying)
                {
                    float y = Velocity.Y;
                    Velocity = Velocity * 0.5f + 0.5f * velocityToSet;
                    Velocity = new Vector3(Velocity.X, y, Velocity.Z);
                }
                else
                {
                    Velocity = Velocity * 0.5f + 0.5f * velocityToSet;
                }
            }


            LastWheel = mouse.ScrollWheelValue;
            float ymult = flying ? 0.9f : 1.0f;

            Velocity = new Vector3(Velocity.X * 0.9f, Velocity.Y * ymult, Velocity.Z * 0.9f);

            float subSteps      = 10.0f;
            float subStepLength = 1.0f / subSteps;

            crouched = false;
            for (int i = 0; i < subSteps; i++)
            {
                VoxelHandle currentVoxel = new VoxelHandle(World.ChunkManager.ChunkData, GlobalVoxelCoordinate.FromVector3(Position));

                var below = VoxelHelpers.GetNeighbor(currentVoxel, new GlobalVoxelOffset(0, -1, 0));
                var above = VoxelHelpers.GetNeighbor(currentVoxel, new GlobalVoxelOffset(0, 1, 0));
                if (above.IsValid && !above.IsEmpty)
                {
                    crouched = true;
                }

                if (!flying)
                {
                    if (!below.IsValid || below.IsEmpty)
                    {
                        Velocity += dt * Gravity * subStepLength;
                    }
                    else if (keys.IsKeyDown(ControlSettings.Mappings.Jump))
                    {
                        Velocity += -dt * Gravity * subStepLength * 4;
                    }

                    if (currentVoxel.IsValid && currentVoxel.LiquidLevel > 0)
                    {
                        Velocity += -dt * Gravity * subStepLength * 0.999f;

                        if (keys.IsKeyDown(ControlSettings.Mappings.Jump))
                        {
                            Velocity += -dt * Gravity * subStepLength * 0.5f;
                        }
                        Velocity *= 0.99f;
                    }
                }

                if (!CollidesWithChunks(World.ChunkManager, Position, true, true, 0.4f, 0.9f))
                {
                    MoveTarget(Velocity * dt * subStepLength);
                    PushVelocity = Vector3.Zero;
                }
                else
                {
                    MoveTarget(Velocity * dt * subStepLength);
                }
            }


            Target += right * diffTheta * 0.1f;
            Target += up * diffPhi * 0.1f;
            var diffTarget = Target - Position;

            diffTarget.Normalize();
            Target = Position + diffTarget * 1.0f;


            UpdateBasisVectors();

            UpdateViewMatrix();
        }
Ejemplo n.º 6
0
        public bool IsCameraRotationModeActive()
        {
            KeyboardState keyState = Keyboard.GetState();

            return(KeyManager.RotationEnabled());
        }
Ejemplo n.º 7
0
        void InputManager_MouseClickedCallback(InputManager.MouseButton button)
        {
            if (button != InputManager.MouseButton.Right || Player.CurrentTool != this || KeyManager.RotationEnabled(Player.World.Camera))
            {
                return;
            }

            var mouseState = KeyManager.TrueMousePos;

            var vox = VoxelHelpers.FindFirstVisibleVoxelOnScreenRay(
                Player.World.ChunkManager.ChunkData,
                mouseState.X, mouseState.Y,
                Player.World.Camera,
                GameState.Game.GraphicsDevice.Viewport,
                150.0f,
                false,
                voxel => voxel.IsValid && (!voxel.IsEmpty || voxel.LiquidLevel > 0));

            if (!vox.IsValid)
            {
                return;
            }

            foreach (CreatureAI minion in Player.SelectedMinions)
            {
                if (minion.Creature.IsAsleep)
                {
                    continue;
                }
                if (minion.CurrentTask != null)
                {
                    minion.AssignTask(minion.CurrentTask);
                }

                var above = VoxelHelpers.GetVoxelAbove(vox);
                minion.Blackboard.SetData("MoveTarget", above);

                minion.ChangeTask(new GoToNamedVoxelAct("MoveTarget", PlanAct.PlanType.Adjacent, minion).AsTask());
                minion.CurrentTask.AutoRetry = false;
                minion.CurrentTask.Priority  = Task.PriorityType.Urgent;
            }
            OnConfirm(Player.SelectedMinions);

            if (Player.SelectedMinions.Count > 0)
            {
                IndicatorManager.DrawIndicator(IndicatorManager.StandardIndicators.DownArrow, vox.WorldPosition + Vector3.One * 0.5f, 0.5f, 2.0f, new Vector2(0, -50), Color.LightGreen);
            }
        }
Ejemplo n.º 8
0
        public void OverheadUpdate(DwarfTime time, ChunkManager chunks)
        {
            MouseState    mouse = Mouse.GetState();
            KeyboardState keys  = Keyboard.GetState();

            if (ZoomTargets.Count > 0)
            {
                Vector3 currTarget = ZoomTargets.First();
                if (Vector3.DistanceSquared(Target, currTarget) > 5)
                {
                    Target = 0.8f * Target + 0.2f * currTarget;
                }
                else
                {
                    ZoomTargets.RemoveAt(0);
                }
            }

            int edgePadding = -10000;

            if (GameSettings.Default.EnableEdgeScroll)
            {
                edgePadding = 100;
            }

            bool  stateChanged = false;
            float dt           = (float)time.ElapsedRealTime.TotalSeconds;

            SnapToBounds(new BoundingBox(PlayState.ChunkManager.Bounds.Min, PlayState.ChunkManager.Bounds.Max + Vector3.UnitY * 20));
            if (KeyManager.RotationEnabled())
            {
                if (!shiftPressed)
                {
                    shiftPressed = true;

                    mouse        = Mouse.GetState();
                    stateChanged = true;
                }
                if (!isLeftPressed && mouse.LeftButton == ButtonState.Pressed)
                {
                    isLeftPressed = true;
                    stateChanged  = true;
                }
                else if (mouse.LeftButton == ButtonState.Released)
                {
                    isLeftPressed = false;
                }

                if (!isRightPressed && mouse.RightButton == ButtonState.Pressed)
                {
                    isRightPressed = true;
                    stateChanged   = true;
                }
                else if (mouse.RightButton == ButtonState.Released)
                {
                    isRightPressed = false;
                }


                if (stateChanged)
                {
                    Mouse.SetPosition(GameState.Game.GraphicsDevice.Viewport.Width / 2, GameState.Game.GraphicsDevice.Viewport.Height / 2);
                    mouse = Mouse.GetState();
                }


                float diffX = mouse.X - GameState.Game.GraphicsDevice.Viewport.Width / 2;
                float diffY = mouse.Y - GameState.Game.GraphicsDevice.Viewport.Height / 2;


                float filterDiffX = (float)(diffX * dt);
                float filterDiffY = (float)(diffY * dt);
                if (Math.Abs(filterDiffX) > 1.0f)
                {
                    filterDiffX = 1.0f * Math.Sign(filterDiffX);
                }

                if (Math.Abs(filterDiffY) > 1.0f)
                {
                    filterDiffY = 1.0f * Math.Sign(filterDiffY);
                }

                targetTheta = Theta - (filterDiffX);
                targetPhi   = Phi - (filterDiffY);
                Theta       = targetTheta * 0.5f + Theta * 0.5f;
                Phi         = targetPhi * 0.5f + Phi * 0.5f;

                if (Phi < -MathHelper.PiOver2)
                {
                    Phi = -MathHelper.PiOver2;
                }
                else if (Phi > MathHelper.PiOver2)
                {
                    Phi = MathHelper.PiOver2;
                }
            }
            else
            {
                shiftPressed = false;
            }

            bool    goingBackward = false;
            Vector3 velocityToSet = Vector3.Zero;

            if (keys.IsKeyDown(ControlSettings.Mappings.Forward) || keys.IsKeyDown(Keys.Up))
            {
                Vector3 forward = (Target - Position);
                forward.Normalize();

                if (!KeyManager.RotationEnabled())
                {
                    forward.Y = 0;
                }
                forward.Normalize();

                velocityToSet += forward * CameraMoveSpeed * dt;
            }
            else if (keys.IsKeyDown(ControlSettings.Mappings.Back) || keys.IsKeyDown(Keys.Down))
            {
                Vector3 forward = (Target - Position);
                forward.Normalize();
                goingBackward = true;

                if (!KeyManager.RotationEnabled())
                {
                    forward.Y = 0;
                }

                forward.Normalize();

                velocityToSet += -forward * CameraMoveSpeed * dt;
            }

            if (keys.IsKeyDown(ControlSettings.Mappings.Left) || keys.IsKeyDown(Keys.Left))
            {
                Vector3 forward = (Target - Position);
                forward.Normalize();
                Vector3 right = Vector3.Cross(forward, UpVector);
                right.Normalize();
                if (goingBackward)
                {
                    //right *= -1;
                }

                velocityToSet += -right * CameraMoveSpeed * dt;
            }
            else if (keys.IsKeyDown(ControlSettings.Mappings.Right) || keys.IsKeyDown(Keys.Right))
            {
                Vector3 forward = (Target - Position);
                forward.Normalize();
                Vector3 right = Vector3.Cross(forward, UpVector);
                right.Normalize();
                if (goingBackward)
                {
                    //right *= -1;
                }
                velocityToSet += right * CameraMoveSpeed * dt;
            }

            if (velocityToSet.LengthSquared() > 0)
            {
                Velocity = velocityToSet;
            }


            if (!KeyManager.RotationEnabled())
            {
                if (mouse.X < edgePadding || mouse.X > GameState.Game.GraphicsDevice.Viewport.Width - edgePadding)
                {
                    moveTimer.Update(time);
                    if (moveTimer.HasTriggered)
                    {
                        float dir = 0.0f;

                        if (mouse.X < edgePadding)
                        {
                            dir = edgePadding - mouse.X;
                        }
                        else
                        {
                            dir = (GameState.Game.GraphicsDevice.Viewport.Width - edgePadding) - mouse.X;
                        }

                        dir *= 0.05f;

                        Vector3 forward = (Target - Position);
                        forward.Normalize();
                        Vector3 right = Vector3.Cross(forward, UpVector);
                        Vector3 delta = right * CameraMoveSpeed * dir * dt;
                        delta.Y  = 0;
                        Velocity = -delta;
                    }
                }
                else if (mouse.Y < edgePadding || mouse.Y > GameState.Game.GraphicsDevice.Viewport.Height - edgePadding)
                {
                    moveTimer.Update(time);
                    if (moveTimer.HasTriggered)
                    {
                        float dir = 0.0f;

                        if (mouse.Y < edgePadding)
                        {
                            dir = -(edgePadding - mouse.Y);
                        }
                        else
                        {
                            dir = -((GameState.Game.GraphicsDevice.Viewport.Height - edgePadding) - mouse.Y);
                        }

                        dir *= 0.1f;

                        Vector3 forward = (Target - Position);
                        forward.Normalize();
                        Vector3 right = Vector3.Cross(forward, UpVector);
                        Vector3 up    = Vector3.Cross(right, forward);
                        Vector3 delta = up * CameraMoveSpeed * dir * dt;
                        delta.Y  = 0;
                        Velocity = -delta;
                    }
                }
                else
                {
                    moveTimer.Reset(moveTimer.TargetTimeSeconds);
                }
            }

            if (mouse.ScrollWheelValue != LastWheel && !PlayState.GUI.IsMouseOver())
            {
                int change = mouse.ScrollWheelValue - LastWheel;

                if (!(keys.IsKeyDown(Keys.LeftAlt) || keys.IsKeyDown(Keys.RightAlt)))
                {
                    if (!keys.IsKeyDown(Keys.LeftControl))
                    {
                        Vector3 delta = new Vector3(0, change, 0);

                        if (GameSettings.Default.InvertZoom)
                        {
                            delta *= -1;
                        }

                        Velocity = delta * CameraZoomSpeed * dt;
                    }
                    else
                    {
                        chunks.ChunkData.SetMaxViewingLevel(chunks.ChunkData.MaxViewingLevel + (int)((float)change * 0.01f), ChunkManager.SliceMode.Y);
                    }
                }
            }

            LastWheel = mouse.ScrollWheelValue;

            if (!CollidesWithChunks(PlayState.ChunkManager, Target + Velocity, false))
            {
                Target      += Velocity;
                PushVelocity = Vector3.Zero;
            }
            else
            {
                PushVelocity += Vector3.Up * 0.05f;
                Target       += PushVelocity;
            }

            Velocity *= 0.8f;
            UpdateBasisVectors();
        }
Ejemplo n.º 9
0
        private void WalkUpdate(DwarfTime time, ChunkManager chunks)
        {
            MouseState    mouse = Mouse.GetState();
            KeyboardState keys  = Keyboard.GetState();


            if (PhysicsObject == null)
            {
                PhysicsObject            = new Physics("CameraPhysics", PlayState.ComponentManager.RootComponent, Matrix.CreateTranslation(Target), new Vector3(0.5f, 0.5f, 0.5f), Vector3.Zero, 1.0f, 1.0f, 0.999f, 1.0f, Vector3.Down * 10);
                PhysicsObject.IsSleeping = false;
                PhysicsObject.Velocity   = Vector3.Down * 0.01f;
            }

            bool  stateChanged = false;
            float dt           = (float)time.ElapsedGameTime.TotalSeconds;

            if (KeyManager.RotationEnabled())
            {
                if (!shiftPressed)
                {
                    shiftPressed = true;

                    mouse        = Mouse.GetState();
                    stateChanged = true;
                }
                if (!isLeftPressed && mouse.LeftButton == ButtonState.Pressed)
                {
                    isLeftPressed = true;
                    stateChanged  = true;
                }
                else if (mouse.LeftButton == ButtonState.Released)
                {
                    isLeftPressed = false;
                }

                if (!isRightPressed && mouse.RightButton == ButtonState.Pressed)
                {
                    isRightPressed = true;
                    stateChanged   = true;
                }
                else if (mouse.RightButton == ButtonState.Released)
                {
                    isRightPressed = false;
                }


                if (stateChanged)
                {
                    Mouse.SetPosition(GameState.Game.GraphicsDevice.Viewport.Width / 2, GameState.Game.GraphicsDevice.Viewport.Height / 2);
                    mouse = Mouse.GetState();
                }


                float diffX = mouse.X - GameState.Game.GraphicsDevice.Viewport.Width / 2;
                float diffY = mouse.Y - GameState.Game.GraphicsDevice.Viewport.Height / 2;


                float filterDiffX = (float)(diffX * dt);
                float filterDiffY = (float)(diffY * dt);
                if (Math.Abs(filterDiffX) > 1.0f)
                {
                    filterDiffX = 1.0f * Math.Sign(filterDiffX);
                }

                if (Math.Abs(filterDiffY) > 1.0f)
                {
                    filterDiffY = 1.0f * Math.Sign(filterDiffY);
                }

                targetTheta = Theta - (filterDiffX);
                targetPhi   = Phi - (filterDiffY);
                Theta       = targetTheta * 0.5f + Theta * 0.5f;
                Phi         = targetPhi * 0.5f + Phi * 0.5f;


                if (Phi < -1.5f)
                {
                    Phi = -1.5f;
                }
                else if (Phi > 1.5f)
                {
                    Phi = 1.5f;
                }
            }
            else
            {
                shiftPressed = false;
            }

            Vector3 velocityToSet = Vector3.Zero;

            if (keys.IsKeyDown(ControlSettings.Mappings.Forward) || keys.IsKeyDown(Keys.Up))
            {
                Vector3 forward = (Target - Position);
                forward.Normalize();

                velocityToSet += forward * CameraMoveSpeed * dt;
            }
            else if (keys.IsKeyDown(ControlSettings.Mappings.Back) || keys.IsKeyDown(Keys.Down))
            {
                Vector3 forward = (Target - Position);
                forward.Normalize();
                velocityToSet += -forward * CameraMoveSpeed * dt;
            }

            if (keys.IsKeyDown(ControlSettings.Mappings.Left) || keys.IsKeyDown(Keys.Left))
            {
                Vector3 forward = (Target - Position);
                forward.Normalize();
                Vector3 right = Vector3.Cross(forward, UpVector);
                right.Normalize();
                velocityToSet += -right * CameraMoveSpeed * dt;
            }
            else if (keys.IsKeyDown(ControlSettings.Mappings.Right) || keys.IsKeyDown(Keys.Right))
            {
                Vector3 forward = (Target - Position);
                forward.Normalize();
                Vector3 right = Vector3.Cross(forward, UpVector);
                right.Normalize();
                velocityToSet += right * CameraMoveSpeed * dt;
            }

            if (velocityToSet.LengthSquared() > 0)
            {
                Velocity = Velocity * 0.5f + velocityToSet * 0.5f;
            }



            LastWheel = mouse.ScrollWheelValue;

            Velocity = new Vector3(Velocity.X, 0, Velocity.Z);


            if (keys.IsKeyDown(Keys.Space))
            {
                Velocity += Vector3.Up;
            }

            //CollidesWithChunks(PlayState.ChunkManager, Target, true);
            PhysicsObject.ApplyForce(Velocity * 20, dt);

            Target    = PhysicsObject.GlobalTransform.Translation + Vector3.Up * 0.5f;
            Velocity *= 0.8f;
            UpdateBasisVectors();
        }