Exemple #1
0
        public Quaternion MakeQuaternion(float x, float y, float z, Quaternion.RotationOrder order)
        {
            Quaternion q;

            switch (order)
            {
            case Quaternion.RotationOrder.OrderXYZ:
                q = Quaternion.FromAxisAngle(Vector3.UnitZ, Maths.DegreesToRadians(z)) *
                    Quaternion.FromAxisAngle(Vector3.UnitY, Maths.DegreesToRadians(y)) *
                    Quaternion.FromAxisAngle(Vector3.UnitX, Maths.DegreesToRadians(x));
                break;

            default:
                throw new NotImplementedException($"Unhandled RotationOrder: {order}");
            }

            return(q);
        }
Exemple #2
0
        private Matrix4D createTransformFor(FBXElem globalSettings, out Quaternion.RotationOrder order)
        {
            order = Quaternion.RotationOrder.OrderXYZ;

            int frontAxis     = (int)globalSettings.Children.GetProperty("FrontAxis").Properties[4].Value;
            int frontAxisSign = (int)globalSettings.Children.GetProperty("FrontAxisSign").Properties[4].Value;
            int upAxis        = (int)globalSettings.Children.GetProperty("UpAxis").Properties[4].Value;
            int upAxisSign    = (int)globalSettings.Children.GetProperty("UpAxisSign").Properties[4].Value;
            int coordAxis     = (int)globalSettings.Children.GetProperty("CoordAxis").Properties[4].Value;
            int coordAxisSign = (int)globalSettings.Children.GetProperty("CoordAxisSign").Properties[4].Value;

            int front = (frontAxis * 2) + Math.Max(frontAxisSign, 0);
            int up    = (upAxis * 2) + Math.Max(upAxisSign, 0) << 3;
            int coord = (coordAxis * 2) + Math.Max(coordAxisSign, 0) << 6;

            CoordinateSystem coords = (CoordinateSystem)(front + up + coord);

            switch (coords)
            {
            // Blender 2.71 tells us that -Y is forward but the UI suggest +Y is forward.
            case CoordinateSystem.nYpZpX:
                order = Quaternion.RotationOrder.OrderXYZ;
                return(Matrix4D.CreateRotationX(Maths.DegreesToRadians(-90)));

            case CoordinateSystem.pZpYpX:
                order = Quaternion.RotationOrder.OrderXYZ;
                return(Matrix4D.Identity);

            case CoordinateSystem.nZpYnX:
                order = Quaternion.RotationOrder.OrderXYZ;
                return(Matrix4D.Identity);

            default:
                throw new NotImplementedException($"Unsupported World Transformation Matrix: {coords}");
            }
        }