Esempio n. 1
0
        //!Get the matrix dot product, most commonly used form of matrix multiplication
        public static GLMatrix4d operator*(GLMatrix4d one, GLMatrix4d two)
        {
            GLMatrix4d ret = new GLMatrix4d();

            for (byte j = 0; j < 4; ++j)
            {
                ret.m[j] = one.m[j] * two.m[0]
                           + one.m[j + 4] * two.m[1]
                           + one.m[j + 8] * two.m[2]
                           + one.m[j + 12] * two.m[3];

                ret.m[j + 4] = one.m[j] * two.m[4]
                               + one.m[j + 4] * two.m[5]
                               + one.m[j + 8] * two.m[6]
                               + one.m[j + 12] * two.m[7];

                ret.m[j + 8] = one.m[j] * two.m[8]
                               + one.m[j + 4] * two.m[9]
                               + one.m[j + 8] * two.m[10]
                               + one.m[j + 12] * two.m[11];

                ret.m[j + 12] = one[j] * two.m[12]
                                + one[j + 4] * two.m[13]
                                + one[j + 8] * two.m[14]
                                + one[j + 12] * two.m[15];
            }
            return(ret);
        }
Esempio n. 2
0
        //!Apply an OpenGL rotation matrix to this
        public GLMatrix4d applyRotateZ(double angle)
        {
            GLMatrix4d temp = new GLMatrix4d();

            temp.loadRotateZ(angle);
            return(mult3by3(temp));
        }
Esempio n. 3
0
        //!Get the adjoint matrix
        public GLMatrix4d adjoint()
        {
            GLMatrix4d ret = new GLMatrix4d();

            ret.m[0] = cofactorm0();
            ret.m[1] = -cofactorm4();
            ret.m[2] = cofactorm8();
            ret.m[3] = -cofactorm12();

            ret.m[4] = -cofactorm1();
            ret.m[5] = cofactorm5();
            ret.m[6] = -cofactorm9();
            ret.m[7] = cofactorm13();

            ret.m[8]  = cofactorm2();
            ret.m[9]  = -cofactorm6();
            ret.m[10] = cofactorm10();
            ret.m[11] = -cofactorm14();

            ret.m[12] = -cofactorm3();
            ret.m[13] = cofactorm7();
            ret.m[14] = -cofactorm11();
            ret.m[15] = cofactorm15();

            return(ret);
        }
Esempio n. 4
0
     //!Get the adjoint matrix
     public GLMatrix4d adjoint()
     {
         GLMatrix4d ret = new GLMatrix4d();
 
         ret.m[0] = cofactorm0();
         ret.m[1] = -cofactorm4();
         ret.m[2] = cofactorm8();
         ret.m[3] = -cofactorm12();
 
         ret.m[4] = -cofactorm1();
         ret.m[5] = cofactorm5();
         ret.m[6] = -cofactorm9();
         ret.m[7] = cofactorm13();
 
         ret.m[8] = cofactorm2();
         ret.m[9] = -cofactorm6();
         ret.m[10] = cofactorm10();
         ret.m[11] = -cofactorm14();
 
         ret.m[12] = -cofactorm3();
         ret.m[13] = cofactorm7();
         ret.m[14] = -cofactorm11();
         ret.m[15] = cofactorm15();
 
         return ret;
     }
Esempio n. 5
0
        //!Apply an OpenGL rotation matrix to this
        public GLMatrix4d applyRotate(double angle, double x, double y, double z)
        {
            GLMatrix4d temp = new GLMatrix4d();

            temp.loadRotate(angle, x, y, z);
            return(mult3by3(temp));
        }
Esempio n. 6
0
        //!OpenGL orthogonal matrix
        public static GLMatrix4d glOrtho(double left, double right,
                                         double bottom, double top,
                                         double zNear, double zFar)
        {
            GLMatrix4d ret = new GLMatrix4d();

            ret.m[0] = 2 / (right - left);
            ret.m[1] = 0;
            ret.m[2] = 0;
            ret.m[3] = 0;

            ret.m[4] = 0;
            ret.m[5] = 2 / (top - bottom);
            ret.m[6] = 0;
            ret.m[7] = 0;

            ret.m[8]  = 0;
            ret.m[9]  = 0;
            ret.m[10] = -2 / (zFar - zNear);
            ret.m[11] = 0;

            ret.m[12] = -(right + left) / (right - left);
            ret.m[13] = -(top + bottom) / (top - bottom);
            ret.m[14] = -(zFar + zNear) / (zFar - zNear);
            ret.m[15] = 1;

            return(ret);
        }
Esempio n. 7
0
    public static void ApplyRotToGLMatrix4d( ref GLMatrix4d matrix, Rot rot )
    {
        double fRotAngle = 0;
            Vector3 vAxis = new Vector3();
            mvMath.Rot2AxisAngle( ref vAxis, ref fRotAngle, rot );

            matrix.applyRotate( (float)( fRotAngle / Math.PI * 180 ), (float)vAxis.x, (float)vAxis.y, (float)vAxis.z );
    }
Esempio n. 8
0
        //!Subtract a matrix from this matrix
        public static GLMatrix4d operator-(GLMatrix4d one, GLMatrix4d two)
        {
            GLMatrix4d result = new GLMatrix4d();

            for (byte i = 0; i < 16; ++i)
            {
                result.m[i] = one.m[i] - two.m[i];
            }
            return(result);
        }
Esempio n. 9
0
        //!Divide this matrix by a scalar
        public static GLMatrix4d operator/(GLMatrix4d mat, double val)
        {
            GLMatrix4d result = new GLMatrix4d();

            for (byte i = 0; i < 16; ++i)
            {
                result.m[i] = mat.m[i] / val;
            }
            return(result);
        }
Esempio n. 10
0
        //!Apply an OpenGL rotation matrix to this
        public GLMatrix4d applyRotateXYZ(double x, double y, double z)
        {
            GLMatrix4d temp = new GLMatrix4d();

            temp.loadRotateX(x);
            mult3by3(temp);
            temp.loadRotateY(y);
            mult3by3(temp);
            temp.loadRotateZ(z);
            return(mult3by3(temp));
        }
Esempio n. 11
0
        //!Adjoint method inverse, constant time inversion implementation
        public GLMatrix4d inverse()
        {
            GLMatrix4d ret = new GLMatrix4d(adjoint());

            double determinant = m[0] * ret[0] + m[1] * ret[4] + m[2] * ret[8] + m[3] * ret[12];

            //assert(determinant!=0 && "Singular matrix has no inverse");

            ret /= determinant;
            return(ret);
        }
Esempio n. 12
0
        //!Special glMatricies
        //!Identity matrix
        public static GLMatrix4d identity()
        {
            GLMatrix4d ret = new GLMatrix4d();

            ret.m[0] = 1;   ret.m[4] = 0;   ret.m[8] = 0;  ret.m[12] = 0;
            ret.m[1] = 0;   ret.m[5] = 1;   ret.m[9] = 0;  ret.m[13] = 0;
            ret.m[2] = 0;   ret.m[6] = 0;   ret.m[10] = 1;  ret.m[14] = 0;
            ret.m[3] = 0;   ret.m[7] = 0;   ret.m[11] = 0;  ret.m[15] = 1;

            return(ret);
        }
Esempio n. 13
0
        public override bool Equals(object twoobject)
        {
            GLMatrix4d two = twoobject as GLMatrix4d;

            for (int i = 0; i < 16; i++)
            {
                if (m[i] != two.m[i])
                {
                    return(false);
                }
            }
            return(true);
        }
Esempio n. 14
0
        //!Return the transpose
        public GLMatrix4d getTranspose()
        {
            GLMatrix4d temp = new GLMatrix4d();

            for (int i = 0; i < 4; ++i)
            {
                for (int j = 0; j < 4; ++j)
                {
                    temp.m[j + i * 4] = m[i + j * 4];
                }
            }
            return(temp);
        }
Esempio n. 15
0
        //!Apply the matrix dot product to this matrix
        //!unrolling by sebastien bloc
        public GLMatrix4d mult3by3(GLMatrix4d mat)
        {
            GLMatrix4d temp = new GLMatrix4d(this);

            m[0] = temp.m[0] * mat.m[0] + temp.m[4] * mat.m[1] + temp.m[8] * mat.m[2];
            m[4] = temp.m[0] * mat.m[4] + temp.m[4] * mat.m[5] + temp.m[8] * mat.m[6];
            m[8] = temp.m[0] * mat.m[8] + temp.m[4] * mat.m[9] + temp.m[8] * mat.m[10];

            m[1] = temp.m[1] * mat.m[0] + temp.m[5] * mat.m[1] + temp.m[9] * mat.m[2];
            m[5] = temp.m[1] * mat.m[4] + temp.m[5] * mat.m[5] + temp.m[9] * mat.m[6];
            m[9] = temp.m[1] * mat.m[8] + temp.m[5] * mat.m[9] + temp.m[9] * mat.m[10];

            m[2]  = temp.m[2] * mat.m[0] + temp.m[6] * mat.m[1] + temp.m[10] * mat.m[2];
            m[6]  = temp.m[2] * mat.m[4] + temp.m[6] * mat.m[5] + temp.m[10] * mat.m[6];
            m[10] = temp.m[2] * mat.m[8] + temp.m[6] * mat.m[9] + temp.m[10] * mat.m[10];

            m[3]  = temp.m[3] * mat.m[0] + temp.m[7] * mat.m[1] + temp.m[11] * mat.m[2];
            m[7]  = temp.m[3] * mat.m[4] + temp.m[7] * mat.m[5] + temp.m[11] * mat.m[6];
            m[11] = temp.m[3] * mat.m[8] + temp.m[7] * mat.m[9] + temp.m[11] * mat.m[10];
            return(this);
        }
Esempio n. 16
0
 //!Subtract a matrix from this matrix
 public static GLMatrix4d operator-( GLMatrix4d one, GLMatrix4d two)
 {
     GLMatrix4d result = new GLMatrix4d();
     for(byte i = 0; i < 16; ++i)
     {
         result.m[i] = one.m[i] - two.m[i];
     }
     return result;
 }
Esempio n. 17
0
 //!Apply an OpenGL rotation matrix to this
 public GLMatrix4d applyRotateXYZ(double x,double y,double z)
 {
     GLMatrix4d temp = new GLMatrix4d();
     temp.loadRotateX(x);
     mult3by3(temp);
     temp.loadRotateY(y);
     mult3by3(temp);
     temp.loadRotateZ(z);
     return mult3by3(temp);
 }
Esempio n. 18
0
 //!Copy a matrix
 public GLMatrix4d(GLMatrix4d mat)
 { 
     Buffer.BlockCopy( mat.m, 0, m, 0, Buffer.ByteLength( mat.m ) );
 }
Esempio n. 19
0
 //!Apply an OpenGL rotation matrix to this
 public GLMatrix4d applyRotateZ(double angle)
 {
     GLMatrix4d temp = new GLMatrix4d();
     temp.loadRotateZ(angle);
     return mult3by3(temp);
 }
Esempio n. 20
0
 //!Apply an OpenGL rotation matrix to this
 public GLMatrix4d applyRotate(double angle, double x, double y, double z)
 {
     GLMatrix4d temp = new GLMatrix4d();
     temp.loadRotate(angle,x,y,z);
     return mult3by3(temp);
 }
Esempio n. 21
0
     //!Special glMatricies
     //!Identity matrix
     public static GLMatrix4d identity()
     {
         GLMatrix4d ret = new GLMatrix4d();
 
         ret.m[0] = 1;   ret.m[4] = 0;   ret.m[8]  = 0;  ret.m[12] = 0;
         ret.m[1] = 0;   ret.m[5] = 1;   ret.m[9]  = 0;  ret.m[13] = 0;
         ret.m[2] = 0;   ret.m[6] = 0;   ret.m[10] = 1;  ret.m[14] = 0;
         ret.m[3] = 0;   ret.m[7] = 0;   ret.m[11] = 0;  ret.m[15] = 1;
 
         return ret;
     }
Esempio n. 22
0
 //!Return the transpose
 public GLMatrix4d getTranspose()
 {
     GLMatrix4d temp = new GLMatrix4d();
     for( int i = 0; i < 4; ++i)
         for( int j = 0; j < 4; ++j)
             temp.m[j+i*4] = m[i+j*4];
     return temp;
 }
Esempio n. 23
0
     //!Apply the matrix dot product to this matrix
     //!unrolling by sebastien bloc
     public GLMatrix4d mult3by3(GLMatrix4d mat)
     {
         GLMatrix4d temp = new GLMatrix4d(this);
         m[0] = temp.m[0]*mat.m[0]+temp.m[4]*mat.m[1]+temp.m[8]*mat.m[2];
         m[4] = temp.m[0]*mat.m[4]+temp.m[4]*mat.m[5]+temp.m[8]*mat.m[6];
         m[8] = temp.m[0]*mat.m[8]+temp.m[4]*mat.m[9]+temp.m[8]*mat.m[10];
 
         m[1] = temp.m[1]*mat.m[0]+temp.m[5]*mat.m[1]+temp.m[9]*mat.m[2];
         m[5] = temp.m[1]*mat.m[4]+temp.m[5]*mat.m[5]+temp.m[9]*mat.m[6];
         m[9] = temp.m[1]*mat.m[8]+temp.m[5]*mat.m[9]+temp.m[9]*mat.m[10];
 
         m[2] = temp.m[2]*mat.m[0]+temp.m[6]*mat.m[1]+temp.m[10]*mat.m[2];
         m[6] = temp.m[2]*mat.m[4]+temp.m[6]*mat.m[5]+temp.m[10]*mat.m[6];
         m[10] = temp.m[2]*mat.m[8]+temp.m[6]*mat.m[9]+temp.m[10]*mat.m[10];
 
         m[3] = temp.m[3]*mat.m[0]+temp.m[7]*mat.m[1]+temp.m[11]*mat.m[2];
         m[7] = temp.m[3]*mat.m[4]+temp.m[7]*mat.m[5]+temp.m[11]*mat.m[6];
         m[11] = temp.m[3]*mat.m[8]+temp.m[7]*mat.m[9]+temp.m[11]*mat.m[10];
         return this;
     }
Esempio n. 24
0
     //!OpenGL orthogonal matrix
     public static GLMatrix4d glOrtho(double left, double right,
                     double bottom, double top,
                 double zNear, double zFar)
     {
         GLMatrix4d ret = new GLMatrix4d();
 
         ret.m[0] = 2/(right-left);
         ret.m[1] = 0;
         ret.m[2] = 0;
         ret.m[3] = 0;
 
         ret.m[4] = 0;
         ret.m[5] = 2/(top-bottom);
         ret.m[6] = 0;
         ret.m[7] = 0;
 
         ret.m[8] = 0;
         ret.m[9] = 0;
         ret.m[10] = -2/(zFar-zNear);
         ret.m[11] = 0;
 
         ret.m[12] = -(right+left)/(right-left);
         ret.m[13] = -(top+bottom)/(top-bottom);
         ret.m[14] = -(zFar+zNear)/(zFar-zNear);
         ret.m[15] = 1;
 
         return ret;
     }
Esempio n. 25
0
 //!Divide this matrix by a scalar
 public static GLMatrix4d operator/( GLMatrix4d mat, double val)
 {
     GLMatrix4d result = new GLMatrix4d();
     for(byte i = 0; i < 16; ++i)
     {
         result.m[i] = mat.m[i] / val;
     }
     return result;
 }
Esempio n. 26
0
 //!Copy a matrix
 public GLMatrix4d(GLMatrix4d mat)
 {
     Buffer.BlockCopy(mat.m, 0, m, 0, Buffer.ByteLength(mat.m));
 }
Esempio n. 27
0
     //!Adjoint method inverse, constant time inversion implementation
     public GLMatrix4d inverse() 
     {
         GLMatrix4d ret = new GLMatrix4d(adjoint());
 
         double determinant = m[0]*ret[0] + m[1]*ret[4] + m[2]*ret[8] + m[3]*ret[12];
         //assert(determinant!=0 && "Singular matrix has no inverse");
 
         ret /= determinant;
         return ret;
     }
Esempio n. 28
0
     //!Get the matrix dot product, most commonly used form of matrix multiplication
     public static GLMatrix4d operator* ( GLMatrix4d one, GLMatrix4d two )
     {
         GLMatrix4d ret = new GLMatrix4d();
         for(byte j = 0; j < 4; ++j)
         {
             ret.m[j] = one.m[j]*two.m[0]
                      + one.m[j+4]*two.m[1]
                      + one.m[j+8]*two.m[2]
                      + one.m[j+12]*two.m[3];
 
             ret.m[j+4] = one.m[j]*two.m[4]
                        + one.m[j+4]*two.m[5]
                        + one.m[j+8]*two.m[6]
                        + one.m[j+12]*two.m[7];
 
             ret.m[j+8] = one.m[j]*two.m[8]
                        + one.m[j+4]*two.m[9]
                        + one.m[j+8]*two.m[10]
                        + one.m[j+12]*two.m[11];
 
             ret.m[j+12] = one[j]*two.m[12]
                         + one[j+4]*two.m[13]
                         + one[j+8]*two.m[14]
                         + one[j+12]*two.m[15];
         }
         return ret;
     }