/// <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); }
/// <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); }
/// <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; }
private static extern void Internal_getHorzFOV(IntPtr thisPtr, out Radian __output);
/// <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; } }
/// <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); }
/// <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); }
/// <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);
/// <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; }
/// <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; }
/// <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; }
/// <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)); }
/// <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);
/// <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)); }
private static extern void Internal_getAngle(IntPtr thisPtr, out Radian __output);
/// <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)); }
/// <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); }
/// <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)); }
private static extern void Internal_Pitch(IntPtr nativeInstance, ref Radian value);
/// <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)); }
private static extern void Internal_setHorzFOV(IntPtr thisPtr, ref Radian fovy);
/// <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)); }