예제 #1
0
        public static Mat4x4 MakeProjection(float fFovDegrees, float fAspectRatio, float fNear, float fFar)
        {
            float  fFovRad = 1.0f / Convert.ToSingle(Math.Tan(fFovDegrees * 0.5f / 180.0f * 3.14159f));
            Mat4x4 matrix  = new Mat4x4(new Matrix4x4());

            matrix.M.M11 = fAspectRatio * fFovRad;
            matrix.M.M22 = fFovRad;
            matrix.M.M33 = fFar / (fFar - fNear);
            matrix.M.M43 = (-fFar * fNear) / (fFar - fNear);
            matrix.M.M34 = 1.0f;
            matrix.M.M44 = 0.0f;
            return(matrix);
        }
예제 #2
0
        internal Mat4x4 QuickInverse()         // Only for Rotation/Translation Matrices
        {
            Mat4x4 matrix = new Mat4x4(new Matrix4x4());

            matrix.M.M11 = this.M.M11; matrix.M.M12 = this.M.M21; matrix.M.M13 = this.M.M31; matrix.M.M14 = 0.0f;
            matrix.M.M21 = this.M.M12; matrix.M.M22 = this.M.M22; matrix.M.M23 = this.M.M32; matrix.M.M24 = 0.0f;
            matrix.M.M31 = this.M.M13; matrix.M.M32 = this.M.M23; matrix.M.M33 = this.M.M33; matrix.M.M34 = 0.0f;
            matrix.M.M41 = -(this.M.M41 * matrix.M.M11 + this.M.M42 * matrix.M.M21 + this.M.M43 * matrix.M.M31);
            matrix.M.M42 = -(this.M.M41 * matrix.M.M12 + this.M.M42 * matrix.M.M22 + this.M.M43 * matrix.M.M32);
            matrix.M.M43 = -(this.M.M41 * matrix.M.M13 + this.M.M42 * matrix.M.M23 + this.M.M43 * matrix.M.M33);
            matrix.M.M44 = 1.0f;

            return(matrix);
        }
예제 #3
0
        public static Mat4x4 PointAt(Vector3D pos, Vector3D target, Vector3D up)
        {
            // Calculate new forward direction
            Vector3D newForward = target - pos;

            newForward = newForward.Normalise();

            // Calculate new Up direction
            Vector3D a     = newForward * (up * newForward);
            Vector3D newUp = up - a;

            newUp = newUp.Normalise();

            // New Right direction is easy, its just cross product
            Vector3D newRight = newUp.CrossProduct(newForward);

            // Construct Dimensioning and Translation Matrix
            Mat4x4 matrix = new Mat4x4();

            matrix.M.M11 = newRight.vector.X;
            matrix.M.M12 = newRight.vector.Y;
            matrix.M.M13 = newRight.vector.Z;
            matrix.M.M14 = 0.0f;
            matrix.M.M21 = newUp.vector.X;
            matrix.M.M22 = newUp.vector.Y;
            matrix.M.M23 = newUp.vector.Z;
            matrix.M.M24 = 0.0f;
            matrix.M.M31 = newForward.vector.X;
            matrix.M.M32 = newForward.vector.Y;
            matrix.M.M33 = newForward.vector.Z;
            matrix.M.M34 = 0.0f;
            matrix.M.M41 = pos.vector.X;
            matrix.M.M42 = pos.vector.Y;
            matrix.M.M43 = pos.vector.Z;
            matrix.M.M44 = 1.0f;
            return(matrix);
        }