Exemplo n.º 1
0
 public void Clamp(Angles min, Angles max)
 {
     if (roll < min.roll)
     {
         roll = min.roll;
     }
     else if (roll > max.roll)
     {
         roll = max.roll;
     }
     if (pitch < min.pitch)
     {
         pitch = min.pitch;
     }
     else if (pitch > max.pitch)
     {
         pitch = max.pitch;
     }
     if (yaw < min.yaw)
     {
         yaw = min.yaw;
     }
     else if (yaw > max.yaw)
     {
         yaw = max.yaw;
     }
 }
Exemplo n.º 2
0
        public override unsafe object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            if ((destinationType != typeof(string)) || (value.GetType() != typeof(Quat)))
            {
                return(base.ConvertTo(context, culture, value, destinationType));
            }
            Angles angles = ((Quat)value).ToAngles();

            for (int i = 0; i < 3; i++)
            {
                float num2 = (float)System.Math.Round(angles[i]);
                if ((num2 != angles[i]) && (System.Math.Abs(num2 - angles[i]) < 0.0001f))
                {
                    angles[i] = num2;
                }
            }
            angles.Normalize360();
            if ((angles[1] >= 180f) && (angles[2] >= 180f))
            {
                angles[0] = 180f - angles[0];
                angles[1] = angles[1] - 180f;
                angles[2] = angles[2] - 180f;
            }
            angles.Normalize360();
            return(angles.ToString());
        }
Exemplo n.º 3
0
        public void ToAngles(out Angles result)
        {
            float ry = Ru.x;

            if (ry > 1f)
            {
                ry = 1f;
            }
            else if (ry < -1f)
            {
                ry = -1f;
            }
            double d = -System.Math.Asin(ry);

            if (System.Math.Cos(d) > 0.0009765625)
            {
                result.roll  = MathFunctions.RadToDeg((float)System.Math.Atan2(Ru.y, Ru.z));
                result.pitch = MathFunctions.RadToDeg((float)d);
                result.yaw   = MathFunctions.RadToDeg((float)System.Math.Atan2(RU.x, Rt.x));
            }
            else
            {
                result.roll  = 0f;
                result.pitch = MathFunctions.RadToDeg((float)d);
                result.yaw   = MathFunctions.RadToDeg((float)-System.Math.Atan2(Rt.y, RU.y));
            }
        }
Exemplo n.º 4
0
 public bool Equals(Angles a, float epsilon)
 {
     if (System.Math.Abs(roll - a.roll) > epsilon)
     {
         return(false);
     }
     if (System.Math.Abs(pitch - a.pitch) > epsilon)
     {
         return(false);
     }
     if (System.Math.Abs(yaw - a.yaw) > epsilon)
     {
         return(false);
     }
     return(true);
 }
Exemplo n.º 5
0
 public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
 {
     if (value.GetType() == typeof(string))
     {
         try
         {
             Angles angles = Angles.Parse((string)value);
             angles.Normalize360();
             return(angles.ToQuat());
         }
         catch (Exception)
         {
             return(value);
         }
     }
     return(base.ConvertFrom(context, culture, value));
 }
Exemplo n.º 6
0
        public static Angles Parse(string text)
        {
            Angles angles;

            if (string.IsNullOrEmpty(text))
            {
                throw new ArgumentNullException("The text parameter cannot be null or zero length.");
            }
            string[] strArray = text.Split(SpaceCharacter.arrayWithOneSpaceCharacter, StringSplitOptions.RemoveEmptyEntries);
            if (strArray.Length != 3)
            {
                throw new FormatException(string.Format("Cannot parse the text '{0}' because it does not have 4 parts separated by spaces in the form (pitch yaw roll).", text));
            }
            try
            {
                angles = new Angles(float.Parse(strArray[0]), float.Parse(strArray[1]), float.Parse(strArray[2]));
            }
            catch (Exception)
            {
                throw new FormatException("The parts of the angles must be decimal numbers.");
            }
            return(angles);
        }
Exemplo n.º 7
0
 public void ToAngles(out Angles result)
 {
     ToMat3(out Mat3 mat);
     mat.ToAngles(out result);
 }
Exemplo n.º 8
0
 static Angles()
 {
     Zero = new Angles(0f, 0f, 0f);
 }
Exemplo n.º 9
0
 public Angles(Angles source)
 {
     roll  = source.roll;
     pitch = source.pitch;
     yaw   = source.yaw;
 }