コード例 #1
0
        //
        // Resumen:
        //     Creates a rotation matrix.
        public static MyMatrix4x4 Rotate(MyQuatern q)
        {
            //  Manipulacion algebraica de p' = q*p*q^-1
            //  Cos(angulo/2) + Sin(angulo)(ijk)
            //  Vec3 angel = q.eulerAngles;

            /*
             * m00 = 1 - 2 * qy2 - 2 * qz2      |   m01 = 2 * qx * qy - 2 * qz * qw   |  m02 = 2 * qx * qz + 2 * qy * qw
             * m10 = 2 * qx * qy + 2 * qz * qw  |   m11 = 1 - 2 * qx2 - 2 * qz2       |  m12 = 2 * qy * qz - 2 * qx * qw
             * m20 = 2 * qx * qz - 2 * qy * qw  |   m21 = 2 * qy * qz + 2 * qx * qw   |  m22 = 1 - 2 * qx2 - 2 * qy2
             */

            MyMatrix4x4 newM = MyMatrix4x4.identity;

            newM.m00 = 1 - 2 * (q.y * q.y) - 2 * (q.z * q.z);
            newM.m01 = 2 * q.x * q.y - 2 * q.z * q.w;
            newM.m02 = 2 * q.x * q.z + 2 * q.y * q.w;
            newM.m10 = 2 * q.x * q.y + 2 * q.z * q.w;
            newM.m11 = 1 - 2 * (q.x * q.x) - 2 * (q.z * q.z);
            newM.m12 = 2 * q.y * q.z - 2 * q.x * q.w;
            newM.m20 = 2 * q.x * q.z - 2 * q.y * q.w;
            newM.m21 = 2 * q.y * q.z + 2 * q.x * q.w;
            newM.m22 = 1 - 2 * (q.x * q.x) - 2 * (q.y * q.y);

            return(newM);
        }
コード例 #2
0
 //
 // Resumen:
 //      The transposed matrix is the one that has the Matrix4x4's columns exchanged with its rows. (Read Only)
 public static MyMatrix4x4 Transpose(MyMatrix4x4 m)
 {
     return(new MyMatrix4x4(new Vector4(m.m00, m.m01, m.m02, m.m03),
                            new Vector4(m.m10, m.m11, m.m12, m.m13),
                            new Vector4(m.m20, m.m21, m.m22, m.m23),
                            new Vector4(m.m30, m.m31, m.m32, m.m33)));
 }
コード例 #3
0
        public static MyMatrix4x4 operator *(MyMatrix4x4 lhs, MyMatrix4x4 rhs)
        {
            // Primero los elementos de las filas (lhs) y despues los elementos de las columnas (rhs)
            MyMatrix4x4 newMatrix = MyMatrix4x4.zero;

            newMatrix.m00 = (lhs.m00 * rhs.m00) + (lhs.m01 * rhs.m10) + (lhs.m02 * rhs.m20) + (lhs.m03 * rhs.m30);
            newMatrix.m01 = (lhs.m00 * rhs.m01) + (lhs.m01 * rhs.m11) + (lhs.m02 * rhs.m21) + (lhs.m03 * rhs.m31);
            newMatrix.m02 = (lhs.m00 * rhs.m02) + (lhs.m01 * rhs.m12) + (lhs.m02 * rhs.m22) + (lhs.m03 * rhs.m32);
            newMatrix.m03 = (lhs.m00 * rhs.m03) + (lhs.m01 * rhs.m13) + (lhs.m02 * rhs.m23) + (lhs.m03 * rhs.m33);

            newMatrix.m10 = (lhs.m10 * rhs.m00) + (lhs.m11 * rhs.m10) + (lhs.m12 * rhs.m20) + (lhs.m13 * rhs.m30);
            newMatrix.m11 = (lhs.m10 * rhs.m01) + (lhs.m11 * rhs.m11) + (lhs.m12 * rhs.m21) + (lhs.m13 * rhs.m31);
            newMatrix.m12 = (lhs.m10 * rhs.m02) + (lhs.m11 * rhs.m12) + (lhs.m12 * rhs.m22) + (lhs.m13 * rhs.m32);
            newMatrix.m13 = (lhs.m10 * rhs.m03) + (lhs.m11 * rhs.m13) + (lhs.m12 * rhs.m23) + (lhs.m13 * rhs.m33);

            newMatrix.m20 = (lhs.m20 * rhs.m00) + (lhs.m21 * rhs.m10) + (lhs.m22 * rhs.m20) + (lhs.m23 * rhs.m30);
            newMatrix.m21 = (lhs.m20 * rhs.m01) + (lhs.m21 * rhs.m11) + (lhs.m22 * rhs.m21) + (lhs.m23 * rhs.m31);
            newMatrix.m22 = (lhs.m20 * rhs.m02) + (lhs.m21 * rhs.m12) + (lhs.m22 * rhs.m22) + (lhs.m23 * rhs.m32);
            newMatrix.m23 = (lhs.m20 * rhs.m03) + (lhs.m21 * rhs.m13) + (lhs.m22 * rhs.m23) + (lhs.m23 * rhs.m33);

            newMatrix.m30 = (lhs.m30 * rhs.m00) + (lhs.m31 * rhs.m10) + (lhs.m32 * rhs.m20) + (lhs.m33 * rhs.m30);
            newMatrix.m31 = (lhs.m30 * rhs.m01) + (lhs.m31 * rhs.m11) + (lhs.m32 * rhs.m21) + (lhs.m33 * rhs.m31);
            newMatrix.m32 = (lhs.m30 * rhs.m02) + (lhs.m31 * rhs.m12) + (lhs.m32 * rhs.m22) + (lhs.m33 * rhs.m32);
            newMatrix.m33 = (lhs.m30 * rhs.m03) + (lhs.m31 * rhs.m13) + (lhs.m32 * rhs.m23) + (lhs.m33 * rhs.m33);

            return(newMatrix);
        }
コード例 #4
0
        //
        // Resumen:
        //     Creates a translation, rotation and scaling matrix.
        public static MyMatrix4x4 TRS(Vec3 pos, MyQuatern q, Vec3 s)
        {
            MyMatrix4x4 translate = MyMatrix4x4.Translate(pos);
            MyMatrix4x4 rotate    = MyMatrix4x4.Rotate(q);
            MyMatrix4x4 scale     = MyMatrix4x4.Scale(s);

            MyMatrix4x4 newM = translate * rotate * scale;

            return(newM);
        }
コード例 #5
0
        //
        // Resumen:
        //     Creates a translation matrix.
        public static MyMatrix4x4 Translate(Vec3 vector)
        {
            MyMatrix4x4 newM = MyMatrix4x4.identity;

            newM.m03 = vector.x;
            newM.m13 = vector.y;
            newM.m23 = vector.z;
            newM.m33 = 1;

            return(newM);
        }
コード例 #6
0
        //
        // Resumen:
        //     Creates a scaling matrix.
        public static MyMatrix4x4 Scale(Vec3 vector)
        {
            MyMatrix4x4 newM = MyMatrix4x4.zero;

            newM.m00 = vector.x;
            newM.m11 = vector.y;
            newM.m22 = vector.z;
            newM.m33 = 1;

            return(newM);
        }
コード例 #7
0
 //
 // Resumen:
 //     Sets this matrix to a translation, rotation and scaling matrix.
 public void SetTRS(Vec3 pos, MyQuatern q, Vec3 s)
 {
     this = MyMatrix4x4.TRS(pos, q, s);
 }
コード例 #8
0
 public bool Equals(MyMatrix4x4 other)
 {
     return(this == other);
 }