Пример #1
0
        protected virtual void HandleInput(GameTime gameTime)
        {
            float dt = (float)gameTime.ElapsedGameTime.TotalMilliseconds;

            IInputContext currentStates = Engine.InputContext;

            Vector2 r = currentStates.Gamepad.RStick();

            Vector2 orientationDelta = new Vector2();

            orientationDelta.X = r.X;
            orientationDelta.Y = -r.Y;

            this.Pitch -= dt * orientationDelta.Y * XSensitivity * 2f;
            this.Yaw   += dt * orientationDelta.X * XSensitivity * 2f;

            MatrixD rot = MatrixD.RotationYawPitchRoll(this.Yaw, this.Pitch, this.Roll);

            this.LookAt = Vector3D.TransformCoordinate(Vector3D.UnitZ, rot);
            this.Right  = Vector3D.TransformCoordinate(Vector3D.UnitX, rot);
            this.Up     = Vector3D.Cross(this.Right, this.LookAt);

            this.LookAt.Normalize();
            this.Right.Normalize();
            this.Up.Normalize();

            Vector2 l = currentStates.Gamepad.LStick();

            float rtrigger = currentStates.Gamepad.RTrigger() == 0 ? 1f : currentStates.Gamepad.RTrigger();

            Vector3D force = this.LookAt * l.Y * 20.0; // thrust

            force -= this.Right * l.X * 20.0;

            force *= dt * 0.1f * rtrigger;

            this.PositionD += force * 0.01;
            this.Position   = this.PositionD.ToVector3();
        }