Пример #1
0
        /// <summary>
        /// Create a View matrix from an existing ProjectionCamera
        /// (code acquired with Reflector)
        /// </summary>
        /// <param name="position">Camera position</param>
        /// <param name="lookDirection">Look direction</param>
        /// <param name="upDirection">Up direction</param>
        /// <returns>View matrix</returns>
        public static Matrix3D CreateViewMatrix(Point3D position, Vector3D lookDirection, Vector3D upDirection)
        {
            Vector3D vectord2 = -lookDirection;

            vectord2.Normalize();
            Vector3D vectord3 = Vector3D.CrossProduct(upDirection, vectord2);

            vectord3.Normalize();
            Vector3D vectord4 = Vector3D.CrossProduct(vectord2, vectord3);
            Vector3D vectord  = (Vector3D)position;
            double   offsetX  = -Vector3D.DotProduct(vectord3, vectord);
            double   offsetY  = -Vector3D.DotProduct(vectord4, vectord);
            double   offsetZ  = -Vector3D.DotProduct(vectord2, vectord);

            return(new Matrix3D(
                       vectord3.X, vectord4.X, vectord2.X, 0,
                       vectord3.Y, vectord4.Y, vectord2.Y, 0,
                       vectord3.Z, vectord4.Z, vectord2.Z, 0,
                       offsetX, offsetY, offsetZ, 1));
        }