Пример #1
0
        /// <summary>
        /// Multiply a float with the matrix
        /// </summary>
        /// <param name="value">The float to multiply to the matrix</param>
        /// <returns>Returns the multiplied matrix</returns>
        public Matrix3x3 Mult(float value)
        {
            Matrix3x3 newMatrix = new Matrix3x3();

            newMatrix.m11 = this.m11 * value;
            newMatrix.m12 = this.m12 * value;
            newMatrix.m13 = this.m13 * value;
            newMatrix.m21 = this.m21 * value;
            newMatrix.m22 = this.m22 * value;
            newMatrix.m23 = this.m23 * value;
            newMatrix.m31 = this.m31 * value;
            newMatrix.m32 = this.m32 * value;
            newMatrix.m33 = this.m33 * value;

            return newMatrix;
        }
Пример #2
0
        /// <summary>
        /// Transpose the matrix
        /// </summary>
        /// <returns>Returns transposed matrix</returns>
        public Matrix3x3 Transpose()
        {
            Matrix3x3 newMatrix = new Matrix3x3();

            newMatrix.m11 = this.m11;
            newMatrix.m12 = this.m21;
            newMatrix.m13 = this.m31;
            newMatrix.m21 = this.m12;
            newMatrix.m22 = this.m22;
            newMatrix.m23 = this.m32;
            newMatrix.m31 = this.m13;
            newMatrix.m32 = this.m23;
            newMatrix.m33 = this.m33;

            return newMatrix;
        }
Пример #3
0
        /// <summary>
        /// Calculate the coefficient of the matrix
        /// </summary>
        /// <returns>Returns the coefficient</returns>
        public Matrix3x3 Coefficient()
        {
            Matrix3x3 newMatrix = new Matrix3x3();

            newMatrix.m11 = + ((this.m22 * this.m33) - (this.m23 * this.m32));
            newMatrix.m12 = - ((this.m21 * this.m33) - (this.m23 * this.m31));
            newMatrix.m13 = + ((this.m21 * this.m32) - (this.m22 * this.m31));
            newMatrix.m21 = - ((this.m12 * this.m33) - (this.m13 * this.m32));
            newMatrix.m22 = + ((this.m11 * this.m33) - (this.m13 * this.m31));
            newMatrix.m23 = - ((this.m11 * this.m32) - (this.m12 * this.m31));
            newMatrix.m31 = + ((this.m12 * this.m23) - (this.m13 * this.m22));
            newMatrix.m32 = - ((this.m11 * this.m23) - (this.m13 * this.m21));
            newMatrix.m33 = + ((this.m11 * this.m22) - (this.m12 * this.m21));

            return newMatrix;
        }
Пример #4
0
        /// <summary>
        /// Multiply another matrix to this matrix
        /// </summary>
        /// <param name="secondMatrix">The second matrix</param>
        /// <returns>Returns the multiplied matrix</returns>
        public Matrix3x3 Mult(Matrix3x3 secondMatrix)
        {
            Matrix3x3 newMatrix = new Matrix3x3();

            newMatrix.m11 = ((this.m11 * secondMatrix.m11) + (this.m12 * secondMatrix.m21) + (this.m13 * secondMatrix.m31));
            newMatrix.m12 = ((this.m11 * secondMatrix.m12) + (this.m12 * secondMatrix.m22) + (this.m13 * secondMatrix.m32));
            newMatrix.m13 = ((this.m11 * secondMatrix.m13) + (this.m12 * secondMatrix.m23) + (this.m13 * secondMatrix.m33));
            newMatrix.m21 = ((this.m21 * secondMatrix.m11) + (this.m22 * secondMatrix.m21) + (this.m23 * secondMatrix.m31));
            newMatrix.m22 = ((this.m21 * secondMatrix.m12) + (this.m22 * secondMatrix.m22) + (this.m23 * secondMatrix.m32));
            newMatrix.m23 = ((this.m21 * secondMatrix.m13) + (this.m22 * secondMatrix.m23) + (this.m23 * secondMatrix.m33));
            newMatrix.m31 = ((this.m31 * secondMatrix.m11) + (this.m32 * secondMatrix.m21) + (this.m33 * secondMatrix.m31));
            newMatrix.m32 = ((this.m31 * secondMatrix.m12) + (this.m32 * secondMatrix.m22) + (this.m33 * secondMatrix.m32));
            newMatrix.m33 = ((this.m31 * secondMatrix.m13) + (this.m32 * secondMatrix.m23) + (this.m33 * secondMatrix.m33));

            return newMatrix;
        }
Пример #5
0
        /// <summary>
        /// Returns the view matrix for the given parameters
        /// </summary>
        /// <param name="right">The camera's right vector</param>
        /// <param name="up">The camera's up vector</param>
        /// <param name="position">The camera's position</param>
        /// <returns>View matrix</returns>
        public static Matrix3x3 ViewTransform(Vector2 right, Vector2 up, Vector2 position)
        {
            Matrix3x3 newMatrix = new Matrix3x3();

            newMatrix.m11 = right.x;
            newMatrix.m12 = right.y;
            newMatrix.m21 = up.x;
            newMatrix.m22 = up.y;
            newMatrix.m31 = -(right * position);
            newMatrix.m32 = -(up * position);

            return newMatrix;
        }
Пример #6
0
        /// <summary>
        /// Returns a world matrix for the given vectors
        /// </summary>
        /// <param name="right">The right vector</param>
        /// <param name="up">The up vector</param>
        /// <param name="position">The position vector</param>
        /// <returns></returns>
        public static Matrix3x3 WorldTransform(Vector2 right, Vector2 up, Vector2 position)
        {
            Matrix3x3 newMatrix = new Matrix3x3();

            newMatrix.m11 = right.x;
            newMatrix.m12 = right.y;
            newMatrix.m21 = up.x;
            newMatrix.m22 = up.y;
            newMatrix.m31 = position.x;
            newMatrix.m32 = position.y;

            return newMatrix;
        }
Пример #7
0
        /// <summary>
        /// Returns a translation matrix for the given vector
        /// </summary>
        /// <param name="translation">Translation vector</param>
        /// <returns>Returns translated matrix</returns>
        public static Matrix3x3 TranslateTransform(Vector2 translation)
        {
            Matrix3x3 newMatrix = new Matrix3x3();

            newMatrix.m31 = translation.x;
            newMatrix.m32 = translation.y;

            return newMatrix;
        }
Пример #8
0
 /// <summary>
 /// Calculate the determinant of a matrix
 /// </summary>
 /// <param name="matrix">Matrix to calculate determinant of</param>
 /// <returns>Returns the determinant</returns>
 public static float Determinant(Matrix3x3 matrix)
 {
     return
         + (matrix.m11 * matrix.m22 * matrix.m33)
         + (matrix.m12 * matrix.m23 * matrix.m31)
         + (matrix.m13 * matrix.m21 * matrix.m32)
         - (matrix.m13 * matrix.m22 * matrix.m31)
         - (matrix.m12 * matrix.m21 * matrix.m33)
         - (matrix.m11 * matrix.m23 * matrix.m32);
 }
Пример #9
0
        /// <summary>
        /// Returns a scale matrix for the given vector
        /// </summary>
        /// <param name="translation">Scale vector</param>
        /// <returns>Returns scale matrix</returns>
        public static Matrix3x3 ScaleTransform(Vector2 scale)
        {
            Matrix3x3 newMatrix = new Matrix3x3();

            newMatrix.m11 = scale.x;
            newMatrix.m22 = scale.y;

            return newMatrix;
        }
Пример #10
0
        /// <summary>
        /// Returns transformation matrix for shearing along Y axis
        /// </summary>
        /// <param name="shear">Shearing value</param>
        /// <returns>Returns transformation matrix for shearing along Y axis</returns>
        public static Matrix3x3 ShearYTransform(float shear)
        {
            Matrix3x3 newMatrix = new Matrix3x3();

            newMatrix.m21 = shear;

            return newMatrix;
        }
Пример #11
0
        /// <summary>
        /// Returns the rotation matrix of a clockwise rotation by an angle given in radians
        /// </summary>
        /// <param name="angle">The angle in radians</param>
        /// <returns>Returns the rotation matrix</returns>
        public static Matrix3x3 RotateTransform(float angle)
        {
            Matrix3x3 newMatrix = new Matrix3x3();

            newMatrix.m11 = (float)(Math.Cos(angle));
            newMatrix.m12 = (float)(Math.Sin(angle));
            newMatrix.m21 = (float)(-Math.Sin(angle));
            newMatrix.m22 = (float)(Math.Cos(angle));

            return newMatrix;
        }
Пример #12
0
        /// <summary>
        /// Multiply a float with a matrix
        /// </summary>
        /// <param name="matrix">The matrix to multiplay the float to</param>
        /// <param name="value">The float to multiply to the matrix</param>
        /// <returns>Returns the multiplied matrix</returns>
        public static Matrix3x3 Mult(Matrix3x3 matrix, float value)
        {
            Matrix3x3 newMatrix = new Matrix3x3();

            newMatrix.m11 = matrix.m11 * value;
            newMatrix.m12 = matrix.m12 * value;
            newMatrix.m13 = matrix.m13 * value;
            newMatrix.m21 = matrix.m21 * value;
            newMatrix.m22 = matrix.m22 * value;
            newMatrix.m23 = matrix.m23 * value;
            newMatrix.m31 = matrix.m31 * value;
            newMatrix.m32 = matrix.m32 * value;
            newMatrix.m33 = matrix.m33 * value;

            return newMatrix;
        }
Пример #13
0
        /// <summary>
        /// Calculate the inverse of a matrix
        /// </summary>
        /// <param name="matrix">Matrix to calculate inverse of</param>
        /// <returns>Returns inverse of matrix</returns>
        public static Matrix3x3 Inverse(Matrix3x3 matrix)
        {
            float determinant = matrix.Determinant();

            Matrix3x3 newMatrix = matrix.Coefficient();
            newMatrix = newMatrix.Transpose();
            newMatrix = newMatrix / determinant;

            return newMatrix;
        }
Пример #14
0
        /// <summary>
        /// Multiply a Matrix3x3 to a vector (ignoring the third dimension of the matrix)
        /// </summary>
        /// <param name="matrix">The Matrix3x3 to multiply to the vector</param>
        /// <returns>Returns the multiplied vector</returns>
        public static Vector2 Mult(Vector2 vector, Matrix3x3 matrix)
        {
            Vector2 newVector = new Vector2();

            newVector.x = ((matrix.m11 * vector.x) + (matrix.m12 * vector.y));
            newVector.y = ((matrix.m21 * vector.x) + (matrix.m22 * vector.y));

            return newVector;
        }
Пример #15
0
        /// <summary>
        /// Transpose a matrix
        /// </summary>
        /// <param name="matrix">Matrix to transpose</param>
        /// <returns>Returns transposed matrix</returns>
        public static Matrix3x3 Transpose(Matrix3x3 matrix)
        {
            Matrix3x3 newMatrix = new Matrix3x3();

            newMatrix.m11 = matrix.m11;
            newMatrix.m12 = matrix.m21;
            newMatrix.m13 = matrix.m31;
            newMatrix.m21 = matrix.m12;
            newMatrix.m22 = matrix.m22;
            newMatrix.m23 = matrix.m32;
            newMatrix.m31 = matrix.m13;
            newMatrix.m32 = matrix.m23;
            newMatrix.m33 = matrix.m33;

            return newMatrix;
        }
Пример #16
0
        /// <summary>
        /// Multiply a Matrix3x3 to the vector (ignoring the third dimension of the matrix)
        /// </summary>
        /// <param name="matrix">The Matrix3x3 to multiply to the vector</param>
        /// <returns>Returns the multiplied vector</returns>
        public Vector2 Mult(Matrix3x3 matrix)
        {
            Vector2 newVector = new Vector2();

            newVector.x = ((matrix.m11 * this.x) + (matrix.m12 * this.y));
            newVector.y = ((matrix.m21 * this.x) + (matrix.m22 * this.y));

            return newVector;
        }
Пример #17
0
        /// <summary>
        /// Calculate the coefficient of a matrix
        /// </summary>
        /// <param name="matrix">Matrix to calculate coefficient of</param>
        /// <returns>Returns the coefficient</returns>
        public static Matrix3x3 Coefficient(Matrix3x3 matrix)
        {
            Matrix3x3 newMatrix = new Matrix3x3();

            newMatrix.m11 = + ((matrix.m22 * matrix.m33) - (matrix.m23 * matrix.m32));
            newMatrix.m12 = - ((matrix.m21 * matrix.m33) - (matrix.m23 * matrix.m31));
            newMatrix.m13 = + ((matrix.m21 * matrix.m32) - (matrix.m22 * matrix.m31));
            newMatrix.m21 = - ((matrix.m12 * matrix.m33) - (matrix.m13 * matrix.m32));
            newMatrix.m22 = + ((matrix.m11 * matrix.m33) - (matrix.m13 * matrix.m31));
            newMatrix.m23 = - ((matrix.m11 * matrix.m32) - (matrix.m12 * matrix.m31));
            newMatrix.m31 = + ((matrix.m12 * matrix.m23) - (matrix.m13 * matrix.m22));
            newMatrix.m32 = - ((matrix.m11 * matrix.m23) - (matrix.m13 * matrix.m21));
            newMatrix.m33 = + ((matrix.m11 * matrix.m22) - (matrix.m12 * matrix.m21));

            return newMatrix;
        }