Пример #1
0
        public Rotator ToRotator()
        {
            // http://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles
            Rotator result = new Rotator();

            // Roll (rotation around x-axis)
            float sinr = 2.0f * (W * X + Y * Z);
            float cosr = 1.0f - 2.0f * (X * X + Y * Y);

            result.Z = RyneMath.Atan2(sinr, cosr);

            // Pitch (rotation around y-axis)
            float sinp = 2.0f * (W * Y - Z * X);

            if (RyneMath.Abs(sinp) >= 1)
            {
                result.Y = Constants.PI / 2.0f * RyneMath.Sign(sinp); // use 90 degrees if out of range
            }
            else
            {
                result.Y = RyneMath.Asin(sinp);
            }

            // Yaw (rotation around z-axis)
            float siny = 2.0f * (W * Z + X * Y);
            float cosy = 1.0f - 2.0f * (Y * Y + Z * Z);

            result.X = RyneMath.Atan2(siny, cosy);

            result.X = RyneMath.RadiansToDegrees(result.X);
            result.Y = RyneMath.RadiansToDegrees(result.Y);
            result.Z = RyneMath.RadiansToDegrees(result.Z);
            return(result);
        }
Пример #2
0
 public float RotationAngle(bool degrees = true)
 {
     return(RyneMath.RadiansToDegrees(2.0f * RyneMath.Acos(W)));
 }