diff --git a/Source/OpenTK/Math/MathHelper.cs b/Source/OpenTK/Math/MathHelper.cs index 76bccdd1..7837f572 100644 --- a/Source/OpenTK/Math/MathHelper.cs +++ b/Source/OpenTK/Math/MathHelper.cs @@ -15,10 +15,80 @@ using System.Text; namespace OpenTK { /// - /// Contains mathematical functions for the OpenTK.Math toolkit. + /// Contains common mathematical functions and constants. /// public static class MathHelper { + #region Fields + + /// + /// Defines the value of Pi as a . + /// + public const float Pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930382f; + + /// + /// Defines the value of Pi divided by two as a . + /// + public const float PiOver2 = Pi / 2; + + /// + /// Defines the value of Pi divided by three as a . + /// + public const float PiOver3 = Pi / 3; + + /// + /// Definesthe value of Pi divided by four as a . + /// + public const float PiOver4 = Pi / 4; + + /// + /// Defines the value of Pi divided by six as a . + /// + public const float PiOver6 = Pi / 6; + + /// + /// Defines the value of Pi multiplied by two as a . + /// + public const float TwoPi = 2 * Pi; + + /// + /// Defines the value of Pi multiplied by 3 and divided by two as a . + /// + public const float ThreePiOver2 = 3 * Pi / 2; + + /// + /// Defines the value of E as a . + /// + public const float E = 2.71828182845904523536f; + + /// + /// Defines the base-10 logarithm of E. + /// + public const float Log10E = 0.434294482f; + + /// + /// Defines the base-2 logarithm of E. + /// + public const float Log2E = 1.442695041f; + + [Obsolete] + public static readonly float PIF = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930382f; + [Obsolete] + public static readonly float RTODF = 180.0f / PIF; + [Obsolete] + public static readonly float DTORF = PIF / 180.0f; + + [Obsolete] + public static readonly double PI = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930382d; + [Obsolete] + public static readonly double RTOD = 180.0d / PIF; + [Obsolete] + public static readonly double DTOR = PIF / 180.0d; + + #endregion + + #region Public Members + #region NextPowerOfTwo /// @@ -182,16 +252,13 @@ namespace OpenTK #endregion - 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; - #region Swap + /// + /// Swaps two double values. + /// + /// The first value. + /// The second value. public static void Swap(ref double a, ref double b) { double temp = a; @@ -199,6 +266,11 @@ namespace OpenTK b = temp; } + /// + /// Swaps two float values. + /// + /// The first value. + /// The second value. public static void Swap(ref float a, ref float b) { float temp = a; @@ -207,128 +279,7 @@ namespace OpenTK } #endregion - } - -#if false - public static partial class Math - { - #region --- Vectors --- - - #region --- Addition --- - - /// - /// Adds the given Vector2 to the current Vector3. - /// - /// The right operand of the addition. - /// A new Vector3 containing the result of the addition. - public static Vector2 Add(Vector2 left, Vector2 right) - { - return new Vector2(left).Add(right); - } - - /// - /// Adds the given Vector3 to the current Vector3. - /// - /// The right operand of the addition. - /// A new Vector3 containing the result of the addition. - public static Vector3 Add(Vector2 left, Vector3 right) - { - return new Vector3(left).Add(right); - } - - /// - /// Adds the given Vector4 to the current Vector3. W-coordinate remains unaffected. - /// - /// The right operand of the addition. - /// A new Vector4 containing the result of the addition. - public static Vector4 Add(Vector2 left, Vector4 right) - { - return new Vector4(left).Add(right); - } - - /// - /// Adds the given Vector2 to the current Vector3. - /// - /// The right operand of the addition. - /// A new Vector3 containing the result of the addition. - public static Vector3 Add(Vector3 left, Vector2 right) - { - return new Vector3(left).Add(right); - } - - /// - /// Adds the given Vector3 to the current Vector3. - /// - /// The right operand of the addition. - /// A new Vector3 containing the result of the addition. - public static Vector3 Add(Vector3 left, Vector3 right) - { - return new Vector3(left).Add(right); - } - - /// - /// Adds the given Vector4 to the current Vector3. W-coordinate remains unaffected. - /// - /// The right operand of the addition. - /// A new Vector4 containing the result of the addition. - public static Vector4 Add(Vector3 left, Vector4 right) - { - return new Vector4(left).Add(right); - } - - /// - /// Adds the given Vector2 to the current Vector3. - /// - /// The right operand of the addition. - /// A new Vector3 containing the result of the addition. - public static Vector4 Add(Vector4 left, Vector2 right) - { - return new Vector4(left).Add(right); - } - - /// - /// Adds the given Vector3 to the current Vector3. - /// - /// The right operand of the addition. - /// A new Vector3 containing the result of the addition. - public static Vector4 Add(Vector4 left, Vector3 right) - { - return new Vector4(left).Add(right); - } - - /// - /// Adds the given Vector4 to the current Vector3. W-coordinate remains unaffected. - /// - /// The right operand of the addition. - /// A new Vector4 containing the result of the addition. - public static Vector4 Add(Vector4 left, Vector4 right) - { - return new Vector4(left).Add(right); - } - - #endregion - - #region --- Subtraction --- - - - - #endregion - - #region --- Cross --- - - /// - /// Computes the cross product between the current and the given Vector3. The current Vector3 is set to the result of the computation. - /// - /// The right operand of the cross product - /// The current - public static Vector3 Cross(Vector3 left, Vector3 right) - { - return new Vector3(left).Cross(right); - } - - #endregion #endregion } -#endif }