Exemplo n.º 1
0
 public static Matrix43 operator *(Matrix43 Left, Matrix43 Right)
 {
     Matrix44 l = new Matrix44(Left, new Vector4(0, 0, 0, 1));
     Matrix44 r = new Matrix44(Right, new Vector4(0, 0, 0, 1));
     Matrix44 Result = l * r;
     Matrix43 result2 = new Matrix43();
     for (int row = 0; row < 4; row++)
     {
         for (int col = 0; col < 3; col++)
         {
             result2[row, col] = Result[row,col];
         }
     }
     return result2;
 }
Exemplo n.º 2
0
        public static Matrix44 operator *(Matrix44 Left, Matrix44 Right)
        {
            Matrix44 tmpMatrix = new Matrix44();

            tmpMatrix[0] = (Left[0] * Right[0]) + (Left[4] * Right[1]) + (Left[8] * Right[2]) + (Left[12] * Right[3]);
            tmpMatrix[1] = (Left[1] * Right[0]) + (Left[5] * Right[1]) + (Left[9] * Right[2]) + (Left[13] * Right[3]);
            tmpMatrix[2] = (Left[2] * Right[0]) + (Left[6] * Right[1]) + (Left[10] * Right[2]) + (Left[14] * Right[3]);
            tmpMatrix[3] = (Left[3] * Right[0]) + (Left[7] * Right[1]) + (Left[11] * Right[2]) + (Left[15] * Right[3]);

            tmpMatrix[4] = (Left[0] * Right[4]) + (Left[4] * Right[5]) + (Left[8] * Right[6]) + (Left[12] * Right[7]);
            tmpMatrix[5] = (Left[1] * Right[4]) + (Left[5] * Right[5]) + (Left[9] * Right[6]) + (Left[13] * Right[7]);
            tmpMatrix[6] = (Left[2] * Right[4]) + (Left[6] * Right[5]) + (Left[10] * Right[6]) + (Left[14] * Right[7]);
            tmpMatrix[7] = (Left[3] * Right[4]) + (Left[7] * Right[5]) + (Left[11] * Right[6]) + (Left[15] * Right[7]);

            tmpMatrix[8] = (Left[0] * Right[8]) + (Left[4] * Right[9]) + (Left[8] * Right[10]) + (Left[12] * Right[11]);
            tmpMatrix[9] = (Left[1] * Right[8]) + (Left[5] * Right[9]) + (Left[9] * Right[10]) + (Left[13] * Right[11]);
            tmpMatrix[10] = (Left[2] * Right[8]) + (Left[6] * Right[9]) + (Left[10] * Right[10]) + (Left[14] * Right[11]);
            tmpMatrix[11] = (Left[3] * Right[8]) + (Left[7] * Right[9]) + (Left[11] * Right[10]) + (Left[15] * Right[11]);

            tmpMatrix[12] = (Left[0] * Right[12]) + (Left[4] * Right[13]) + (Left[8] * Right[14]) + (Left[12] * Right[15]);
            tmpMatrix[13] = (Left[1] * Right[12]) + (Left[5] * Right[13]) + (Left[9] * Right[14]) + (Left[13] * Right[15]);
            tmpMatrix[14] = (Left[2] * Right[12]) + (Left[6] * Right[13]) + (Left[10] * Right[14]) + (Left[14] * Right[15]);
            tmpMatrix[15] = (Left[3] * Right[12]) + (Left[7] * Right[13]) + (Left[11] * Right[14]) + (Left[15] * Right[15]);
            return tmpMatrix;
        }
Exemplo n.º 3
0
 public void Scale(Vector3 scale)
 {
     Matrix44 m = Matrix44.CreateScale(scale);
     if (MtxMode == NDSMatrixMode.Position || MtxMode == NDSMatrixMode.Position_Vector) CurPosMtx = CurPosMtx * m;
 }
Exemplo n.º 4
0
 public void Translate(Vector3 translation)
 {
     Matrix44 m = Matrix44.CreateTranslation(translation);
     if (MtxMode == NDSMatrixMode.Position || MtxMode == NDSMatrixMode.Position_Vector) CurPosMtx = CurPosMtx * m;
     if (MtxMode == NDSMatrixMode.Position_Vector) CurDirMtx = CurDirMtx * m;
 }
Exemplo n.º 5
0
 public void PopMatrix(int num)
 {
     StackPtr -= num;
     if (MtxMode == NDSMatrixMode.Position || MtxMode == NDSMatrixMode.Position_Vector) CurPosMtx = PosMtxStack[StackPtr];
     if (MtxMode == NDSMatrixMode.Position_Vector) CurDirMtx = DirMtxStack[StackPtr];
 }
Exemplo n.º 6
0
 public void RestoreMatrix(uint index)
 {
     index &= 0x1F;
     if (MtxMode == NDSMatrixMode.Position || MtxMode == NDSMatrixMode.Position_Vector) CurPosMtx = PosMtxStack[index];
     if (MtxMode == NDSMatrixMode.Position_Vector) CurDirMtx = DirMtxStack[index];
 }
Exemplo n.º 7
0
 public void MultMatrix44(Matrix44 mtx)
 {
     if (MtxMode == NDSMatrixMode.Position || MtxMode == NDSMatrixMode.Position_Vector) CurPosMtx = CurPosMtx * mtx;
     if (MtxMode == NDSMatrixMode.Position_Vector) CurDirMtx = CurDirMtx * mtx;
 }
Exemplo n.º 8
0
 public void MultMatrix43(Matrix43 mtx)
 {
     if (MtxMode == NDSMatrixMode.Position || MtxMode == NDSMatrixMode.Position_Vector) CurPosMtx = CurPosMtx * new Matrix44(mtx, new Vector4(0, 0, 0, 1));
     if (MtxMode == NDSMatrixMode.Position_Vector) CurDirMtx = CurDirMtx * new Matrix44(mtx, new Vector4(0, 0, 0, 1));
 }
Exemplo n.º 9
0
 public void Identity()
 {
     if (MtxMode == NDSMatrixMode.Position || MtxMode == NDSMatrixMode.Position_Vector) CurPosMtx = Matrix44.Identity;
     if (MtxMode == NDSMatrixMode.Position_Vector) CurDirMtx = Matrix44.Identity;
 }
Exemplo n.º 10
0
                    public float[] GetMatrix()
                    {
                        /*if ((flag & NNS_G3D_MATFLAG.NNS_G3D_MATFLAG_EFFECTMTX) != 0)
                        {
                            //MTX44 S_ = new MTX44();
                            //S_.Scale(1f / (float)origWidth, 1f / (float)origHeight, 1f);
                            //return ((MTX44)effectMtx).MultMatrix(S_);
                            return effectMtx;
                        }*/
                        Matrix44 m = new Matrix44();//zero!
                        bool Scale = (flag & NNS_G3D_MATFLAG.NNS_G3D_MATFLAG_TEXMTX_SCALEONE) == 0;
                        bool Rotation = (flag & NNS_G3D_MATFLAG.NNS_G3D_MATFLAG_TEXMTX_ROTZERO) == 0;
                        bool Translation = (flag & NNS_G3D_MATFLAG.NNS_G3D_MATFLAG_TEXMTX_TRANSZERO) == 0;
                        /*if (!Scale && !Rotation && !Translation)
                        {
                            m[0, 0] = 1;
                            m[1, 0] = 0;
                            m[0, 1] = 0;
                            m[1, 1] = 1;
                            m[0, 3] = 0;
                            m[1, 3] = 0;
                        }
                        else if (!Scale && !Rotation && Translation)
                        {
                            m[0, 0] = 1;
                            m[1, 1] = 1;

                            m[1, 0] = 0;

                            m[0, 3] = -(transS * origWidth) * 16f;
                            m[1, 3] = (transT * origHeight) * 16f;

                            m[0, 1] = 0;
                        }
                        else if (!Scale && Rotation && !Translation)
                        {
                            Single tmpW, tmpH;

                            tmpW = (Int32)origWidth * 4096f;
                            tmpH = (Int32)origHeight * 4096f;

                            Single Div = tmpH / tmpW;

                            m[0, 0] = rotCos;
                            m[1, 1] = rotCos;

                            m[1, 0] = -rotSin * Div / 4096f;

                            Div = tmpW / tmpH;

                            m[0, 3] = ((-rotSin - rotCos + 1) * origWidth * 8);
                            m[1, 3] = ((rotSin - rotCos + 1) * origHeight * 8);

                            m[0, 1] = rotSin * Div / 4096f;
                        }
                        else if (!Scale && Rotation && Translation)
                        {
                            Single tmpW, tmpH;

                            tmpW = (Int32)origWidth * 4096f;
                            tmpH = (Int32)origHeight * 4096f;

                            Single Div = tmpH / tmpW;

                            m[0, 0] = rotCos;
                            m[1, 1] = rotCos;

                            m[1, 0] = -rotSin * Div / 4096f;

                            Div = tmpW / tmpH;

                            m[0, 3] = ((-rotSin - rotCos + 1) * origWidth * 8) -
                                     (transS * origWidth * 16);
                            m[1, 3] = ((rotSin - rotCos + 1) * origHeight * 8) +
                                     (transT * origHeight * 16);

                            m[0, 1] = rotSin * Div / 4096f;

                        }
                        else if (Scale && !Rotation && !Translation)
                        {
                            m[0, 0] = scaleS;
                            m[1, 1] = scaleT;

                            m[1, 0] = 0;

                            m[0, 3] = 0;
                            m[1, 3] = ((-2 * scaleT + 1 * 2) * origHeight * 8);

                            m[0, 1] = 0;
                        }
                        else if (Scale && !Rotation && Translation)
                        {
                            m[0, 0] = scaleS;
                            m[1, 1] = scaleT;

                            m[1, 0] = 0;

                            m[0, 3] = -(Single)((Double)scaleS * transS / 255f) * origWidth;
                            m[1, 3] = ((-scaleT - scaleT + 1 * 2) * origHeight * 8) +
                                     (Single)((Double)scaleT * transT / 255f) * origHeight;

                            m[0, 1] = 0;

                        }
                        else if (Scale && Rotation && !Translation)
                        {
                            Single ss_sin, ss_cos;
                            Single st_sin, st_cos;
                            Single tmpW, tmpH;

                            tmpW = (Int32)origWidth * 4096f;
                            tmpH = (Int32)origHeight * 4096f;

                            Single Div = tmpH / tmpW;

                            ss_sin = (Single)((Double)scaleS * rotSin / 4096f);
                            ss_cos = (Single)((Double)scaleS * rotCos / 4096f);
                            st_sin = (Single)((Double)scaleT * rotSin / 4096f);
                            st_cos = (Single)((Double)scaleT * rotCos / 4096f);

                            m[0, 0] = ss_cos;
                            m[1, 1] = st_cos;

                            m[0, 1] = -st_sin * Div / 4096f;

                            Div = tmpW / tmpH;

                            m[0, 3] = ((-ss_sin - ss_cos + scaleS) * origWidth * 8);
                            m[1, 3] = ((st_sin - st_cos - scaleT + 1 * 2) * origHeight * 8);

                            m[0, 1] = ss_sin * Div / 4096f;

                        }
                        else if (Scale && Rotation && Translation)
                        {
                            Single ss_sin, ss_cos;
                            Single st_sin, st_cos;
                            Single tmpW, tmpH;

                            tmpW = (Int32)origWidth * 4096f;
                            tmpH = (Int32)origHeight * 4096f;

                            Single Div = tmpH / tmpW;

                            ss_sin = (Single)((Double)scaleS * rotSin / 4096f);
                            ss_cos = (Single)((Double)scaleS * rotCos / 4096f);
                            st_sin = (Single)((Double)scaleT * rotSin / 4096f);
                            st_cos = (Single)((Double)scaleT * rotCos / 4096f);

                            m[0, 0] = ss_cos;
                            m[1, 1] = st_cos;

                            m[1, 0] = -st_sin * Div / 4096f;

                            Div = tmpW / tmpH;

                            m[0, 3] = ((-ss_sin - ss_cos + scaleS) * origWidth * 8) -
                                     (Single)((Double)scaleS * transS / 255f) * origWidth;
                            m[1, 3] = ((st_sin - st_cos - scaleT + 1 * 2) * origHeight * 8) +
                                     (Single)((Double)scaleT * transT / 255f) * origHeight;

                            m[0, 1] = ss_sin * Div / 4096f;

                        }*/

                        //Single Ss, St;
                        //Single Ts, Tt;
                        //Single Sin, Cos;
                        /*MTX44 S = new MTX44();
                        MTX44 R = new MTX44();
                        MTX44 T = new MTX44();
                        if ((flag & NNS_G3D_MATFLAG_TEXMTX_SCALEONE) == 0)
                        {
                            //Ss = scaleS / (float)origWidth;
                            //St = scaleT / (float)origHeight;
                            S.Scale(scaleS / (float)origWidth, scaleT / (float)origHeight, 1f);
                        }
                        else
                        {
                            //Ss = 1 / (float)origWidth;// / (float)origWidth;
                            //St = 1 / (float)origHeight;// / (float)origHeight;
                            S.Scale(1f / (float)origWidth, 1f / (float)origHeight, 1f);
                        }

                        if ((flag & NNS_G3D_MATFLAG_TEXMTX_ROTZERO) == 0)
                        {
                            //Sin = rotSin;
                            //Cos = rotCos;
                            R[0, 0] = rotCos;
                            R[1, 0] = -rotSin;
                            R[0, 1] = rotSin;
                            R[1, 1] = -rotCos;
                        }
                        else
                        {
                            //Sin = 0;
                            //Cos = 1;
                            //R = Matrix4.Identity;
                        }

                        if ((flag & NNS_G3D_MATFLAG_TEXMTX_TRANSZERO) == 0)
                        {
                            //Ts = transS;
                            //Tt = transT;
                            T.translate(transS, transT, 0);
                        }
                        else
                        {
                            //Ts = 0;
                            //Tt = 0;
                        }
                        MTX44 m = new MTX44();

                        /*Single ss_sin, ss_cos;
                        Single st_sin, st_cos;
                        Single tmpW, tmpH;

                        tmpW = (Single)origWidth * 4096f;
                        tmpH = (Single)origHeight * 4096f;

                        Single div = tmpH / tmpW;

                        ss_sin = (Single)((Double)Ss * Sin / 4096f);
                        ss_cos = (Single)((Double)Ss * Cos / 4096f);
                        st_sin = (Single)((Double)St * Sin / 4096f);
                        st_cos = (Single)((Double)St * Cos / 4096f);

                        m[0, 0] = ss_cos;// / (float)origWidth;
                        m[1, 1] = st_cos;// / (float)origHeight;
                        m[1, 0] = -st_sin * div / 4096f;
                        div = tmpW / tmpH;

                        m[0,3] = ((-ss_sin - ss_cos + Ss) * origWidth * 8) -
                                 (Int32)((Int64)Ss * Ts / 255f) * origWidth;
                        //m[0, 3] /= 4096f;
                        m[1,3] = ((st_sin - st_cos - St + 1 * 2) * origHeight * 8) +
                                 (Int32)((Int64)St * Tt / 255f) * origHeight;
                        //m[1, 3] /= 4096f;
                        m[0,1] = ss_sin * div / 4096f;
                        Single ss_sin, ss_cos;
                        Single st_sin, st_cos;
                        Single tmpW, tmpH;

                        int FX32_SHIFT = 12;

                        tmpW = (Int32)origWidth * 4096f;
                        tmpH = (Int32)origHeight * 4096f;

                        Single Div = tmpH / tmpW;
                        //FX_DivAsync(tmpH, tmpW);

                        ss_sin = (Single)((Double)Ss * Sin / 4096f);
                        ss_cos = (Single)((Double)Ss * Cos / 4096f);
                        st_sin = (Single)((Double)St * Sin / 4096f);
                        st_cos = (Single)((Double)St * Cos / 4096f);

                        m[0, 0] = ss_cos;
                        m[1, 1] = st_cos;

                        m[1, 0] = -st_sin * Div / 4096f;
                        Div = tmpW / tmpH;
                        //FX_DivAsync(tmpW, tmpH);

                        m[0,3] = ((-ss_sin - ss_cos + Ss) * origWidth * 8) -
                                 (Single)((Double)Ss * Ts / 255f) * origWidth;
                        m[0, 3] /= 4096f;
                        m[1,3] = ((st_sin - st_cos - St + 1 * 2) * origHeight * 8) +
                                 (Single)((Double)St * Tt / 255f) * origHeight;
                        m[1, 3] /= 4096f;

                        m[0, 1] = ss_sin * Div / 4096f;/

                        m = m.MultMatrix(T);
                        m = m.MultMatrix(R);
                        m = m.MultMatrix(S);*/
                        //m[2, 2] = 1;
                        //m[3, 3] = 1;
                        //	m.Scale(1f / origWidth, 1f / origHeight, 1);
                        //m[0, 0] /= origWidth;
                        //m[1, 1] /= origWidth;
                        //m[0, 3] /= origWidth;
                        //m[1, 3] /= origHeight;
                        if (Translation)
                        {
                            m[3, 0] = transS;
                            m[3, 1] = transT;
                        }
                        float Sx = (Scale ? scaleS : 1);
                        float Sy = (Scale ? scaleT : 1);
                        if (Rotation)
                        {
                            m[0, 0] = rotCos * Sx;
                            m[0, 1] = -rotSin;
                            m[1, 0] = rotSin;
                            m[1, 1] = -rotCos * Sy;
                        }
                        else
                        {
                            m[0, 0] = Sx;
                            m[1, 1] = Sy;
                        }
                        m[2, 2] = 1;
                        m[3, 3] = 1;
                        return (float[])m;
                    }
Exemplo n.º 11
0
 public static Matrix34 operator *(Matrix34 Left, Matrix34 Right)
 {
     Matrix44 l = new Matrix44(Left, new Vector4(0, 0, 0, 1));
     Matrix44 r = new Matrix44(Right, new Vector4(0, 0, 0, 1));
     Matrix44 Result = l * r;
     Matrix34 result2 = new Matrix34();
     for (int i = 0; i < 12; i++)
     {
         result2[i] = Result[i];
     }
     return result2;
 }