示例#1
0
        public void RotateRelative(double x, double y, double z)
        {
#if true
            if (x != 0)
            {
                Matrix4X4 M1 = Matrix4X4.Identity;
                M1 = Matrix4X4.CreateRotationX(x);
                if (y != 0)
                {
                    Matrix4X4 M2 = Matrix4X4.Identity;
                    Matrix4X4 M4 = Matrix4X4.Identity;
                    M2 = Matrix4X4.CreateRotationY(y);
                    M4 = M2 * M1;
                    if (z != 0)
                    {
                        Matrix4X4 M3 = Matrix4X4.Identity;
                        M3 = Matrix4X4.CreateRotationZ(z);
                        Matrix4X4 Delta = Matrix4X4.Identity;
                        Delta        = M3 * M4;
                        AxisToWorld *= Delta;
                    }
                    else
                    {
                        AxisToWorld *= M4;
                    }
                }
                else
                {
                    if (z != 0)
                    {
                        Matrix4X4 M3 = Matrix4X4.Identity;
                        M3 = Matrix4X4.CreateRotationZ(z);
                        Matrix4X4 Delta = Matrix4X4.Identity;
                        Delta        = M3 * M1;
                        AxisToWorld *= Delta;
                    }
                    else
                    {
                        AxisToWorld *= M1;
                    }
                }
            }
            else
            {
                if (y != 0)
                {
                    Matrix4X4 M2 = Matrix4X4.Identity;
                    M2 = Matrix4X4.CreateRotationY(y);
                    if (z != 0)
                    {
                        Matrix4X4 M3 = Matrix4X4.Identity;
                        M3 = Matrix4X4.CreateRotationZ(z);
                        Matrix4X4 Delta = Matrix4X4.Identity;
                        Delta        = M3 * M2;
                        AxisToWorld *= Delta;
                    }
                    else
                    {
                        AxisToWorld *= M2;
                    }
                }
                else
                {
                    if (z != 0)
                    {
                        Matrix4X4 M3 = Matrix4X4.Identity;
                        M3           = Matrix4X4.CreateRotationZ(z);
                        AxisToWorld *= M3;
                    }
                }
            }

            WorldToAxis = Matrix4X4.Invert(AxisToWorld);
#else
            M1.Rotate(0, x);
            M2.Rotate(1, y);
            M3.Rotate(2, z);
            // 1 * 2 * 3
            M4    = M2 * M1;
            Delta = M3 * M4;

            AxisToWorld = AxisToWorld * Delta;

            WorldToAxis = AxisToWorld.GetInverse();
#endif
        }