Example #1
0
        private LVector3 MatrixToEuler(LMatrix33 m)
        {
            LVector3 v = new LVector3();

            if (m[1, 2] < 1)
            {
                if (m[1, 2] > -1)
                {
                    v.x = LMath.Asin(-m[1, 2]);
                    v.y = LMath.Atan2(m[0, 2], m[2, 2]);
                    v.z = LMath.Atan2(m[1, 0], m[1, 1]);
                }
                else
                {
                    v.x = LMath.PI * LFloat.half;
                    v.y = LMath.Atan2(m[0, 1], m[0, 0]);
                    v.z = (LFloat)0;
                }
            }
            else
            {
                v.x = -LMath.PI * LFloat.half;
                v.y = LMath.Atan2(-m[0, 1], m[0, 0]);
                v.z = (LFloat)0;
            }

            for (int i = 0; i < 3; i++)
            {
                if (v[i] < 0)
                {
                    v[i] += LMath.PI2;
                }
                else if (v[i] > LMath.PI2)
                {
                    v[i] -= LMath.PI2;
                }
            }

            return(v);
        }