Пример #1
0
        /// <summary>
        /// Creates a new 4x4 perspective matrix
        /// </summary>
        /// <param name="focalLength"></param>
        /// <returns></returns>
        public static ASMATRIX4 CreatePerspectiveMatrix(double focalLength)
        {
            // Reset the matrix to an identity matrix
            var m = new ASMATRIX4();

            // Create the perspective matrix
            m.Matrix[3].Points[2] = 1 / focalLength;
            m.Matrix[3].Points[3] = 0;

            return(m);
        }
Пример #2
0
        /// <summary>
        /// Builds a transaltion matrix and returns it to the caller
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="z"></param>
        /// <returns></returns>
        public static ASMATRIX4 CreateScalingMatrix(double x, double y, double z)
        {
            // Zero the matrix
            var m = new ASMATRIX4();

            // Scale the matrix
            m.Matrix[0].Points[0] = x;
            m.Matrix[1].Points[1] = y;
            m.Matrix[2].Points[2] = z;

            return(m);
        }
Пример #3
0
        /// <summary>
        /// Builds a transaltion matrix and returns it to the caller
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="z"></param>
        /// <returns></returns>
        public static ASMATRIX4 CreateTranslationMatrix(double x, double y, double z)
        {
            // reset to identity matrix
            var m = new ASMATRIX4();

            // Set the translation matrix
            m.Matrix[0].Points[3] = x;
            m.Matrix[1].Points[3] = y;
            m.Matrix[2].Points[3] = z;

            return(m);
        }
Пример #4
0
        /// <summary>
        /// Transforms the face by a transformation matrix, this will allow
        /// the mesh to be scaled
        /// </summary>
        /// <param name="matrix"></param>
        /// <returns></returns>
        public ASFace TransformFace(ASMATRIX4 matrix)
        {
            var transformedFace = new ASFace();

            for (var i = 0; i < 3; i++)
            {
                transformedFace.m_points[i] = m_points[i].TransformVector(matrix);
                transformedFace.m_points[i] = transformedFace.m_points[i].Rescale();
            }

            return(transformedFace);
        }
Пример #5
0
        /// <summary>
        /// Creates a rotation matrix around the Z origin, given the angle
        /// in degree
        /// </summary>
        /// <param name="radians"></param>
        private static ASMATRIX4 CreateRotationAroundZ(double radians)
        {
            // See if the angle is valid, if not set default
            CheckAngle(radians, out radians);

            // Zero the Matrix
            var m = new ASMATRIX4();

            // Create the X Rotation Matrix
            m.Matrix[0].Points[0] = Math.Cos(radians);
            m.Matrix[0].Points[1] = Math.Sin(radians);
            m.Matrix[1].Points[0] = -(Math.Sin(radians));
            m.Matrix[1].Points[1] = Math.Cos(radians);

            return(m);
        }
Пример #6
0
        /// <summary>
        /// Transform the vector by a matrix
        /// </summary>
        /// <param name="m"></param>
        public ASVECTOR3 TransformVector(ASMATRIX4 m)
        {
            var newPoint = new ASVECTOR3();

            // Multiply rows by cols to get the new vector
            for (var col = 0; col < 3; col++)
            {
                double total = 0;
                for (var row = 0; row < 3; row++)
                {
                    total = total + points[row] * m.Matrix[col].Points[row];
                }
            }

            return(newPoint);
        }
Пример #7
0
        /// <summary>
        /// Multiply two matrices together to get the cross product
        /// </summary>
        /// <param name="mA"></param>
        /// <param name="mB"></param>
        /// <returns></returns>
        public static ASMATRIX4 operator *(ASMATRIX4 mA, ASMATRIX4 mB)
        {
            //  Creates a new zeroed output matrix
            var m = new ASMATRIX4();

            // Multiply the two matrixes together and return the output matrix
            for (var i = 0; i < 4; i++)
            {
                for (var j = 0; j < 4; j++)
                {
                    m.Matrix[i].Points[j] =
                        (mB.Matrix[i].Points[0] * mA.Matrix[0].Points[j]) +
                        (mB.Matrix[i].Points[1] * mA.Matrix[1].Points[j]) +
                        (mB.Matrix[i].Points[2] * mA.Matrix[2].Points[j]) +
                        (mB.Matrix[i].Points[3] * mA.Matrix[3].Points[j]);
                }
            }
            return(m);
        }
Пример #8
0
 /// <summary>
 /// Transform the vector by a matrix
 /// </summary>
 /// <param name="m"></param>
 public ASVECTOR4 TransformVector(ASMATRIX4 m)
 {
     return(m * this);
 }