示例#1
0
        public void walkMove(Vector3 direction)
        {
            this.applyFriction();

            if (camera.inverted)
            {
                direction.Z *= -1.0f;
            }

            Vector3 moveDir = QuaternionLib.Rotate(camera.Orientation, direction);

            float speed = direction.Length * Config.q3movement_scale;

            camera.velocity = this.accelerate(moveDir, speed, Config.q3movement_accelerate);

            Vector3 normal = this.groundTrace.plane.normal;

            camera.velocity = this.clipVelocity(camera.velocity, normal);

            if (camera.velocity.X == 0 && camera.velocity.Z == 0)
            {
                return;
            }                                                                      //if(!this.velocity[0] && !this.velocity[1]) { return; }


            bool apply_gravity = false;

            this.stepSlideMove(apply_gravity);
        }
示例#2
0
        public void Strafe(float magnitude)
        {
            Vector3 lookat  = QuaternionLib.Rotate(Orientation, Vector3.UnitZ);
            Vector3 forward = new Vector3(lookat.X, lookat.Y, 0).Normalized();
            Vector3 up      = Vector3.UnitZ;
            Vector3 left    = up.Cross(forward);

            Position += left * (-magnitude);
        }
示例#3
0
        public void SetOrigin(Vector3 origin, Vector3 rotation)
        {
            Position       = Origin = origin;
            Rotation       = rotation;
            OriginRotation = rotation;

            Orientation = Quaternion.Identity;
            //xAngle = 0.0;

            camera_pitch = OriginRotation.Z; // * MathHelpers.PiOver180;
            camera_yaw   = OriginRotation.X; // * MathHelpers.PiOver180;

            Orientation = QuaternionLib.QuaternionFromEulerAnglesRad(0, -camera_yaw, -camera_pitch);
            //Orientation = QuaternionExtensions.EulerToQuat(0, camera_yaw, -camera_pitch);
        }
示例#4
0
        public void ApplyOrientation(float pitch, float yaw)
        {
            Vector3 direction = (this.Look - this.Position);

            direction.Normalize();

            Vector3 pitch_axis = Vector3.Cross(direction, this.Up);

            this.pitch = Quaternion.FromAxisAngle(pitch_axis, pitch);
            this.yaw   = Quaternion.FromAxisAngle(this.Up, yaw);

            this.Orientation = this.yaw * this.pitch /* this.roll */;
            this.Orientation.Normalize();

            this.Direction = QuaternionLib.Rotate(Orientation, Right);
        }
示例#5
0
        public void ApplyRotation()
        {
            Vector3 direction = (Look - Position);

            direction.Normalize();

            //MakeOrthogonal();


            Vector3 lookat  = QuaternionLib.Rotate(Orientation, Vector3.UnitZ);
            Vector3 forward = new Vector3(lookat.X, lookat.Y, 0).Normalized();
            Vector3 up      = Vector3.UnitY;
            Vector3 left    = up.Cross(forward);

            Vector3 roll_axis = forward + Up;

            Orientation = QuaternionLib.QuaternionFromEulerAnglesRad(0, -camera_yaw, -camera_pitch);

            if (inverted)
            {
                Orientation *= QuaternionLib.QuaternionFromEulerAnglesRad(0, 0, -MathHelpers.PI);
            }
        }
示例#6
0
        private void ApplyKeyBindings(float frameTime)
        {
            if (camera.playerMover == null)
            {
                return;
            }

            Vector3 direction  = Vector3.Zero;
            bool    translated = false;
            float   walkMovementSpeed;

            slowFlySpeed  = Keyboard[Key.AltLeft];
            fastFlySpeed  = Keyboard[Key.ShiftLeft];
            movementSpeed = fastFlySpeed ? 10.0f : 1.0f;
            movementSpeed = slowFlySpeed ? 0.01f : movementSpeed;

            fastWalkSpeed            = Keyboard[Key.ShiftLeft];
            walkMovementSpeed        = fastWalkSpeed ? Config.walkVelocityFast : Config.walkVelocityScale;
            camera.walkMovementSpeed = walkMovementSpeed;

            if (Keyboard[Key.Escape] || Keyboard[Key.Q])
            {
                // QUIT APPLICATION
                if (this.WindowState == WindowState.Fullscreen)
                {
                    this.WindowState = WindowState.Normal;
                }

                Quit();
            }

            Vector3 lookat  = QuaternionLib.Rotate(camera.Orientation, Vector3.UnitY);
            Vector3 forward = new Vector3(lookat.X, 0, lookat.Z).Normalized();
            Vector3 up      = Vector3.UnitZ;
            Vector3 left    = up.Cross(forward);
            Vector3 right   = up.Cross(camera.Direction);

            if (navigationType == NavigationType.Walk)
            {
                if (Keyboard[Key.W])
                {
                    camera.Forward = new Vector3(lookat.X, 0, lookat.Z).Normalized();
                    direction     -= camera.Forward * (Config.playerDirectionMagnitude * walkMovementSpeed);

                    translated = true;
                }
                if (Keyboard[Key.S])
                {
                    camera.Forward = new Vector3(lookat.X, 0, lookat.Z).Normalized();
                    direction     += camera.Forward * (Config.playerDirectionMagnitude * walkMovementSpeed);

                    translated = true;
                }
                if (Keyboard[Key.A])
                {
                    camera.Forward = new Vector3(lookat.X, 0, lookat.Z).Normalized();
                    camera.Right   = right;

                    direction += camera.Right * (Config.playerDirectionMagnitude * walkMovementSpeed);

                    translated = true;
                }
                if (Keyboard[Key.D])
                {
                    camera.Forward = new Vector3(lookat.X, 0, lookat.Z).Normalized();
                    camera.Right   = right;

                    direction -= camera.Right * (Config.playerDirectionMagnitude * walkMovementSpeed);

                    translated = true;
                }
            }
            else if (navigationType == NavigationType.Fly)
            {
                if (Keyboard[Key.T])
                {
                    camera.Fly(playerDirectionMagnitude * movementSpeed);
                }
                if (Keyboard[Key.G])
                {
                    camera.Fly(-playerDirectionMagnitude * movementSpeed);
                }

                if (Keyboard[Key.W])
                {
                    camera.Walk(playerDirectionMagnitude * movementSpeed);
                }
                if (Keyboard[Key.S])
                {
                    camera.Walk(-playerDirectionMagnitude * movementSpeed);
                }
                if (Keyboard[Key.A])
                {
                    camera.Strafe(playerDirectionMagnitude * movementSpeed);
                }
                if (Keyboard[Key.D])
                {
                    camera.Strafe(-playerDirectionMagnitude * movementSpeed);
                }
            }



            if (Keyboard[Key.PageUp])
            {
                //drawMap = false;
            }
            if (Keyboard[Key.PageDown])
            {
                //drawMap = true;
            }

            bool rotated = false;

            if (Keyboard[Key.Left])
            {
                camera.ApplyYaw(-Config.turnMagnitude);
                rotated = true;
            }
            if (Keyboard[Key.Right])
            {
                camera.ApplyYaw(Config.turnMagnitude);
                rotated = true;
            }
            if (Keyboard[Key.Up])
            {
                camera.ApplyPitch(-Config.turnMagnitude);
                rotated = true;
            }
            if (Keyboard[Key.Down])
            {
                camera.ApplyPitch(Config.turnMagnitude);
                rotated = true;
            }

            // Calibrator (for translation debugging)
            if (Keyboard[Key.Number1])
            {
                camera.calibTrans.X += camera.calibSpeed.X;
            }
            if (Keyboard[Key.Number2])
            {
                camera.calibTrans.X -= camera.calibSpeed.X;
            }
            if (Keyboard[Key.Number3])
            {
                camera.calibTrans.Y += camera.calibSpeed.Y;
            }
            if (Keyboard[Key.Number4])
            {
                camera.calibTrans.Y -= camera.calibSpeed.Y;
            }
            if (Keyboard[Key.Number5])
            {
                camera.calibTrans.Z += camera.calibSpeed.Z;
            }
            if (Keyboard[Key.Number6])
            {
                camera.calibTrans.Z -= camera.calibSpeed.Z;
            }

            // Calibrator (for orientation debugging)
            if (Keyboard[Key.Number6])
            {
                camera.calibOrient.X += camera.calibSpeed.X;
            }
            if (Keyboard[Key.Number7])
            {
                camera.calibOrient.X -= camera.calibSpeed.X;
            }
            if (Keyboard[Key.Number8])
            {
                camera.calibOrient.Y += camera.calibSpeed.Y;
            }
            if (Keyboard[Key.Number9])
            {
                camera.calibOrient.Y -= camera.calibSpeed.Y;
            }
            if (Keyboard[Key.Minus])
            {
                camera.calibOrient.Z += camera.calibSpeed.Z;
            }
            if (Keyboard[Key.Plus])
            {
                camera.calibOrient.Z -= camera.calibSpeed.Z;
            }



            if (rotated)
            {
                camera.ApplyRotation();
            }

            if (navigationType == NavigationType.Walk)
            {
                camera.move(direction, frameTime);
            }


            //camera.update(frameTime);
        }
示例#7
0
        public void Walk(float magnitude)
        {
            Vector3 lookat = QuaternionLib.Rotate(Orientation, Vector3.UnitZ);

            Position += lookat * (-magnitude);
        }