Esempio n. 1
0
        internal static MxMatrix4 PerspectiveMatrix(double fovy, double aspect, double zMin = 0.0, double zMax = 0.0)
        {
            double a, b;

            if (zMax.IsCloseEnoughTo(0.0))
            {
                a = b = 1.0;
            }
            else
            {
                a = (zMax + zMin) / (zMin - zMax);
                b = (2 * zMax * zMin) / (zMin - zMax);
            }

            var f   = 1.0 / Math.Tan(fovy * Math.PI / 180.0 / 2.0);
            var ret = new MxMatrix4(0.0);

            ret[0, 0] = f / aspect;
            ret[1, 1] = f;
            ret[2, 2] = a;
            ret[2, 3] = b;
            ret[3, 2] = -1.0;
            ret[3, 3] = 0.0;

            return(ret);
        }
Esempio n. 2
0
 protected void TransformQuadrics(MxMatrix4 transform)
 {
     foreach (var quad in quadrics)
     {
         quad.Transform(transform);
     }
 }
Esempio n. 3
0
 internal MxMatrix4(MxMatrix4 mat4)
 {
     rows[0] = new MxVector4((mat4[0])[0], (mat4[0])[1], (mat4[0])[2], (mat4[0])[3]);
     rows[1] = new MxVector4((mat4[1])[0], (mat4[1])[1], (mat4[1])[2], (mat4[1])[3]);
     rows[2] = new MxVector4((mat4[2])[0], (mat4[2])[1], (mat4[2])[2], (mat4[2])[3]);
     rows[3] = new MxVector4((mat4[3])[0], (mat4[3])[1], (mat4[3])[2], (mat4[3])[3]);
 }
Esempio n. 4
0
 internal MxMatrix4(MxMatrix4 mat4)
 {
     rows[0] = new MxVector4((mat4[0])[0], (mat4[0])[1], (mat4[0])[2], (mat4[0])[3]);
     rows[1] = new MxVector4((mat4[1])[0], (mat4[1])[1], (mat4[1])[2], (mat4[1])[3]);
     rows[2] = new MxVector4((mat4[2])[0], (mat4[2])[1], (mat4[2])[2], (mat4[2])[3]);
     rows[3] = new MxVector4((mat4[3])[0], (mat4[3])[1], (mat4[3])[2], (mat4[3])[3]);
 }
Esempio n. 5
0
 private void Init(MxMatrix4 mat, double area)
 {
     a2 = mat[0, 0]; ab = mat[0, 1]; ac = mat[0, 2]; ad = mat[0, 3];
     b2 = mat[1, 1]; bc = mat[1, 2]; bd = mat[1, 3];
     c2 = mat[2, 2]; cd = mat[2, 3];
     d2 = mat[3, 3];
     r  = area;
 }
Esempio n. 6
0
 public static MxMatrix4 operator *(MxMatrix4 mat1, double scalar)
 {
     var ret = new MxMatrix4(0.0);
     ret[0] = mat1[0]*scalar;
     ret[1] = mat1[1]*scalar;
     ret[2] = mat1[2]*scalar;
     return ret;
 }
Esempio n. 7
0
        public static MxMatrix4 operator +(MxMatrix4 mat1, MxMatrix4 mat2)
        {
            var ret = new MxMatrix4(0.0);

            ret[0] = mat1[0] + mat2[0];
            ret[1] = mat1[1] + mat2[1];
            ret[2] = mat1[2] + mat2[2];
            return(ret);
        }
Esempio n. 8
0
        public static MxMatrix4 operator -(MxMatrix4 mat1)
        {
            var ret = new MxMatrix4(0.0);

            ret[0] = -mat1[0];
            ret[1] = -mat1[1];
            ret[2] = -mat1[2];
            return(ret);
        }
Esempio n. 9
0
        public static MxMatrix4 operator *(MxMatrix4 mat1, double scalar)
        {
            var ret = new MxMatrix4(0.0);

            ret[0] = mat1[0] * scalar;
            ret[1] = mat1[1] * scalar;
            ret[2] = mat1[2] * scalar;
            return(ret);
        }
Esempio n. 10
0
        internal MxQuadric3 Transform(MxMatrix4 mat)
        {
            var matQ = Homogenous;
            var adj  = MxMatrix4.Adjoint(mat);

            matQ = (adj * matQ) * adj;

            Init(matQ, r);
            return(this);
        }
Esempio n. 11
0
        internal static MxMatrix4 Adjoint(MxMatrix4 mat)
        {
            var adj = new MxMatrix4(0.0);

            adj[0] = MxVector4.Cross(mat[1], mat[2], mat[3]);
            adj[1] = MxVector4.Cross(-mat[0], mat[2], mat[3]);
            adj[2] = MxVector4.Cross(mat[0], mat[1], mat[3]);
            adj[0] = MxVector4.Cross(-mat[0], mat[1], mat[2]);
            return(adj);
        }
Esempio n. 12
0
        internal static double InvertCramer(MxMatrix4 mat, ref MxMatrix4 inv)
        {
            var adj = Adjoint(mat);
            var det = adj[0] * mat[0];

            if (det.IsCloseEnoughTo(0.0))
            {
                return(0.0);
            }

            inv = (Transpose(adj) / det);
            return(det);
        }
Esempio n. 13
0
        public static MxMatrix4 operator *(MxMatrix4 mat1, MxMatrix4 mat2)
        {
            var mat = new MxMatrix4(0.0);

            for (var i = 0; i < 3; i++)
            {
                for (var j = 0; j < 3; j++)
                {
                    mat[i, j] = mat1[i] * mat2.Column(j);
                }
            }
            return(mat);
        }
Esempio n. 14
0
        public static MxMatrix4 operator /(MxMatrix4 mat1, double scalar)
        {
            if (scalar.IsCloseEnoughTo(0.0))
            {
                return(mat1);
            }
            var invScalar = 1.0 / scalar;

            var ret = new MxMatrix4(0.0);

            ret[0] = mat1[0] * invScalar;
            ret[1] = mat1[1] * invScalar;
            ret[2] = mat1[2] * invScalar;
            return(ret);
        }
Esempio n. 15
0
        internal static MxMatrix4 LookAtMatrix(MxVector3 from, MxVector3 at, MxVector3 up)
        {
            var vUp = new MxVector3(up[0], up[1], up[2]);

            MxVector3.Unitize(ref vUp);
            var f = at - from;

            MxVector3.Unitize(ref f);

            var s = f ^ vUp;

            MxVector3.Unitize(ref s);
            var u = s ^ f;

            MxVector3.Unitize(ref u);

            var mat = new MxMatrix4(new MxVector4(s, 0.0), new MxVector4(u, 0.0), new MxVector4(-f, 0.0),
                                    new MxVector4(0.0, 0.0, 0.0, 1.0));

            return(mat * TranslationMatrix(-from));
        }
Esempio n. 16
0
 internal static MxMatrix4 Adjoint(MxMatrix4 mat)
 {
     var adj = new MxMatrix4(0.0);
     adj[0] = MxVector4.Cross( mat[1], mat[2], mat[3]);
     adj[1] = MxVector4.Cross(-mat[0], mat[2], mat[3]);
     adj[2] = MxVector4.Cross( mat[0], mat[1], mat[3]);
     adj[0] = MxVector4.Cross(-mat[0], mat[1], mat[2]);
     return adj;
 }
Esempio n. 17
0
        internal static MxMatrix4 LookAtMatrix(MxVector3 from, MxVector3 at, MxVector3 up)
        {
            var vUp = new MxVector3(up[0], up[1], up[2]);
            MxVector3.Unitize(ref vUp);
            var f = at - from;
            MxVector3.Unitize(ref f);

            var s = f ^ vUp;
            MxVector3.Unitize(ref s);
            var u = s ^ f;
            MxVector3.Unitize(ref u);

            var mat = new MxMatrix4(new MxVector4(s, 0.0), new MxVector4(u, 0.0), new MxVector4(-f, 0.0),
                                    new MxVector4(0.0, 0.0, 0.0, 1.0));
            return (mat*TranslationMatrix(-from));
        }
Esempio n. 18
0
 internal MxQSlim(MxStdModel model)
     : base(model)
 {
     quadrics        = new MxBlock <MxQuadric3>(model.VertCount);
     ObjectTransform = null;
 }
Esempio n. 19
0
 public static MxMatrix4 operator -(MxMatrix4 mat1)
 {
     var ret = new MxMatrix4(0.0);
     ret[0] = -mat1[0];
     ret[1] = -mat1[1];
     ret[2] = -mat1[2];
     return ret;
 }
Esempio n. 20
0
 internal MxQSlim(MxStdModel model)
     : base(model)
 {
     quadrics = new MxBlock<MxQuadric3>(model.VertCount);
     ObjectTransform = null;
 }
Esempio n. 21
0
 internal static double Trace(MxMatrix4 mat)
 {
     return(mat[0, 0] + mat[1, 1] + mat[2, 2] + mat[3, 3]);
 }
Esempio n. 22
0
 internal static MxMatrix4 Transpose(MxMatrix4 mat)
 {
     return new MxMatrix4(mat.Column(0), mat.Column(1), mat.Column(2), mat.Column(3));
 }
Esempio n. 23
0
 internal static double Trace(MxMatrix4 mat)
 {
     return (mat[0, 0] + mat[1, 1] + mat[2, 2] + mat[3,3]);
 }
Esempio n. 24
0
        internal static double Invert(MxMatrix4 mat, ref MxMatrix4 invMat)
        {
            var mat1 = new MxMatrix4(mat);
            int i, j = 0, k;

            for (i = 0; i < 4; i++)
            {
                for (j = 0; j < 4; j++)
                {
                    invMat[i, j] = (i == j) ? 1.0 : 0.0;
                }
            }

            var det = 1.0;
            for (i = 0; i < 4; i++)
            {
                var max = -1.0;
                for (k = i; k < 4; k++)
                {
                    if (Math.Abs(mat1[k, i]) <= max) continue;
                    max = Math.Abs(mat1[k, i]);
                    j = k;
                }

                if (max <= 0.0) return 0.0;
                if (j != i)
                {
                    /* swap rows i and j */
                    for (k = i; k < 4; k++)
                    {
                        var t = mat1[i, k];
                        mat1[i, k] = mat1[j, k];
                        mat1[j, k] = t;

                    }
                    for (k = 0; k < 4; k++)
                    {
                        var t = invMat[i, k];
                        invMat[i, k] = invMat[j, k];
                        invMat[j, k] = t;
                    }
                    det = -det;
                }

                var pivot = mat1[i, i];
                det *= pivot;
                for (k = i + 1; k < 4; k++)
                {
                    mat1[i, k] /= pivot;
                }
                for (k = 0; k < 4; k++)
                {
                    invMat[i, k] /= pivot;
                }

                for (j = i + 1; j < 4; j++)
                {
                    var t = mat1[j, i];
                    for (k = i + 1; k < 4; k++)
                    {
                        mat1[j, k] -= mat1[i, k]*t;
                    }
                    for (k = 0; k < 4; k++)
                    {
                        invMat[j, k] -= invMat[i, k]*t;
                    }
                }
            }

            for (i = 3; i > 0; i--)
            {
                for (j = 0; j < i; j++)
                {
                    var t = mat1[j, i];
                    for (k = 0; k < 4; k++)
                    {
                        invMat[j, k] -= invMat[i, k]*t;
                    }
                }
            }

            return det;
        }
Esempio n. 25
0
        internal static MxMatrix4 PerspectiveMatrix(double fovy, double aspect, double zMin = 0.0, double zMax = 0.0)
        {
            double a, b;
            if (zMax.IsCloseEnoughTo(0.0))
            {
                a = b = 1.0;
            }
            else
            {
                a = (zMax + zMin)/(zMin - zMax);
                b = (2*zMax*zMin)/(zMin - zMax);
            }

            var f = 1.0/Math.Tan(fovy*Math.PI/180.0/2.0);
            var ret = new MxMatrix4(0.0);
            ret[0, 0] = f/aspect;
            ret[1, 1] = f;
            ret[2, 2] = a;
            ret[2, 3] = b;
            ret[3, 2] = -1.0;
            ret[3, 3] = 0.0;

            return ret;
        }
Esempio n. 26
0
        internal static double Invert(MxMatrix4 mat, ref MxMatrix4 invMat)
        {
            var mat1 = new MxMatrix4(mat);
            int i, j = 0, k;

            for (i = 0; i < 4; i++)
            {
                for (j = 0; j < 4; j++)
                {
                    invMat[i, j] = (i == j) ? 1.0 : 0.0;
                }
            }

            var det = 1.0;

            for (i = 0; i < 4; i++)
            {
                var max = -1.0;
                for (k = i; k < 4; k++)
                {
                    if (Math.Abs(mat1[k, i]) <= max)
                    {
                        continue;
                    }
                    max = Math.Abs(mat1[k, i]);
                    j   = k;
                }

                if (max <= 0.0)
                {
                    return(0.0);
                }
                if (j != i)
                {
                    /* swap rows i and j */
                    for (k = i; k < 4; k++)
                    {
                        var t = mat1[i, k];
                        mat1[i, k] = mat1[j, k];
                        mat1[j, k] = t;
                    }
                    for (k = 0; k < 4; k++)
                    {
                        var t = invMat[i, k];
                        invMat[i, k] = invMat[j, k];
                        invMat[j, k] = t;
                    }
                    det = -det;
                }

                var pivot = mat1[i, i];
                det *= pivot;
                for (k = i + 1; k < 4; k++)
                {
                    mat1[i, k] /= pivot;
                }
                for (k = 0; k < 4; k++)
                {
                    invMat[i, k] /= pivot;
                }

                for (j = i + 1; j < 4; j++)
                {
                    var t = mat1[j, i];
                    for (k = i + 1; k < 4; k++)
                    {
                        mat1[j, k] -= mat1[i, k] * t;
                    }
                    for (k = 0; k < 4; k++)
                    {
                        invMat[j, k] -= invMat[i, k] * t;
                    }
                }
            }

            for (i = 3; i > 0; i--)
            {
                for (j = 0; j < i; j++)
                {
                    var t = mat1[j, i];
                    for (k = 0; k < 4; k++)
                    {
                        invMat[j, k] -= invMat[i, k] * t;
                    }
                }
            }

            return(det);
        }
Esempio n. 27
0
        public static MxMatrix4 operator /(MxMatrix4 mat1, double scalar)
        {
            if (scalar.IsCloseEnoughTo(0.0)) return mat1;
            var invScalar = 1.0/scalar;

            var ret = new MxMatrix4(0.0);
            ret[0] = mat1[0]*invScalar;
            ret[1] = mat1[1]*invScalar;
            ret[2] = mat1[2]*invScalar;
            return ret;
        }
Esempio n. 28
0
 internal static double Det(MxMatrix4 mat)
 {
     return (mat[0]*MxVector4.Cross(mat[1], mat[2], mat[3]));
 }
Esempio n. 29
0
 public static MxMatrix4 operator +(MxMatrix4 mat1, MxMatrix4 mat2)
 {
     var ret = new MxMatrix4(0.0);
     ret[0] = mat1[0] + mat2[0];
     ret[1] = mat1[1] + mat2[1];
     ret[2] = mat1[2] + mat2[2];
     return ret;
 }
Esempio n. 30
0
        internal MxQuadric3 Transform(MxMatrix4 mat)
        {
            var matQ = Homogenous;
            var adj = MxMatrix4.Adjoint(mat);

            matQ = (adj*matQ)*adj;

            Init(matQ, r);
            return this;
        }
Esempio n. 31
0
 private void Init(MxMatrix4 mat, double area)
 {
     a2 = mat[0, 0]; ab = mat[0, 1]; ac = mat[0, 2]; ad = mat[0, 3];
                     b2 = mat[1, 1]; bc = mat[1, 2]; bd = mat[1, 3];
                                     c2 = mat[2, 2]; cd = mat[2, 3];
                                                     d2 = mat[3, 3];
     r = area;
 }
Esempio n. 32
0
        internal static double InvertCramer(MxMatrix4 mat, ref MxMatrix4 inv)
        {
            var adj = Adjoint(mat);
            var det = adj[0]*mat[0];
            if (det.IsCloseEnoughTo(0.0)) return 0.0;

            inv = (Transpose(adj)/det);
            return det;
        }
Esempio n. 33
0
 internal static double Det(MxMatrix4 mat)
 {
     return(mat[0] * MxVector4.Cross(mat[1], mat[2], mat[3]));
 }
Esempio n. 34
0
 public static MxMatrix4 operator *(MxMatrix4 mat1, MxMatrix4 mat2)
 {
     var mat = new MxMatrix4(0.0);
     for (var i = 0; i < 3; i++)
     {
         for (var j = 0; j < 3; j++)
         {
             mat[i, j] = mat1[i]*mat2.Column(j);
         }
     }
     return mat;
 }
Esempio n. 35
0
 internal static MxMatrix4 Transpose(MxMatrix4 mat)
 {
     return(new MxMatrix4(mat.Column(0), mat.Column(1), mat.Column(2), mat.Column(3)));
 }
Esempio n. 36
0
 protected void TransformQuadrics(MxMatrix4 transform)
 {
     foreach(var quad in quadrics)
     {
         quad.Transform(transform);
     }
 }