예제 #1
0
        /// <summary>
        /// Clamps a value between two other values.
        /// </summary>
        /// <param name="value">Value to clamp.</param>
        /// <param name="min">Minimum value of the range to clamp. Must be lower than <paramref name="max"/></param>
        /// <param name="max">Maximum value of the range to clamp. Must be higher than <paramref name="min"/></param>
        /// <returns>Returns unchanged value if it is in valid range, otherwise returns value clamped to the range
        /// extremes. </returns>
        public static Radian Clamp(Radian value, Radian min, Radian max)
        {
            if (value < min)
            {
                value = min;
            }
            else if (value > max)
            {
                value = max;
            }

            return(value);
        }
예제 #2
0
        /// <inheritdoc/>
        public override bool Equals(object other)
        {
            if (!(other is Radian))
            {
                return(false);
            }

            Radian radian = (Radian)other;

            if (value.Equals(radian.value))
            {
                return(true);
            }

            return(false);
        }
예제 #3
0
 /// <summary>
 /// Constructs a soft limit. Once the limit is reached the bodies will bounce back according to the resitution
 /// parameter and will be pulled back towards the limit by the provided spring.
 /// </summary>
 /// <param name="lower"><see cref="Lower"/></param>
 /// <param name="upper"><see cref="Upper"/></param>
 /// <param name="spring"><see cref="LimitCommon.Spring"/></param>
 /// <param name="restitution"><see cref="LimitCommon.Restitution"/></param>
 public LimitAngularRange(Radian lower, Radian upper, Spring spring, float restitution = 0.0f)
     : base(spring, restitution)
 {
     data.lower = lower;
     data.upper = upper;
 }
예제 #4
0
 private static extern void Internal_getHorzFOV(IntPtr thisPtr, out Radian __output);
예제 #5
0
        /// <summary>
        /// Converts an orthonormal matrix to axis angle representation.
        /// </summary>
        /// <param name="axis">Axis around which the rotation is performed.</param>
        /// <param name="angle">Amount of rotation.</param>
        public void ToAxisAngle(out Vector3 axis, out Degree angle)
        {
            float  trace   = m00 + m11 + m22;
            float  cos     = 0.5f * (trace - 1.0f);
            Radian radians = (Radian)MathEx.Acos(cos);  // In [0, PI]

            angle = radians;

            if (radians > (Radian)0.0f)
            {
                if (radians < MathEx.Pi)
                {
                    axis.x = m21 - m12;
                    axis.y = m02 - m20;
                    axis.z = m10 - m01;

                    axis.Normalize();
                }
                else
                {
                    // Angle is PI
                    float halfInverse;
                    if (m00 >= m11)
                    {
                        // r00 >= r11
                        if (m00 >= m22)
                        {
                            // r00 is maximum diagonal term
                            axis.x      = 0.5f * MathEx.Sqrt(m00 - m11 - m22 + 1.0f);
                            halfInverse = 0.5f / axis.x;
                            axis.y      = halfInverse * m01;
                            axis.z      = halfInverse * m02;
                        }
                        else
                        {
                            // r22 is maximum diagonal term
                            axis.z      = 0.5f * MathEx.Sqrt(m22 - m00 - m11 + 1.0f);
                            halfInverse = 0.5f / axis.z;
                            axis.x      = halfInverse * m02;
                            axis.y      = halfInverse * m12;
                        }
                    }
                    else
                    {
                        // r11 > r00
                        if (m11 >= m22)
                        {
                            // r11 is maximum diagonal term
                            axis.y      = 0.5f * MathEx.Sqrt(m11 - m00 - m22 + 1.0f);
                            halfInverse = 0.5f / axis.y;
                            axis.x      = halfInverse * m01;
                            axis.z      = halfInverse * m12;
                        }
                        else
                        {
                            // r22 is maximum diagonal term
                            axis.z      = 0.5f * MathEx.Sqrt(m22 - m00 - m11 + 1.0f);
                            halfInverse = 0.5f / axis.z;
                            axis.x      = halfInverse * m02;
                            axis.y      = halfInverse * m12;
                        }
                    }
                }
            }
            else
            {
                // The angle is 0 and the matrix is the identity.  Any axis will
                // work, so just use the x-axis.
                axis.x = 1.0f;
                axis.y = 0.0f;
                axis.z = 0.0f;
            }
        }
예제 #6
0
        /// <summary>
        /// Rotates around local X axis.
        /// </summary>
        /// <param name="angle">Angle to rotate by.</param>
        public void Pitch(Degree angle)
        {
            Radian radianAngle = angle;

            Internal_Pitch(mCachedPtr, ref radianAngle);
        }
예제 #7
0
        /// <summary>
        /// Rotates around local Z axis.
        /// </summary>
        /// <param name="angle">Angle to rotate by.</param>
        public void Roll(Degree angle)
        {
            Radian radianAngle = angle;

            Internal_Roll(mCachedPtr, ref radianAngle);
        }
예제 #8
0
 /// <summary>
 /// Creates a new degree value.
 /// </summary>
 /// <param name="r">Value in radians.</param>
 public Degree(Radian r)
 {
     this.value = r.Degrees;
 }
 private static extern void Internal_getSlopeLimit(IntPtr thisPtr, out Radian __output);
예제 #10
0
 /// <summary>
 /// Constructs a hard limit. Once the limit is reached the movement of the attached bodies will come to a stop.
 /// </summary>
 /// <param name="yLimitAngle"><see cref="YLimitAngle"/></param>
 /// <param name="zLimitAngle"><see cref="ZLimitAngle"/></param>
 /// <param name="contactDist"><see cref="LimitCommon.ContactDist"/></param>
 public LimitConeRange(Radian yLimitAngle, Radian zLimitAngle, float contactDist = -1.0f)
     : base(contactDist)
 {
     data.yLimitAngle = yLimitAngle;
     data.zLimitAngle = zLimitAngle;
 }
예제 #11
0
 /// <summary>
 /// Constructs a soft limit. Once the limit is reached the bodies will bounce back according to the resitution
 /// parameter and will be pulled back towards the limit by the provided spring.
 /// </summary>
 /// <param name="lower"><see cref="Lower"/></param>
 /// <param name="upper"><see cref="Upper"/></param>
 /// <param name="spring"><see cref="LimitCommon.Spring"/></param>
 /// <param name="restitution"><see cref="LimitCommon.Restitution"/></param>
 public LimitAngularRange(Radian lower, Radian upper, Spring spring, float restitution = 0.0f)
     : base(spring, restitution)
 {
     data.lower = lower;
     data.upper = upper;
 }
예제 #12
0
 /// <summary>
 /// Constructs a hard limit. Once the limit is reached the movement of the attached bodies will come to a stop.
 /// </summary>
 /// <param name="lower"><see cref="Lower"/></param>
 /// <param name="upper"><see cref="Upper"/></param>
 /// <param name="contactDist"><see cref="LimitCommon.ContactDist"/></param>
 public LimitAngularRange(Radian lower, Radian upper, float contactDist = -1.0f)
     : base(contactDist)
 {
     data.lower = lower;
     data.upper = upper;
 }
예제 #13
0
 /// <summary>
 /// Constructs a soft limit. Once the limit is reached the bodies will bounce back according to the resitution
 /// parameter and will be pulled back towards the limit by the provided spring.
 /// </summary>
 /// <param name="yLimitAngle"><see cref="YLimitAngle"/></param>
 /// <param name="zLimitAngle"><see cref="ZLimitAngle"/></param>
 /// <param name="spring"><see cref="LimitCommon.Spring"/></param>
 /// <param name="restitution"><see cref="LimitCommon.Restitution"/></param>
 public LimitConeRange(Radian yLimitAngle, Radian zLimitAngle, Spring spring, float restitution = 0.0f)
     : base(spring, restitution)
 {
     data.yLimitAngle = yLimitAngle;
     data.zLimitAngle = zLimitAngle;
 }
예제 #14
0
 /// <summary>
 /// Constructs a hard limit. Once the limit is reached the movement of the attached bodies will come to a stop.
 /// </summary>
 /// <param name="yLimitAngle"><see cref="YLimitAngle"/></param>
 /// <param name="zLimitAngle"><see cref="ZLimitAngle"/></param>
 /// <param name="contactDist"><see cref="LimitCommon.ContactDist"/></param>
 public LimitConeRange(Radian yLimitAngle, Radian zLimitAngle, float contactDist = -1.0f)
     : base(contactDist)
 {
     data.yLimitAngle = yLimitAngle;
     data.zLimitAngle = zLimitAngle;
 }
예제 #15
0
 /// <summary>
 /// Returns an angle of a point.
 /// </summary>
 /// <param name="y">Y coordinate of the point.</param>
 /// <param name="x">X coordinate of the point.</param>
 /// <returns>Angle in radians in range [Pi, -Pi].</returns>
 public static Radian Atan2(Radian y, Radian x)
 {
     return((Radian)Math.Atan2(y.Radians, x.Radians));
 }
예제 #16
0
 /// <summary>
 /// Constructs a soft limit. Once the limit is reached the bodies will bounce back according to the resitution
 /// parameter and will be pulled back towards the limit by the provided spring.
 /// </summary>
 /// <param name="yLimitAngle"><see cref="YLimitAngle"/></param>
 /// <param name="zLimitAngle"><see cref="ZLimitAngle"/></param>
 /// <param name="spring"><see cref="LimitCommon.Spring"/></param>
 /// <param name="restitution"><see cref="LimitCommon.Restitution"/></param>
 public LimitConeRange(Radian yLimitAngle, Radian zLimitAngle, Spring spring, float restitution = 0.0f)
     : base(spring, restitution)
 {
     data.yLimitAngle = yLimitAngle;
     data.zLimitAngle = zLimitAngle;
 }
예제 #17
0
 /// <summary>
 /// Returns the angle whose sine is the specified number.
 /// </summary>
 /// <param name="f">Sine of an angle.</param>
 /// <returns>Angle in radians.</returns>
 public static float Asin(Radian f)
 {
     return((float)Math.Asin(f.Radians));
 }
 private static extern void Internal_setSlopeLimit(IntPtr thisPtr, ref Radian value);
예제 #19
0
 /// <summary>
 /// Returns an angle of a point.
 /// </summary>
 /// <param name="y">Y coordinate of the point.</param>
 /// <param name="x">X coordinate of the point.</param>
 /// <returns>Angle in radians in range [Pi, -Pi].</returns>
 public static float Atan2(Radian y, Radian x)
 {
     return((float)Math.Atan2(y.Radians, x.Radians));
 }
예제 #20
0
 private static extern void Internal_getAngle(IntPtr thisPtr, out Radian __output);
예제 #21
0
 /// <summary>
 /// Returns the cosine of the provided value.
 /// </summary>
 /// <param name="f">Angle in radians.</param>
 /// <returns>Cosine of the angle.</returns>
 public static float Cos(Radian f)
 {
     return((float)Math.Cos(f.Radians));
 }
예제 #22
0
        /// <summary>
        /// Rotates around local Y axis.
        /// </summary>
        /// <param name="angle">Angle to rotate by.</param>
        public void Yaw(Degree angle)
        {
            Radian radianAngle = angle;

            Internal_Yaw(mCachedPtr, ref radianAngle);
        }
예제 #23
0
 /// <summary>
 /// Returns the tangent of the provided value.
 /// </summary>
 /// <param name="f">Angle in radians.</param>
 /// <returns>Tangent of the angle.</returns>
 public static float Tan(Radian f)
 {
     return((float)Math.Tan(f.Radians));
 }
예제 #24
0
 private static extern void Internal_Pitch(IntPtr nativeInstance, ref Radian value);
예제 #25
0
 /// <summary>
 /// Returns the angle whose cosine is the specified number.
 /// </summary>
 /// <param name="f">Cosine of an angle.</param>
 /// <returns>Angle in radians.</returns>
 public static Radian Acos(Radian f)
 {
     return((Radian)Math.Acos(f.Radians));
 }
예제 #26
0
 private static extern void Internal_setHorzFOV(IntPtr thisPtr, ref Radian fovy);
예제 #27
0
 /// <summary>
 /// Returns the angle whose tangent is the specified number.
 /// </summary>
 /// <param name="f">Tangent of an angle.</param>
 /// <returns>Angle in radians.</returns>
 public static Radian Atan(Radian f)
 {
     return((Radian)Math.Atan(f.Radians));
 }
예제 #28
0
파일: Degree.cs 프로젝트: Ruu/BansheeEngine
 /// <summary>
 /// Creates a new degree value.
 /// </summary>
 /// <param name="r">Value in radians.</param>
 public Degree(Radian r)
 {
     this.value = r.Degrees;
 }
예제 #29
0
 /// <summary>
 /// Constructs a hard limit. Once the limit is reached the movement of the attached bodies will come to a stop.
 /// </summary>
 /// <param name="lower"><see cref="Lower"/></param>
 /// <param name="upper"><see cref="Upper"/></param>
 /// <param name="contactDist"><see cref="LimitCommon.ContactDist"/></param>
 public LimitAngularRange(Radian lower, Radian upper, float contactDist = -1.0f)
     : base(contactDist)
 {
     data.lower = lower;
     data.upper = upper;
 }