Beispiel #1
0
        public void Multiply(Matrix34 *m)
        {
            Matrix34 m2 = this;

            float *s1 = (float *)&m2, s2 = (float *)m;

            fixed(float *p = _data)
            {
                int   index = 0;
                float val;

                for (int b = 0; b < 12; b += 4)
                {
                    for (int a = 0; a < 4; a++)
                    {
                        val = 0.0f;
                        for (int x = b, y = a; y < 12; y += 4)
                        {
                            val += s1[x++] * s2[y];
                        }

                        p[index++] = val;
                    }
                }

                p[3]  += s1[3];
                p[7]  += s1[7];
                p[11] += s1[11];
            }
        }
Beispiel #2
0
        public static Matrix34 ScaleMatrix(float x, float y, float z)
        {
            Matrix34 m = new Matrix34();
            float *  p = (float *)&m;

            p[0]  = x;
            p[5]  = y;
            p[10] = z;
            return(m);
        }
Beispiel #3
0
        public static Matrix34 TranslationMatrix(float x, float y, float z)
        {
            Matrix34 m = new Matrix34();
            float *  p = (float *)&m;

            p[3]  = x;
            p[7]  = y;
            p[11] = z;
            p[0]  = p[5] = p[10] = 1.0f;
            return(m);
        }
Beispiel #4
0
        public static Matrix34 EnvironmentTexMtx()
        {
            Matrix34 m = Identity;

            m[0]  = 0.5f;
            m[3]  = 0.5f;
            m[5]  = -0.5f;
            m[7]  = 0.5f;
            m[10] = 0.0f;
            m[11] = 1.0f;
            return(m);
        }
Beispiel #5
0
        public Matrix34 GetTranslation()
        {
            Matrix34 m = Identity;
            float *  p = (float *)&m;

            fixed(float *s = _data)
            {
                p[3]  = s[3];
                p[7]  = s[7];
                p[11] = s[11];
            }

            return(m);
        }
Beispiel #6
0
        public static Matrix34 RotationMatrix(float x, float y, float z)
        {
            float cosx = (float)Math.Cos(x / 180.0f * Math.PI);
            float sinx = (float)Math.Sin(x / 180.0f * Math.PI);
            float cosy = (float)Math.Cos(y / 180.0f * Math.PI);
            float siny = (float)Math.Sin(y / 180.0f * Math.PI);
            float cosz = (float)Math.Cos(z / 180.0f * Math.PI);
            float sinz = (float)Math.Sin(z / 180.0f * Math.PI);

            Matrix34 m = Identity;
            float *  p = (float *)&m;

            p[5]  = cosx;
            p[6]  = -sinx;
            p[9]  = sinx;
            p[10] = cosx;

            Matrix34 m2 = Identity;
            float *  p2 = (float *)&m2;

            p2[0]  = cosy;
            p2[2]  = siny;
            p2[8]  = -siny;
            p2[10] = cosy;

            Matrix34 m3 = Identity;
            float *  p3 = (float *)&m3;

            p3[0] = cosz;
            p3[1] = -sinz;
            p3[4] = sinz;
            p3[5] = cosz;

            m.Multiply(&m2);
            m.Multiply(&m3);

            //p[0] = cosy * cosz;
            //p[1] = cosy * sinz;
            //p[2] = -siny;
            //p[4] = (sinx * siny * cosz - cosx * sinz);
            //p[5] = (sinx * siny * sinz + cosx * cosz);
            //p[6] = sinx * cosy;
            //p[8] = (cosx * siny * cosz + sinx * sinz);
            //p[9] = (cosx * siny * sinz - sinx * cosz);
            //p[10] = cosx * cosy;

            return(m);
        }
Beispiel #7
0
        public static Matrix34 RotationMatrixRX(float x)
        {
            Matrix34 m = new Matrix34();
            float *  p = (float *)&m;

            float cosx = (float)Math.Cos(x / 180.0f * Math.PI);
            float sinx = (float)Math.Sin(x / 180.0f * Math.PI);

            p[0]  = 1.0f;
            p[5]  = cosx;
            p[6]  = sinx;
            p[9]  = -sinx;
            p[10] = cosx;

            return(m);
        }
Beispiel #8
0
        public static Matrix34 RotationMatrixRY(float y)
        {
            Matrix34 m = new Matrix34();
            float *  p = (float *)&m;

            float cosy = (float)Math.Cos(y / 180.0f * Math.PI);
            float siny = (float)Math.Sin(y / 180.0f * Math.PI);

            p[5] = 1.0f;

            p[0]  = cosy;
            p[2]  = -siny;
            p[8]  = siny;
            p[10] = cosy;

            return(m);
        }
Beispiel #9
0
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            Matrix34 m = new Matrix34();

            string s = value?.ToString() ?? "";

            string[] arr = s.Split(LanguageCheck.DecimalDelimiters, StringSplitOptions.RemoveEmptyEntries);

            if (arr.Length == 12)
            {
                float.TryParse(arr[0], out m._data[0]);
                float.TryParse(arr[1], out m._data[1]);
                float.TryParse(arr[2], out m._data[2]);
                float.TryParse(arr[3], out m._data[3]);
                float.TryParse(arr[4], out m._data[4]);
                float.TryParse(arr[5], out m._data[5]);
                float.TryParse(arr[6], out m._data[6]);
                float.TryParse(arr[7], out m._data[7]);
                float.TryParse(arr[8], out m._data[8]);
                float.TryParse(arr[9], out m._data[9]);
                float.TryParse(arr[10], out m._data[10]);
                float.TryParse(arr[11], out m._data[11]);
            }
            else if (arr.Length == 1 && float.TryParse(arr[0], out float f))
            {
                m._data[0]  = f;
                m._data[1]  = f;
                m._data[2]  = f;
                m._data[3]  = f;
                m._data[4]  = f;
                m._data[5]  = f;
                m._data[6]  = f;
                m._data[7]  = f;
                m._data[8]  = f;
                m._data[9]  = f;
                m._data[10] = f;
                m._data[11] = f;
            }

            return(m);
        }
Beispiel #10
0
        internal void Scale(float x, float y, float z)
        {
            Matrix34 m = ScaleMatrix(x, y, z);

            Multiply(&m);
        }
Beispiel #11
0
        internal void Rotate(float x, float y, float z)
        {
            Matrix34 m = RotationMatrix(x, y, z);

            Multiply(&m);
        }
Beispiel #12
0
        public void Translate(float x, float y, float z)
        {
            Matrix34 m = TranslationMatrix(x, y, z);

            Multiply(&m);
        }