diff --git a/Source/OpenTK/Math/BezierCurve.cs b/Source/OpenTK/Math/BezierCurve.cs
index 61eb4843..4e3035bd 100644
--- a/Source/OpenTK/Math/BezierCurve.cs
+++ b/Source/OpenTK/Math/BezierCurve.cs
@@ -207,7 +207,7 @@ namespace OpenTK
foreach (Vector2 pt in points)
{
- temp = (float)Functions.BinomialCoefficient(points.Count - 1, i) * (float)(System.Math.Pow(t, i) *
+ temp = (float)MathHelper.BinomialCoefficient(points.Count - 1, i) * (float)(System.Math.Pow(t, i) *
System.Math.Pow(c, (points.Count - 1) - i));
r.X += temp * pt.X;
@@ -243,7 +243,7 @@ namespace OpenTK
foreach (Vector2 pt in points)
{
- temp = (float)Functions.BinomialCoefficient(points.Count - 2, i) * (float)(System.Math.Pow(t, i) *
+ temp = (float)MathHelper.BinomialCoefficient(points.Count - 2, i) * (float)(System.Math.Pow(t, i) *
System.Math.Pow(c, (points.Count - 2) - i));
r.X += temp * pt.X;
diff --git a/Source/OpenTK/Math/Functions.cs b/Source/OpenTK/Math/Functions.cs
index 5c9f3f22..89deba33 100644
--- a/Source/OpenTK/Math/Functions.cs
+++ b/Source/OpenTK/Math/Functions.cs
@@ -11,14 +11,16 @@
using System;
using System.Collections.Generic;
using System.Text;
+
namespace OpenTK
{
///
/// Contains mathematical functions for the OpenTK.Math toolkit.
///
+ [Obsolete("Use OpenTK.MathHelper instead.")]
public static class Functions
{
- #region public static long NextPowerOfTwo(long n)
+ #region NextPowerOfTwo
///
/// Returns the next power of two that is larger than the specified number.
@@ -31,10 +33,6 @@ namespace OpenTK
return (long)System.Math.Pow(2, System.Math.Ceiling(System.Math.Log((double)n, 2)));
}
- #endregion
-
- #region public static int NextPowerOfTwo(int n)
-
///
/// Returns the next power of two that is larger than the specified number.
///
@@ -46,10 +44,6 @@ namespace OpenTK
return (int)System.Math.Pow(2, System.Math.Ceiling(System.Math.Log((double)n, 2)));
}
- #endregion
-
- #region public static int NextPowerOfTwo(int n)
-
///
/// Returns the next power of two that is larger than the specified number.
///
@@ -61,11 +55,6 @@ namespace OpenTK
return (float)System.Math.Pow(2, System.Math.Ceiling(System.Math.Log((double)n, 2)));
}
- #endregion
-
-
- #region public static int NextPowerOfTwo(int n)
-
///
/// Returns the next power of two that is larger than the specified number.
///
@@ -79,6 +68,8 @@ namespace OpenTK
#endregion
+ #region Factorial
+
/// Calculates the factorial of a given natural number.
///
/// The number.
@@ -93,6 +84,10 @@ namespace OpenTK
return result;
}
+ #endregion
+
+ #region BinomialCoefficient
+
///
/// Calculates the binomial coefficient above .
///
@@ -104,6 +99,10 @@ namespace OpenTK
return Factorial(n) / (Factorial(k) * Factorial(n - k));
}
+ #endregion
+
+ #region InverseSqrtFast
+
///
/// Returns an approximation of the inverse square root of left number.
///
@@ -156,6 +155,10 @@ namespace OpenTK
#endif
}
+ #endregion
+
+ #region DegreesToRadians
+
///
/// Convert degrees to radians
///
@@ -178,6 +181,8 @@ namespace OpenTK
return radians * radToDeg;
}
+ #endregion
+
public static readonly float PIF = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930382f;
public static readonly float RTODF = 180.0f / PIF;
public static readonly float DTORF = PIF / 180.0f;
@@ -186,18 +191,23 @@ namespace OpenTK
public static readonly double RTOD = 180.0d / PIF;
public static readonly double DTOR = PIF / 180.0d;
+ #region Swap
+
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;
}
+
+ #endregion
}
#if false
diff --git a/Source/OpenTK/Math/MathHelper.cs b/Source/OpenTK/Math/MathHelper.cs
new file mode 100644
index 00000000..76bccdd1
--- /dev/null
+++ b/Source/OpenTK/Math/MathHelper.cs
@@ -0,0 +1,334 @@
+#region --- License ---
+/* Licensed under the MIT/X11 license.
+ * Copyright (c) 2006-2008 the OpenTK Team.
+ * This notice may not be removed from any source distribution.
+ * See license.txt for licensing detailed licensing details.
+ *
+ * Contributions by Andy Gill, James Talton and Georg Wächter.
+ */
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace OpenTK
+{
+ ///
+ /// Contains mathematical functions for the OpenTK.Math toolkit.
+ ///
+ public static class MathHelper
+ {
+ #region NextPowerOfTwo
+
+ ///
+ /// Returns the next power of two that is larger than the specified number.
+ ///
+ /// The specified number.
+ /// The next power of two.
+ public static long NextPowerOfTwo(long n)
+ {
+ if (n < 0) throw new ArgumentOutOfRangeException("n", "Must be positive.");
+ return (long)System.Math.Pow(2, System.Math.Ceiling(System.Math.Log((double)n, 2)));
+ }
+
+ ///
+ /// Returns the next power of two that is larger than the specified number.
+ ///
+ /// The specified number.
+ /// The next power of two.
+ public static int NextPowerOfTwo(int n)
+ {
+ if (n < 0) throw new ArgumentOutOfRangeException("n", "Must be positive.");
+ return (int)System.Math.Pow(2, System.Math.Ceiling(System.Math.Log((double)n, 2)));
+ }
+
+ ///
+ /// Returns the next power of two that is larger than the specified number.
+ ///
+ /// The specified number.
+ /// The next power of two.
+ public static float NextPowerOfTwo(float n)
+ {
+ if (n < 0) throw new ArgumentOutOfRangeException("n", "Must be positive.");
+ return (float)System.Math.Pow(2, System.Math.Ceiling(System.Math.Log((double)n, 2)));
+ }
+
+ ///
+ /// Returns the next power of two that is larger than the specified number.
+ ///
+ /// The specified number.
+ /// The next power of two.
+ public static double NextPowerOfTwo(double n)
+ {
+ if (n < 0) throw new ArgumentOutOfRangeException("n", "Must be positive.");
+ return System.Math.Pow(2, System.Math.Ceiling(System.Math.Log((double)n, 2)));
+ }
+
+ #endregion
+
+ #region Factorial
+
+ /// Calculates the factorial of a given natural number.
+ ///
+ /// The number.
+ /// n!
+ public static long Factorial(int n)
+ {
+ long result = 1;
+
+ for (; n > 1; n--)
+ result *= n;
+
+ return result;
+ }
+
+ #endregion
+
+ #region BinomialCoefficient
+
+ ///
+ /// Calculates the binomial coefficient above .
+ ///
+ /// The n.
+ /// The k.
+ /// n! / (k! * (n - k)!)
+ public static long BinomialCoefficient(int n, int k)
+ {
+ return Factorial(n) / (Factorial(k) * Factorial(n - k));
+ }
+
+ #endregion
+
+ #region InverseSqrtFast
+
+ ///
+ /// Returns an approximation of the inverse square root of left number.
+ ///
+ /// A number.
+ /// An approximation of the inverse square root of the specified number, with an upper error bound of 0.001
+ ///
+ /// This is an improved implementation of the the method known as Carmack's inverse square root
+ /// which is found in the Quake III source code. This implementation comes from
+ /// http://www.codemaestro.com/reviews/review00000105.html. For the history of this method, see
+ /// http://www.beyond3d.com/content/articles/8/
+ ///
+ public static float InverseSqrtFast(float x)
+ {
+ unsafe
+ {
+ float xhalf = 0.5f * x;
+ int i = *(int*)&x; // Read bits as integer.
+ i = 0x5f375a86 - (i >> 1); // Make an initial guess for Newton-Raphson approximation
+ x = *(float*)&i; // Convert bits back to float
+ x = x * (1.5f - xhalf * x * x); // Perform left single Newton-Raphson step.
+ return x;
+ }
+ }
+
+ ///
+ /// Returns an approximation of the inverse square root of left number.
+ ///
+ /// A number.
+ /// An approximation of the inverse square root of the specified number, with an upper error bound of 0.001
+ ///
+ /// This is an improved implementation of the the method known as Carmack's inverse square root
+ /// which is found in the Quake III source code. This implementation comes from
+ /// http://www.codemaestro.com/reviews/review00000105.html. For the history of this method, see
+ /// http://www.beyond3d.com/content/articles/8/
+ ///
+ public static double InverseSqrtFast(double x)
+ {
+ return InverseSqrtFast((float)x);
+ // TODO: The following code is wrong. Fix it, to improve precision.
+#if false
+ unsafe
+ {
+ double xhalf = 0.5f * x;
+ int i = *(int*)&x; // Read bits as integer.
+ i = 0x5f375a86 - (i >> 1); // Make an initial guess for Newton-Raphson approximation
+ x = *(float*)&i; // Convert bits back to float
+ x = x * (1.5f - xhalf * x * x); // Perform left single Newton-Raphson step.
+ return x;
+ }
+#endif
+ }
+
+ #endregion
+
+ #region DegreesToRadians
+
+ ///
+ /// Convert degrees to radians
+ ///
+ /// An angle in degrees
+ /// The angle expressed in radians
+ public static float DegreesToRadians(float degrees)
+ {
+ const float degToRad = (float)System.Math.PI / 180.0f;
+ return degrees * degToRad;
+ }
+
+ ///
+ /// Convert radians to degrees
+ ///
+ /// An angle in radians
+ /// The angle expressed in degrees
+ public static float RadiansToDegrees(float radians)
+ {
+ const float radToDeg = 180.0f / (float)System.Math.PI;
+ return radians * radToDeg;
+ }
+
+ #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
+
+ 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;
+ }
+
+ #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
+}
diff --git a/Source/OpenTK/Math/Matrix4.cs b/Source/OpenTK/Math/Matrix4.cs
index cc97b02b..a13c63c7 100644
--- a/Source/OpenTK/Math/Matrix4.cs
+++ b/Source/OpenTK/Math/Matrix4.cs
@@ -761,7 +761,7 @@ namespace OpenTK
/// Eye (camera) position in world space
/// Target position in world space
/// Up vector in world space (should not be parallel to the camera direction, that is target - eye)
- /// A Matrix that transforms world space to camera space
+ /// A Matrix4 that transforms world space to camera space
public static Matrix4 LookAt(Vector3 eye, Vector3 target, Vector3 up)
{
Vector3 z = Vector3.Normalize(eye - target);
@@ -778,6 +778,24 @@ namespace OpenTK
return trans * rot;
}
+ ///
+ /// Build a world space to camera space matrix
+ ///
+ /// Eye (camera) position in world space
+ /// Eye (camera) position in world space
+ /// Eye (camera) position in world space
+ /// Target position in world space
+ /// Target position in world space
+ /// Target position in world space
+ /// Up vector in world space (should not be parallel to the camera direction, that is target - eye)
+ /// Up vector in world space (should not be parallel to the camera direction, that is target - eye)
+ /// Up vector in world space (should not be parallel to the camera direction, that is target - eye)
+ /// A Matrix4 that transforms world space to camera space
+ public static Matrix4 LookAt(float eyeX, float eyeY, float eyeZ, float targetX, float targetY, float targetZ, float upX, float upY, float upZ)
+ {
+ return LookAt(new Vector3(eyeX, eyeY, eyeZ), new Vector3(targetX, targetY, targetZ), new Vector3(upX, upY, upZ));
+ }
+
///
/// Build a projection matrix
///
diff --git a/Source/OpenTK/Math/Matrix4d.cs b/Source/OpenTK/Math/Matrix4d.cs
index 86b35b99..1a030653 100644
--- a/Source/OpenTK/Math/Matrix4d.cs
+++ b/Source/OpenTK/Math/Matrix4d.cs
@@ -628,6 +628,24 @@ namespace OpenTK
return trans * rot;
}
+ ///
+ /// Build a world space to camera space matrix
+ ///
+ /// Eye (camera) position in world space
+ /// Eye (camera) position in world space
+ /// Eye (camera) position in world space
+ /// Target position in world space
+ /// Target position in world space
+ /// Target position in world space
+ /// Up vector in world space (should not be parallel to the camera direction, that is target - eye)
+ /// Up vector in world space (should not be parallel to the camera direction, that is target - eye)
+ /// Up vector in world space (should not be parallel to the camera direction, that is target - eye)
+ /// A Matrix4 that transforms world space to camera space
+ public static Matrix4d LookAt(double eyeX, double eyeY, double eyeZ, double targetX, double targetY, double targetZ, double upX, double upY, double upZ)
+ {
+ return LookAt(new Vector3d(eyeX, eyeY, eyeZ), new Vector3d(targetX, targetY, targetZ), new Vector3d(upX, upY, upZ));
+ }
+
///
/// Build a projection matrix
///
diff --git a/Source/OpenTK/Math/Vector2.cs b/Source/OpenTK/Math/Vector2.cs
index 6f005891..66a0b746 100644
--- a/Source/OpenTK/Math/Vector2.cs
+++ b/Source/OpenTK/Math/Vector2.cs
@@ -199,7 +199,7 @@ namespace OpenTK
{
get
{
- return 1.0f /OpenTK.Functions.InverseSqrtFast(X * X + Y * Y);
+ return 1.0f / MathHelper.InverseSqrtFast(X * X + Y * Y);
}
}
@@ -277,7 +277,7 @@ namespace OpenTK
///
public void NormalizeFast()
{
- float scale = Functions.InverseSqrtFast(X * X + Y * Y);
+ float scale = MathHelper.InverseSqrtFast(X * X + Y * Y);
X *= scale;
Y *= scale;
}
@@ -624,7 +624,7 @@ namespace OpenTK
/// The normalized vector
public static Vector2 NormalizeFast(Vector2 vec)
{
- float scale = Functions.InverseSqrtFast(vec.X * vec.X + vec.Y * vec.Y);
+ float scale = MathHelper.InverseSqrtFast(vec.X * vec.X + vec.Y * vec.Y);
vec.X *= scale;
vec.Y *= scale;
return vec;
@@ -637,7 +637,7 @@ namespace OpenTK
/// The normalized vector
public static void NormalizeFast(ref Vector2 vec, out Vector2 result)
{
- float scale = Functions.InverseSqrtFast(vec.X * vec.X + vec.Y * vec.Y);
+ float scale = MathHelper.InverseSqrtFast(vec.X * vec.X + vec.Y * vec.Y);
result.X = vec.X * scale;
result.Y = vec.Y * scale;
}
diff --git a/Source/OpenTK/Math/Vector2d.cs b/Source/OpenTK/Math/Vector2d.cs
index 4cff4607..1e799cf8 100644
--- a/Source/OpenTK/Math/Vector2d.cs
+++ b/Source/OpenTK/Math/Vector2d.cs
@@ -512,7 +512,7 @@ namespace OpenTK
/// The normalized vector
public static Vector2d NormalizeFast(Vector2d vec)
{
- double scale = Functions.InverseSqrtFast(vec.X * vec.X + vec.Y * vec.Y);
+ double scale = MathHelper.InverseSqrtFast(vec.X * vec.X + vec.Y * vec.Y);
vec.X *= scale;
vec.Y *= scale;
return vec;
@@ -525,7 +525,7 @@ namespace OpenTK
/// The normalized vector
public static void NormalizeFast(ref Vector2d vec, out Vector2d result)
{
- double scale = Functions.InverseSqrtFast(vec.X * vec.X + vec.Y * vec.Y);
+ double scale = MathHelper.InverseSqrtFast(vec.X * vec.X + vec.Y * vec.Y);
result.X = vec.X * scale;
result.Y = vec.Y * scale;
}
diff --git a/Source/OpenTK/Math/Vector3.cs b/Source/OpenTK/Math/Vector3.cs
index cf09708d..214ae445 100644
--- a/Source/OpenTK/Math/Vector3.cs
+++ b/Source/OpenTK/Math/Vector3.cs
@@ -215,7 +215,7 @@ namespace OpenTK
{
get
{
- return 1.0f /OpenTK.Functions.InverseSqrtFast(X * X + Y * Y + Z * Z);
+ return 1.0f / MathHelper.InverseSqrtFast(X * X + Y * Y + Z * Z);
}
}
@@ -264,7 +264,7 @@ namespace OpenTK
///
public void NormalizeFast()
{
- float scale = Functions.InverseSqrtFast(X * X + Y * Y + Z * Z);
+ float scale = MathHelper.InverseSqrtFast(X * X + Y * Y + Z * Z);
X *= scale;
Y *= scale;
Z *= scale;
@@ -637,7 +637,7 @@ namespace OpenTK
/// The normalized vector
public static Vector3 NormalizeFast(Vector3 vec)
{
- float scale = Functions.InverseSqrtFast(vec.X * vec.X + vec.Y * vec.Y + vec.Z * vec.Z);
+ float scale = MathHelper.InverseSqrtFast(vec.X * vec.X + vec.Y * vec.Y + vec.Z * vec.Z);
vec.X *= scale;
vec.Y *= scale;
vec.Z *= scale;
@@ -651,7 +651,7 @@ namespace OpenTK
/// The normalized vector
public static void NormalizeFast(ref Vector3 vec, out Vector3 result)
{
- float scale = Functions.InverseSqrtFast(vec.X * vec.X + vec.Y * vec.Y + vec.Z * vec.Z);
+ float scale = MathHelper.InverseSqrtFast(vec.X * vec.X + vec.Y * vec.Y + vec.Z * vec.Z);
result.X = vec.X * scale;
result.Y = vec.Y * scale;
result.Z = vec.Z * scale;
diff --git a/Source/OpenTK/Math/Vector3d.cs b/Source/OpenTK/Math/Vector3d.cs
index babda74f..e120b8de 100644
--- a/Source/OpenTK/Math/Vector3d.cs
+++ b/Source/OpenTK/Math/Vector3d.cs
@@ -214,7 +214,7 @@ namespace OpenTK
{
get
{
- return 1.0f / OpenTK.Functions.InverseSqrtFast(X * X + Y * Y + Z * Z);
+ return 1.0f / MathHelper.InverseSqrtFast(X * X + Y * Y + Z * Z);
}
}
@@ -263,7 +263,7 @@ namespace OpenTK
///
public void NormalizeFast()
{
- double scale = Functions.InverseSqrtFast(X * X + Y * Y + Z * Z);
+ double scale = MathHelper.InverseSqrtFast(X * X + Y * Y + Z * Z);
X *= scale;
Y *= scale;
Z *= scale;
@@ -636,7 +636,7 @@ namespace OpenTK
/// The normalized vector
public static Vector3d NormalizeFast(Vector3d vec)
{
- double scale = Functions.InverseSqrtFast(vec.X * vec.X + vec.Y * vec.Y + vec.Z * vec.Z);
+ double scale = MathHelper.InverseSqrtFast(vec.X * vec.X + vec.Y * vec.Y + vec.Z * vec.Z);
vec.X *= scale;
vec.Y *= scale;
vec.Z *= scale;
@@ -650,7 +650,7 @@ namespace OpenTK
/// The normalized vector
public static void NormalizeFast(ref Vector3d vec, out Vector3d result)
{
- double scale = Functions.InverseSqrtFast(vec.X * vec.X + vec.Y * vec.Y + vec.Z * vec.Z);
+ double scale = MathHelper.InverseSqrtFast(vec.X * vec.X + vec.Y * vec.Y + vec.Z * vec.Z);
result.X = vec.X * scale;
result.Y = vec.Y * scale;
result.Z = vec.Z * scale;
diff --git a/Source/OpenTK/Math/Vector4.cs b/Source/OpenTK/Math/Vector4.cs
index 018a6dcc..677c9b2e 100644
--- a/Source/OpenTK/Math/Vector4.cs
+++ b/Source/OpenTK/Math/Vector4.cs
@@ -277,7 +277,7 @@ namespace OpenTK
{
get
{
- return 1.0f /OpenTK.Functions.InverseSqrtFast(X * X + Y * Y + Z * Z + W * W);
+ return 1.0f / MathHelper.InverseSqrtFast(X * X + Y * Y + Z * Z + W * W);
}
}
@@ -327,7 +327,7 @@ namespace OpenTK
///
public void NormalizeFast()
{
- float scale = Functions.InverseSqrtFast(X * X + Y * Y + Z * Z + W * W);
+ float scale = MathHelper.InverseSqrtFast(X * X + Y * Y + Z * Z + W * W);
X *= scale;
Y *= scale;
Z *= scale;
@@ -657,7 +657,7 @@ namespace OpenTK
/// The normalized vector
public static Vector4 NormalizeFast(Vector4 vec)
{
- float scale = Functions.InverseSqrtFast(vec.X * vec.X + vec.Y * vec.Y + vec.Z * vec.Z + vec.W * vec.W);
+ float scale = MathHelper.InverseSqrtFast(vec.X * vec.X + vec.Y * vec.Y + vec.Z * vec.Z + vec.W * vec.W);
vec.X *= scale;
vec.Y *= scale;
vec.Z *= scale;
@@ -672,7 +672,7 @@ namespace OpenTK
/// The normalized vector
public static void NormalizeFast(ref Vector4 vec, out Vector4 result)
{
- float scale = Functions.InverseSqrtFast(vec.X * vec.X + vec.Y * vec.Y + vec.Z * vec.Z + vec.W * vec.W);
+ float scale = MathHelper.InverseSqrtFast(vec.X * vec.X + vec.Y * vec.Y + vec.Z * vec.Z + vec.W * vec.W);
result.X = vec.X * scale;
result.Y = vec.Y * scale;
result.Z = vec.Z * scale;
diff --git a/Source/OpenTK/Math/Vector4d.cs b/Source/OpenTK/Math/Vector4d.cs
index 484b4347..c121f790 100644
--- a/Source/OpenTK/Math/Vector4d.cs
+++ b/Source/OpenTK/Math/Vector4d.cs
@@ -275,7 +275,7 @@ namespace OpenTK
{
get
{
- return 1.0f / OpenTK.Functions.InverseSqrtFast(X * X + Y * Y + Z * Z + W * W);
+ return 1.0f / MathHelper.InverseSqrtFast(X * X + Y * Y + Z * Z + W * W);
}
}
@@ -324,7 +324,7 @@ namespace OpenTK
///
public void NormalizeFast()
{
- double scale = Functions.InverseSqrtFast(X * X + Y * Y + Z * Z + W * W);
+ double scale = MathHelper.InverseSqrtFast(X * X + Y * Y + Z * Z + W * W);
X *= scale;
Y *= scale;
Z *= scale;
@@ -654,7 +654,7 @@ namespace OpenTK
/// The normalized vector
public static Vector4d NormalizeFast(Vector4d vec)
{
- double scale = Functions.InverseSqrtFast(vec.X * vec.X + vec.Y * vec.Y + vec.Z * vec.Z + vec.W * vec.W);
+ double scale = MathHelper.InverseSqrtFast(vec.X * vec.X + vec.Y * vec.Y + vec.Z * vec.Z + vec.W * vec.W);
vec.X *= scale;
vec.Y *= scale;
vec.Z *= scale;
@@ -669,7 +669,7 @@ namespace OpenTK
/// The normalized vector
public static void NormalizeFast(ref Vector4d vec, out Vector4d result)
{
- double scale = Functions.InverseSqrtFast(vec.X * vec.X + vec.Y * vec.Y + vec.Z * vec.Z + vec.W * vec.W);
+ double scale = MathHelper.InverseSqrtFast(vec.X * vec.X + vec.Y * vec.Y + vec.Z * vec.Z + vec.W * vec.W);
result.X = vec.X * scale;
result.Y = vec.Y * scale;
result.Z = vec.Z * scale;