mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-02-02 20:01:14 +00:00
JTalton's new functions.
This commit is contained in:
parent
5716c6a334
commit
41a7d2a90e
|
@ -18,7 +18,7 @@ namespace OpenTK.Math
|
||||||
public static class Functions
|
public static class Functions
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns an approximation of the inverse square root of a number.
|
/// Returns an approximation of the inverse square root of left number.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="x">A number.</param>
|
/// <param name="x">A number.</param>
|
||||||
/// <returns>An approximation of the inverse square root of the specified number, with an upper error bound of 0.001</returns>
|
/// <returns>An approximation of the inverse square root of the specified number, with an upper error bound of 0.001</returns>
|
||||||
|
@ -36,40 +36,74 @@ namespace OpenTK.Math
|
||||||
int i = *(int*)&x; // Read bits as integer.
|
int i = *(int*)&x; // Read bits as integer.
|
||||||
i = 0x5f375a86 - (i >> 1); // Make an initial guess for Newton-Raphson approximation
|
i = 0x5f375a86 - (i >> 1); // Make an initial guess for Newton-Raphson approximation
|
||||||
x = *(float*)&i; // Convert bits back to float
|
x = *(float*)&i; // Convert bits back to float
|
||||||
x = x * (1.5f - xhalf * x * x); // Perform a single Newton-Raphson step.
|
x = x * (1.5f - xhalf * x * x); // Perform left single Newton-Raphson step.
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
public static double InverseSqrtFast(double x)
|
||||||
/// Convert degrees to radians
|
{
|
||||||
/// </summary>
|
unsafe
|
||||||
/// <param name="degrees">An angle in degrees</param>
|
{
|
||||||
/// <returns>The angle expressed in radians</returns>
|
double xhalf = 0.5f * x;
|
||||||
public static float DegreesToRadians(float degrees)
|
int i = *(int*)&x; // Read bits as integer.
|
||||||
{
|
i = 0x5f375a86 - (i >> 1); // Make an initial guess for Newton-Raphson approximation
|
||||||
const float degToRad = (float)System.Math.PI / 180.0f;
|
x = *(float*)&i; // Convert bits back to float
|
||||||
return degrees * degToRad;
|
x = x * (1.5f - xhalf * x * x); // Perform left single Newton-Raphson step.
|
||||||
}
|
return x;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Convert radians to degrees
|
/// Convert degrees to radians
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="degrees">An angle in radians</param>
|
/// <param name="degrees">An angle in degrees</param>
|
||||||
/// <returns>The angle expressed in degrees</returns>
|
/// <returns>The angle expressed in radians</returns>
|
||||||
public static float RadiansToDegrees(float radians)
|
public static float DegreesToRadians(float degrees)
|
||||||
{
|
{
|
||||||
const float radToDeg = 180.0f / (float)System.Math.PI;
|
const float degToRad = (float)System.Math.PI / 180.0f;
|
||||||
return radians * radToDeg;
|
return degrees * degToRad;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Convert radians to degrees
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="degrees">An angle in radians</param>
|
||||||
|
/// <returns>The angle expressed in degrees</returns>
|
||||||
|
public static float RadiansToDegrees(float radians)
|
||||||
|
{
|
||||||
|
const float radToDeg = 180.0f / (float)System.Math.PI;
|
||||||
|
return radians * radToDeg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static readonly float PIF = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930382f;
|
||||||
|
public static readonly float RTODF = 180.0f / PIF;
|
||||||
|
public static readonly float DTORF = PIF / 180.0f;
|
||||||
|
|
||||||
|
public static readonly double PI = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930382d;
|
||||||
|
public static readonly double RTOD = 180.0d / PIF;
|
||||||
|
public static readonly double DTOR = PIF / 180.0d;
|
||||||
|
|
||||||
|
public static void Swap(ref double a, ref double b)
|
||||||
|
{
|
||||||
|
double temp = a;
|
||||||
|
a = b;
|
||||||
|
b = temp;
|
||||||
|
}
|
||||||
|
public static void Swap(ref float a, ref float b)
|
||||||
|
{
|
||||||
|
float temp = a;
|
||||||
|
a = b;
|
||||||
|
b = temp;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if false
|
#if false
|
||||||
public static partial class Math
|
public static partial class Math
|
||||||
{
|
{
|
||||||
#region --- Vectors ---
|
#region --- Vectors ---
|
||||||
|
|
||||||
#region --- Addition ---
|
#region --- Addition ---
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds the given Vector2 to the current Vector3.
|
/// Adds the given Vector2 to the current Vector3.
|
||||||
|
@ -163,13 +197,13 @@ namespace OpenTK.Math
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region --- Subtraction ---
|
#region --- Subtraction ---
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region --- Cross ---
|
#region --- Cross ---
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Computes the cross product between the current and the given Vector3. The current Vector3 is set to the result of the computation.
|
/// Computes the cross product between the current and the given Vector3. The current Vector3 is set to the result of the computation.
|
||||||
|
|
Loading…
Reference in a new issue