diff --git a/Source/OpenTK/Math/Quaternion.cs b/Source/OpenTK/Math/Quaternion.cs index cab4a543..306515d0 100644 --- a/Source/OpenTK/Math/Quaternion.cs +++ b/Source/OpenTK/Math/Quaternion.cs @@ -45,27 +45,27 @@ namespace OpenTK.Math #region Constructors - /// - /// Construct a new Quaternion from vector and w components - /// - /// The vector part - /// The w part + /// + /// Construct a new Quaternion from vector and w components + /// + /// The vector part + /// The w part public Quaternion(Vector3 v, float w) { this.xyz = v; this.w = w; } - /// - /// Construct a new Quaternion - /// - /// The x component - /// The y component - /// The z component - /// The w component - public Quaternion(float x, float y, float z, float w) + /// + /// Construct a new Quaternion + /// + /// The x component + /// The y component + /// The z component + /// The w component + public Quaternion(float x, float y, float z, float w) : this(new Vector3(x, y, z), w) - { } + { } #endregion @@ -117,16 +117,16 @@ namespace OpenTK.Math #region ToAxisAngle /// - /// Convert the current quaternion to axis angle representation - /// - /// The resultant axis - /// The resultant angle - public void ToAxisAngle(out Vector3 axis, out float angle) - { + /// Convert the current quaternion to axis angle representation + /// + /// The resultant axis + /// The resultant angle + public void ToAxisAngle(out Vector3 axis, out float angle) + { Vector4 result = ToAxisAngle(); axis = result.Xyz; angle = result.W; - } + } /// /// Convert this instance to an axis-angle representation. @@ -156,34 +156,34 @@ namespace OpenTK.Math return result; } - #endregion + #endregion - #region public float Length + #region public float Length - /// + /// /// Gets the length (magnitude) of the quaternion. /// /// - public float Length + public float Length { get { - return (float)System.Math.Sqrt(W * W + XYZ.LengthSquared); + return (float)System.Math.Sqrt(W * W + Xyz.LengthSquared); } } #endregion - #region public float LengthSquared + #region public float LengthSquared - /// + /// /// Gets the square of the quaternion length (magnitude). /// public float LengthSquared { get { - return W * W + XYZ.LengthSquared; + return W * W + Xyz.LengthSquared; } } @@ -203,19 +203,19 @@ namespace OpenTK.Math #endregion - #region public void Conjugate() + #region public void Conjugate() - /// - /// Convert this quaternion to its conjugate - /// - public void Conjugate() - { + /// + /// Convert this quaternion to its conjugate + /// + public void Conjugate() + { Xyz = -Xyz; - } + } - #endregion + #endregion - #endregion + #endregion #region Static @@ -474,29 +474,29 @@ namespace OpenTK.Math #endregion - #region Operators + #region Operators - public static Quaternion operator +(Quaternion left, Quaternion right) + public static Quaternion operator +(Quaternion left, Quaternion right) { left.Xyz += right.Xyz; left.W += right.W; return left; } - public static Quaternion operator -(Quaternion left, Quaternion right) + public static Quaternion operator -(Quaternion left, Quaternion right) { left.Xyz -= right.Xyz; left.W -= right.W; return left; } - public static Quaternion operator *(Quaternion left, Quaternion right) - { + public static Quaternion operator *(Quaternion left, Quaternion right) + { float w = left.W * right.W - Vector3.Dot(left.Xyz, right.Xyz); left.Xyz = right.W * left.Xyz + left.W * right.Xyz + Vector3.Cross(left.Xyz, right.Xyz); - left.W = w; - return left; - } + left.W = w; + return left; + } public static bool operator ==(Quaternion left, Quaternion right) { diff --git a/Source/OpenTK/Math/Quaterniond.cs b/Source/OpenTK/Math/Quaterniond.cs index be9016e9..2bea3401 100644 --- a/Source/OpenTK/Math/Quaterniond.cs +++ b/Source/OpenTK/Math/Quaterniond.cs @@ -45,25 +45,25 @@ namespace OpenTK.Math #region Constructors - /// - /// Construct a new Quaterniond from vector and w components - /// - /// The vector part - /// The w part - public Quaterniond(Vector3d v, double w) - { + /// + /// Construct a new Quaterniond from vector and w components + /// + /// The vector part + /// The w part + public Quaterniond(Vector3d v, double w) + { this.xyz = v; this.w = w; - } + } - /// - /// Construct a new Quaterniond - /// - /// The x component - /// The y component - /// The z component - /// The w component - public Quaterniond(double x, double y, double z, double w) + /// + /// Construct a new Quaterniond + /// + /// The x component + /// The y component + /// The z component + /// The w component + public Quaterniond(double x, double y, double z, double w) : this(new Vector3d(x, y, z), w) { } @@ -156,34 +156,34 @@ namespace OpenTK.Math return result; } - #endregion + #endregion - #region public double Length + #region public double Length - /// + /// /// Gets the length (magnitude) of the Quaterniond. /// /// - public double Length + public double Length { get { - return (double)System.Math.Sqrt(W * W + XYZ.LengthSquared); + return (double)System.Math.Sqrt(W * W + Xyz.LengthSquared); } } #endregion - #region public double LengthSquared + #region public double LengthSquared - /// + /// /// Gets the square of the Quaterniond length (magnitude). /// public double LengthSquared { get { - return W * W + XYZ.LengthSquared; + return W * W + Xyz.LengthSquared; } } @@ -203,19 +203,19 @@ namespace OpenTK.Math #endregion - #region public void Conjugate() + #region public void Conjugate() - /// - /// Convert this Quaterniond to its conjugate - /// - public void Conjugate() - { + /// + /// Convert this Quaterniond to its conjugate + /// + public void Conjugate() + { Xyz = -Xyz; - } + } - #endregion + #endregion - #endregion + #endregion #region Static @@ -474,29 +474,29 @@ namespace OpenTK.Math #endregion - #region Operators + #region Operators - public static Quaterniond operator +(Quaterniond left, Quaterniond right) + public static Quaterniond operator +(Quaterniond left, Quaterniond right) { left.Xyz += right.Xyz; left.W += right.W; return left; } - public static Quaterniond operator -(Quaterniond left, Quaterniond right) + public static Quaterniond operator -(Quaterniond left, Quaterniond right) { left.Xyz -= right.Xyz; left.W -= right.W; return left; } - public static Quaterniond operator *(Quaterniond left, Quaterniond right) - { + public static Quaterniond operator *(Quaterniond left, Quaterniond right) + { double w = left.W * right.W - Vector3d.Dot(left.Xyz, right.Xyz); left.Xyz = right.W * left.Xyz + left.W * right.Xyz + Vector3d.Cross(left.Xyz, right.Xyz); - left.W = w; - return left; - } + left.W = w; + return left; + } public static bool operator ==(Quaterniond left, Quaterniond right) { @@ -619,14 +619,14 @@ namespace OpenTK.Math /// Constructs left Quaterniond from the given array of double-precision floating point numbers. /// The array of doubles for the components of the Quaterniond. public Quaterniond(double[] doubleArray) - { + { if (doubleArray == null || doubleArray.GetLength(0) < 4) throw new MissingFieldException(); this.W = doubleArray[0]; this.X = doubleArray[1]; this.Y = doubleArray[2]; this.Z = doubleArray[3]; - } + } /// Constructs left Quaterniond from the given matrix. Only contains rotation information. /// The matrix for the components of the Quaterniond. @@ -795,10 +795,10 @@ namespace OpenTK.Math } } - public static double DotProduct(Quaterniond left, Quaterniond right) - { - return left.W * right.W + left.X * right.X + left.Y * right.Y + left.Z * right.Z; - } + public static double DotProduct(Quaterniond left, Quaterniond right) + { + return left.W * right.W + left.X * right.X + left.Y * right.Y + left.Z * right.Z; + } public void Normalize() { @@ -1045,7 +1045,7 @@ namespace OpenTK.Math } public static void Slerp(ref Quaterniond start, ref Quaterniond end, double blend, out Quaterniond result) - { + { if (start.W == 0 && start.X == 0 && start.Y == 0 && start.Z == 0) { if (end.W == 0 && end.X == 0 && end.Y == 0 && end.Z == 0) @@ -1069,37 +1069,37 @@ namespace OpenTK.Math Vector3d endVector = new Vector3d(end.X, end.Y, end.Z); double cosHalfAngle = start.W * end.W + Vector3d.Dot(startVector, endVector); - if (cosHalfAngle >= 1.0f || cosHalfAngle <= -1.0f) - { - // angle = 0.0f, so just return one input. + if (cosHalfAngle >= 1.0f || cosHalfAngle <= -1.0f) + { + // angle = 0.0f, so just return one input. result = start; - } - else if (cosHalfAngle < 0.0f) - { + } + else if (cosHalfAngle < 0.0f) + { end.W = -end.W; end.X = -end.X; end.Y = -end.Y; end.Z = -end.Z; cosHalfAngle = -cosHalfAngle; - } + } - double blendA; + double blendA; double blendB; - if (cosHalfAngle < 0.99f) - { - // do proper slerp for big angles + if (cosHalfAngle < 0.99f) + { + // do proper slerp for big angles double halfAngle = (double)System.Math.Acos(cosHalfAngle); double sinHalfAngle = (double)System.Math.Sin(halfAngle); double oneOverSinHalfAngle = 1.0f / sinHalfAngle; blendA = (double)System.Math.Sin(halfAngle * (1.0f - blend)) * oneOverSinHalfAngle; blendB = (double)System.Math.Sin(halfAngle * blend) * oneOverSinHalfAngle; - } - else - { - // do lerp if angle is really small. - blendA = 1.0f - blend; - blendB = blend; - } + } + else + { + // do lerp if angle is really small. + blendA = 1.0f - blend; + blendB = blend; + } result.W = blendA * start.W + blendB * end.W; result.X = blendA * start.X + blendB * end.X; @@ -1117,7 +1117,7 @@ namespace OpenTK.Math result.Y = 0; result.Z = 0; } - } + } #endregion