Beispiel #1
0
        public Camera(Vector3 Position, Vector3 Target, Vector3 Up)
        {
            this.Position  = Position;
            this.Target    = Target;
            this.Direction = Vector3.Normalize(this.Position - this.Target);

            this.Right = Vector3.Normalize(Vector3.Cross(Up, Direction));
            this.Up    = Vector3.Normalize(Vector3.Cross(this.Direction, this.Right));

            this.View = Matrix.CreateLookAt(Position, Target, Up);
            GroundRay = new Raycast(Position, Position + Vector3.Down * HEIGHT);
        }
Beispiel #2
0
        public void Update(GameTime gameTime)
        {
            // If window is focused
            if (Game1.Instance.IsActive)
            {
                GetInput();
                MouseControl();
            }
            else
            {
                First = true;
            }

            if (InputManager.IsKeyDown(Keys.F1))
            {
                IsFlying = true;
            }
            if (InputManager.IsKeyDown(Keys.F2))
            {
                IsFlying = false;
            }

            KeyboardControl();

            if (!IsFlying)
            {
                GroundRay.Start = Position;
                GroundRay.End   = Position - new Vector3(0, HEIGHT, 0);
                CollisionResult?result = CollisionHelper.IsCollidingWithWorld(GroundRay);
                IsGrounded = result != null;

                if (IsGrounded)
                {
                    Position   = Vector3.Lerp(Position, new Vector3(Position.X, result.Value.VoxelPosition.Y + HEIGHT, Position.Z), 0.2f);
                    Velocity.Y = 0;
                }

                else
                {
                    Velocity -= GRAVITY * Up * (float)gameTime.ElapsedGameTime.TotalSeconds;
                }
            }

            Direction = Vector3.Lerp(Direction, TargetDirection, Smoothing);

            DestroyRaycast(25f);

            Position  += Velocity * (float)gameTime.ElapsedGameTime.TotalSeconds;
            this.Right = Vector3.Normalize(Vector3.Cross(Up, Direction));
            this.View  = Matrix.CreateLookAt(Position, Position + Direction, Up);
        }