コード例 #1
0
        /// <summary>
        /// Retrieves the current camera vectors which represent the current forward, right and up directions
        /// for the camera.
        /// </summary>
        /// <returns></returns>
        public CameraVectors GetCameraVectors()
        {
            if (_validCameraVectors)
            {
                return(_cameraVectors);
            }

            _cameraVectors      = CameraVectors.FromYawPitchRoll(_yaw, _pitch, 0F);
            _validCameraVectors = true;
            return(_cameraVectors);
        }
コード例 #2
0
        /// <summary>
        /// Retrieves the view matrix for the current class instance.
        /// </summary>
        /// <returns>The view matrix.</returns>
        public Matrix GetViewMatrix()
        {
            if (_validViewMatrix && _validCameraVectors)
            {
                return(_viewMatrix);
            }

            _cameraVectors   = GetCameraVectors();
            _viewMatrix      = Matrix.LookAtRH(_position, _position + _cameraVectors._forwardVector, Vector3.Up);
            _validViewMatrix = true;

            return(_viewMatrix);
        }
コード例 #3
0
        /// <summary>
        /// Calculates the camera movement vectors from
        /// </summary>
        /// <param name="yawDegrees">The direction that moves the camera left and right.</param>
        /// <param name="pitchDegrees">The direction that moves the camera up and down.</param>
        /// <param name="rollDegrees">Self explanatory.</param>
        public static CameraVectors FromYawPitchRoll(float yawRadians, float pitchRadians, float rollRadians)
        {
            CameraVectors cameraVectors = new CameraVectors();

            Matrix.RotationYawPitchRoll(yawRadians, pitchRadians, rollRadians, out Matrix result);

            cameraVectors._forwardVector = (Vector3)Vector3.Transform(Vector3.ForwardRH, result);
            cameraVectors._forwardVector.Normalize();

            cameraVectors._leftVector = Vector3.Cross(Vector3.Up, cameraVectors._forwardVector);
            cameraVectors._leftVector.Normalize();

            cameraVectors._upVector = Vector3.Cross(cameraVectors._forwardVector, cameraVectors._leftVector);
            cameraVectors._upVector.Normalize();

            return(cameraVectors);
        }