From 77262129214d6c722146ac8269787840e631933f Mon Sep 17 00:00:00 2001 From: the_fiddler Date: Fri, 17 Jul 2009 08:27:25 +0000 Subject: [PATCH] Replaced tabs with spaces. --- Source/OpenTK/Math/BezierCurve.cs | 410 +++++++++++------------ Source/OpenTK/Math/BezierCurveCubic.cs | 244 +++++++------- Source/OpenTK/Math/BezierCurveQuadric.cs | 222 ++++++------ Source/OpenTK/Math/Functions.cs | 47 ++- Source/OpenTK/Math/Half.cs | 4 +- Source/OpenTK/Math/Matrix4.cs | 218 ++++++------ Source/OpenTK/Math/Matrix4d.cs | 110 +++--- Source/OpenTK/Math/Vector2.cs | 156 ++++----- Source/OpenTK/Math/Vector4.cs | 106 +++--- 9 files changed, 758 insertions(+), 759 deletions(-) diff --git a/Source/OpenTK/Math/BezierCurve.cs b/Source/OpenTK/Math/BezierCurve.cs index ed832121..61eb4843 100644 --- a/Source/OpenTK/Math/BezierCurve.cs +++ b/Source/OpenTK/Math/BezierCurve.cs @@ -14,248 +14,248 @@ using System.Text; namespace OpenTK { - /// - /// Represents a bezier curve with as many points as you want. - /// - [Serializable] - public struct BezierCurve - { - #region Fields + /// + /// Represents a bezier curve with as many points as you want. + /// + [Serializable] + public struct BezierCurve + { + #region Fields - private List points; + private List points; - /// - /// The parallel value. - /// - /// This value defines whether the curve should be calculated as a - /// parallel curve to the original bezier curve. A value of 0.0f represents - /// the original curve, 5.0f i.e. stands for a curve that has always a distance - /// of 5.0f to the orignal curve at any point. - public float Parallel; + /// + /// The parallel value. + /// + /// This value defines whether the curve should be calculated as a + /// parallel curve to the original bezier curve. A value of 0.0f represents + /// the original curve, 5.0f i.e. stands for a curve that has always a distance + /// of 5.0f to the orignal curve at any point. + public float Parallel; - #endregion + #endregion - #region Properties + #region Properties - /// - /// Gets the points of this curve. - /// - /// The first point and the last points represent the anchor points. - public IList Points - { - get - { - return points; - } - } + /// + /// Gets the points of this curve. + /// + /// The first point and the last points represent the anchor points. + public IList Points + { + get + { + return points; + } + } - #endregion + #endregion - #region Constructors + #region Constructors - /// - /// Constructs a new . - /// - /// The points. - public BezierCurve(IEnumerable points) - { - if (points == null) - throw new ArgumentNullException("points", "Must point to a valid list of Vector2 structures."); + /// + /// Constructs a new . + /// + /// The points. + public BezierCurve(IEnumerable points) + { + if (points == null) + throw new ArgumentNullException("points", "Must point to a valid list of Vector2 structures."); - this.points = new List(points); - this.Parallel = 0.0f; - } + this.points = new List(points); + this.Parallel = 0.0f; + } - /// - /// Constructs a new . - /// - /// The points. - public BezierCurve(params Vector2[] points) - { - if (points == null) - throw new ArgumentNullException("points", "Must point to a valid list of Vector2 structures."); + /// + /// Constructs a new . + /// + /// The points. + public BezierCurve(params Vector2[] points) + { + if (points == null) + throw new ArgumentNullException("points", "Must point to a valid list of Vector2 structures."); - this.points = new List(points); - this.Parallel = 0.0f; - } + this.points = new List(points); + this.Parallel = 0.0f; + } - /// - /// Constructs a new . - /// - /// The parallel value. - /// The points. - public BezierCurve(float parallel, params Vector2[] points) - { - if (points == null) - throw new ArgumentNullException("points", "Must point to a valid list of Vector2 structures."); + /// + /// Constructs a new . + /// + /// The parallel value. + /// The points. + public BezierCurve(float parallel, params Vector2[] points) + { + if (points == null) + throw new ArgumentNullException("points", "Must point to a valid list of Vector2 structures."); - this.Parallel = parallel; - this.points = new List(points); - } + this.Parallel = parallel; + this.points = new List(points); + } - /// - /// Constructs a new . - /// - /// The parallel value. - /// The points. - public BezierCurve(float parallel, IEnumerable points) - { - if (points == null) - throw new ArgumentNullException("points", "Must point to a valid list of Vector2 structures."); + /// + /// Constructs a new . + /// + /// The parallel value. + /// The points. + public BezierCurve(float parallel, IEnumerable points) + { + if (points == null) + throw new ArgumentNullException("points", "Must point to a valid list of Vector2 structures."); - this.Parallel = parallel; - this.points = new List(points); - } + this.Parallel = parallel; + this.points = new List(points); + } - #endregion + #endregion - #region Functions + #region Functions - /// - /// Calculates the point with the specified t. - /// - /// The t value, between 0.0f and 1.0f. - /// Resulting point. - public Vector2 CalculatePoint(float t) - { - return BezierCurve.CalculatePoint(points, t, Parallel); - } + /// + /// Calculates the point with the specified t. + /// + /// The t value, between 0.0f and 1.0f. + /// Resulting point. + public Vector2 CalculatePoint(float t) + { + return BezierCurve.CalculatePoint(points, t, Parallel); + } - /// - /// Calculates the length of this bezier curve. - /// - /// The precision. - /// Length of curve. - /// The precision gets better as the - /// value gets smaller. - public float CalculateLength(float precision) - { - return BezierCurve.CalculateLength(points, precision, Parallel); - } + /// + /// Calculates the length of this bezier curve. + /// + /// The precision. + /// Length of curve. + /// The precision gets better as the + /// value gets smaller. + public float CalculateLength(float precision) + { + return BezierCurve.CalculateLength(points, precision, Parallel); + } - #region Static methods + #region Static methods - /// - /// Calculates the length of the specified bezier curve. - /// - /// The points. - /// The precision value. - /// The precision gets better as the - /// value gets smaller. - public static float CalculateLength(IList points, float precision) - { - return BezierCurve.CalculateLength(points, precision, 0.0f); - } + /// + /// Calculates the length of the specified bezier curve. + /// + /// The points. + /// The precision value. + /// The precision gets better as the + /// value gets smaller. + public static float CalculateLength(IList points, float precision) + { + return BezierCurve.CalculateLength(points, precision, 0.0f); + } - /// - /// Calculates the length of the specified bezier curve. - /// - /// The points. - /// The precision value. - /// The parallel value. - /// Length of curve. - /// The precision gets better as the - /// value gets smaller. - /// The parameter defines whether the curve should be calculated as a - /// parallel curve to the original bezier curve. A value of 0.0f represents - /// the original curve, 5.0f represents a curve that has always a distance - /// of 5.0f to the orignal curve. - public static float CalculateLength(IList points, float precision, float parallel) - { - float length = 0.0f; - Vector2 old = BezierCurve.CalculatePoint(points, 0.0f, parallel); + /// + /// Calculates the length of the specified bezier curve. + /// + /// The points. + /// The precision value. + /// The parallel value. + /// Length of curve. + /// The precision gets better as the + /// value gets smaller. + /// The parameter defines whether the curve should be calculated as a + /// parallel curve to the original bezier curve. A value of 0.0f represents + /// the original curve, 5.0f represents a curve that has always a distance + /// of 5.0f to the orignal curve. + public static float CalculateLength(IList points, float precision, float parallel) + { + float length = 0.0f; + Vector2 old = BezierCurve.CalculatePoint(points, 0.0f, parallel); - for (float i = precision; i < (1.0f + precision); i += precision) - { - Vector2 n = CalculatePoint(points, i, parallel); - length += (n - old).Length; - old = n; - } + for (float i = precision; i < (1.0f + precision); i += precision) + { + Vector2 n = CalculatePoint(points, i, parallel); + length += (n - old).Length; + old = n; + } - return length; - } + return length; + } - /// - /// Calculates the point on the given bezier curve with the specified t parameter. - /// - /// The points. - /// The t parameter, a value between 0.0f and 1.0f. - /// Resulting point. - public static Vector2 CalculatePoint(IList points, float t) - { - return BezierCurve.CalculatePoint(points, t, 0.0f); - } + /// + /// Calculates the point on the given bezier curve with the specified t parameter. + /// + /// The points. + /// The t parameter, a value between 0.0f and 1.0f. + /// Resulting point. + public static Vector2 CalculatePoint(IList points, float t) + { + return BezierCurve.CalculatePoint(points, t, 0.0f); + } - /// - /// Calculates the point on the given bezier curve with the specified t parameter. - /// - /// The points. - /// The t parameter, a value between 0.0f and 1.0f. - /// The parallel value. - /// Resulting point. - /// The parameter defines whether the curve should be calculated as a - /// parallel curve to the original bezier curve. A value of 0.0f represents - /// the original curve, 5.0f represents a curve that has always a distance - /// of 5.0f to the orignal curve. - public static Vector2 CalculatePoint(IList points, float t, float parallel) - { - Vector2 r = new Vector2(); - double c = 1.0d - (double)t; - float temp; - int i = 0; + /// + /// Calculates the point on the given bezier curve with the specified t parameter. + /// + /// The points. + /// The t parameter, a value between 0.0f and 1.0f. + /// The parallel value. + /// Resulting point. + /// The parameter defines whether the curve should be calculated as a + /// parallel curve to the original bezier curve. A value of 0.0f represents + /// the original curve, 5.0f represents a curve that has always a distance + /// of 5.0f to the orignal curve. + public static Vector2 CalculatePoint(IList points, float t, float parallel) + { + Vector2 r = new Vector2(); + double c = 1.0d - (double)t; + float temp; + int i = 0; - foreach (Vector2 pt in points) - { - temp = (float)Functions.BinomialCoefficient(points.Count - 1, i) * (float)(System.Math.Pow(t, i) * - System.Math.Pow(c, (points.Count - 1) - i)); + foreach (Vector2 pt in points) + { + temp = (float)Functions.BinomialCoefficient(points.Count - 1, i) * (float)(System.Math.Pow(t, i) * + System.Math.Pow(c, (points.Count - 1) - i)); - r.X += temp * pt.X; - r.Y += temp * pt.Y; - i++; - } + r.X += temp * pt.X; + r.Y += temp * pt.Y; + i++; + } - if (parallel == 0.0f) - return r; + if (parallel == 0.0f) + return r; - Vector2 perpendicular = new Vector2(); + Vector2 perpendicular = new Vector2(); - if (t != 0.0f) - perpendicular = r - BezierCurve.CalculatePointOfDerivative(points, t); - else - perpendicular = points[1] - points[0]; + if (t != 0.0f) + perpendicular = r - BezierCurve.CalculatePointOfDerivative(points, t); + else + perpendicular = points[1] - points[0]; - return r + Vector2.Normalize(perpendicular).PerpendicularRight * parallel; - } + return r + Vector2.Normalize(perpendicular).PerpendicularRight * parallel; + } - /// - /// Calculates the point with the specified t of the derivative of the given bezier function. - /// - /// The points. - /// The t parameter, value between 0.0f and 1.0f. - /// Resulting point. - private static Vector2 CalculatePointOfDerivative(IList points, float t) - { - Vector2 r = new Vector2(); - double c = 1.0d - (double)t; - float temp; - int i = 0; + /// + /// Calculates the point with the specified t of the derivative of the given bezier function. + /// + /// The points. + /// The t parameter, value between 0.0f and 1.0f. + /// Resulting point. + private static Vector2 CalculatePointOfDerivative(IList points, float t) + { + Vector2 r = new Vector2(); + double c = 1.0d - (double)t; + float temp; + int i = 0; - foreach (Vector2 pt in points) - { - temp = (float)Functions.BinomialCoefficient(points.Count - 2, i) * (float)(System.Math.Pow(t, i) * - System.Math.Pow(c, (points.Count - 2) - i)); + foreach (Vector2 pt in points) + { + temp = (float)Functions.BinomialCoefficient(points.Count - 2, i) * (float)(System.Math.Pow(t, i) * + System.Math.Pow(c, (points.Count - 2) - i)); - r.X += temp * pt.X; - r.Y += temp * pt.Y; - i++; - } + r.X += temp * pt.X; + r.Y += temp * pt.Y; + i++; + } - return r; - } + return r; + } - #endregion + #endregion - #endregion - } + #endregion + } } diff --git a/Source/OpenTK/Math/BezierCurveCubic.cs b/Source/OpenTK/Math/BezierCurveCubic.cs index 77e9cf48..149bbf7a 100644 --- a/Source/OpenTK/Math/BezierCurveCubic.cs +++ b/Source/OpenTK/Math/BezierCurveCubic.cs @@ -14,150 +14,150 @@ using System.Text; namespace OpenTK { - /// - /// Represents a cubic bezier curve with two anchor and two control points. - /// - [Serializable] - public struct BezierCurveCubic - { - #region Fields + /// + /// Represents a cubic bezier curve with two anchor and two control points. + /// + [Serializable] + public struct BezierCurveCubic + { + #region Fields - /// - /// Start anchor point. - /// - public Vector2 StartAnchor; + /// + /// Start anchor point. + /// + public Vector2 StartAnchor; - /// - /// End anchor point. - /// - public Vector2 EndAnchor; + /// + /// End anchor point. + /// + public Vector2 EndAnchor; - /// - /// First control point, controls the direction of the curve start. - /// - public Vector2 FirstControlPoint; + /// + /// First control point, controls the direction of the curve start. + /// + public Vector2 FirstControlPoint; - /// - /// Second control point, controls the direction of the curve end. - /// - public Vector2 SecondControlPoint; + /// + /// Second control point, controls the direction of the curve end. + /// + public Vector2 SecondControlPoint; - /// - /// Gets or sets the parallel value. - /// - /// This value defines whether the curve should be calculated as a - /// parallel curve to the original bezier curve. A value of 0.0f represents - /// the original curve, 5.0f i.e. stands for a curve that has always a distance - /// of 5.f to the orignal curve at any point. - public float Parallel; + /// + /// Gets or sets the parallel value. + /// + /// This value defines whether the curve should be calculated as a + /// parallel curve to the original bezier curve. A value of 0.0f represents + /// the original curve, 5.0f i.e. stands for a curve that has always a distance + /// of 5.f to the orignal curve at any point. + public float Parallel; - #endregion + #endregion - #region Constructors + #region Constructors - /// - /// Constructs a new . - /// - /// The start anchor point. - /// The end anchor point. - /// The first control point. - /// The second control point. - public BezierCurveCubic(Vector2 startAnchor, Vector2 endAnchor, Vector2 firstControlPoint, Vector2 secondControlPoint) - { - this.StartAnchor = startAnchor; - this.EndAnchor = endAnchor; - this.FirstControlPoint = firstControlPoint; - this.SecondControlPoint = secondControlPoint; - this.Parallel = 0.0f; - } + /// + /// Constructs a new . + /// + /// The start anchor point. + /// The end anchor point. + /// The first control point. + /// The second control point. + public BezierCurveCubic(Vector2 startAnchor, Vector2 endAnchor, Vector2 firstControlPoint, Vector2 secondControlPoint) + { + this.StartAnchor = startAnchor; + this.EndAnchor = endAnchor; + this.FirstControlPoint = firstControlPoint; + this.SecondControlPoint = secondControlPoint; + this.Parallel = 0.0f; + } - /// - /// Constructs a new . - /// - /// The parallel value. - /// The start anchor point. - /// The end anchor point. - /// The first control point. - /// The second control point. - public BezierCurveCubic(float parallel, Vector2 startAnchor, Vector2 endAnchor, Vector2 firstControlPoint, Vector2 secondControlPoint) - { - this.Parallel = parallel; - this.StartAnchor = startAnchor; - this.EndAnchor = endAnchor; - this.FirstControlPoint = firstControlPoint; - this.SecondControlPoint = secondControlPoint; - } + /// + /// Constructs a new . + /// + /// The parallel value. + /// The start anchor point. + /// The end anchor point. + /// The first control point. + /// The second control point. + public BezierCurveCubic(float parallel, Vector2 startAnchor, Vector2 endAnchor, Vector2 firstControlPoint, Vector2 secondControlPoint) + { + this.Parallel = parallel; + this.StartAnchor = startAnchor; + this.EndAnchor = endAnchor; + this.FirstControlPoint = firstControlPoint; + this.SecondControlPoint = secondControlPoint; + } - #endregion + #endregion - #region Functions + #region Functions - /// - /// Calculates the point with the specified t. - /// - /// The t value, between 0.0f and 1.0f. - /// Resulting point. - public Vector2 CalculatePoint(float t) - { - Vector2 r = new Vector2(); - float c = 1.0f - t; + /// + /// Calculates the point with the specified t. + /// + /// The t value, between 0.0f and 1.0f. + /// Resulting point. + public Vector2 CalculatePoint(float t) + { + Vector2 r = new Vector2(); + float c = 1.0f - t; - r.X = (StartAnchor.X * c * c * c) + (FirstControlPoint.X * 3 * t * c * c) + (SecondControlPoint.X * 3 * t * t * c) - + EndAnchor.X * t * t * t; - r.Y = (StartAnchor.Y * c * c * c) + (FirstControlPoint.Y * 3 * t * c * c) + (SecondControlPoint.Y * 3 * t * t * c) - + EndAnchor.Y * t * t * t; + r.X = (StartAnchor.X * c * c * c) + (FirstControlPoint.X * 3 * t * c * c) + (SecondControlPoint.X * 3 * t * t * c) + + EndAnchor.X * t * t * t; + r.Y = (StartAnchor.Y * c * c * c) + (FirstControlPoint.Y * 3 * t * c * c) + (SecondControlPoint.Y * 3 * t * t * c) + + EndAnchor.Y * t * t * t; - if (Parallel == 0.0f) - return r; + if (Parallel == 0.0f) + return r; - Vector2 perpendicular = new Vector2(); + Vector2 perpendicular = new Vector2(); - if (t == 0.0f) - perpendicular = FirstControlPoint - StartAnchor; - else - perpendicular = r - CalculatePointOfDerivative(t); + if (t == 0.0f) + perpendicular = FirstControlPoint - StartAnchor; + else + perpendicular = r - CalculatePointOfDerivative(t); - return r + Vector2.Normalize(perpendicular).PerpendicularRight * Parallel; - } + return r + Vector2.Normalize(perpendicular).PerpendicularRight * Parallel; + } - /// - /// Calculates the point with the specified t of the derivative of this function. - /// - /// The t, value between 0.0f and 1.0f. - /// Resulting point. - private Vector2 CalculatePointOfDerivative(float t) - { - Vector2 r = new Vector2(); - float c = 1.0f - t; + /// + /// Calculates the point with the specified t of the derivative of this function. + /// + /// The t, value between 0.0f and 1.0f. + /// Resulting point. + private Vector2 CalculatePointOfDerivative(float t) + { + Vector2 r = new Vector2(); + float c = 1.0f - t; - r.X = (c * c * StartAnchor.X) + (2 * t * c * FirstControlPoint.X) + (t * t * SecondControlPoint.X); - r.Y = (c * c * StartAnchor.Y) + (2 * t * c * FirstControlPoint.Y) + (t * t * SecondControlPoint.Y); + r.X = (c * c * StartAnchor.X) + (2 * t * c * FirstControlPoint.X) + (t * t * SecondControlPoint.X); + r.Y = (c * c * StartAnchor.Y) + (2 * t * c * FirstControlPoint.Y) + (t * t * SecondControlPoint.Y); - return r; - } + return r; + } - /// - /// Calculates the length of this bezier curve. - /// - /// The precision. - /// Length of the curve. - /// The precision gets better when the - /// value gets smaller. - public float CalculateLength(float precision) - { - float length = 0.0f; - Vector2 old = CalculatePoint(0.0f); + /// + /// Calculates the length of this bezier curve. + /// + /// The precision. + /// Length of the curve. + /// The precision gets better when the + /// value gets smaller. + public float CalculateLength(float precision) + { + float length = 0.0f; + Vector2 old = CalculatePoint(0.0f); - for (float i = precision; i < (1.0f + precision); i += precision) - { - Vector2 n = CalculatePoint(i); - length += (n - old).Length; - old = n; - } + for (float i = precision; i < (1.0f + precision); i += precision) + { + Vector2 n = CalculatePoint(i); + length += (n - old).Length; + old = n; + } - return length; - } + return length; + } - #endregion - } + #endregion + } } diff --git a/Source/OpenTK/Math/BezierCurveQuadric.cs b/Source/OpenTK/Math/BezierCurveQuadric.cs index 941769b6..500b7fff 100644 --- a/Source/OpenTK/Math/BezierCurveQuadric.cs +++ b/Source/OpenTK/Math/BezierCurveQuadric.cs @@ -14,138 +14,138 @@ using System.Text; namespace OpenTK { - /// - /// Represents a quadric bezier curve with two anchor and one control point. - /// - [Serializable] - public struct BezierCurveQuadric - { - #region Fields + /// + /// Represents a quadric bezier curve with two anchor and one control point. + /// + [Serializable] + public struct BezierCurveQuadric + { + #region Fields - /// - /// Start anchor point. - /// - public Vector2 StartAnchor; + /// + /// Start anchor point. + /// + public Vector2 StartAnchor; - /// - /// End anchor point. - /// - public Vector2 EndAnchor; + /// + /// End anchor point. + /// + public Vector2 EndAnchor; - /// - /// Control point, controls the direction of both endings of the curve. - /// - public Vector2 ControlPoint; + /// + /// Control point, controls the direction of both endings of the curve. + /// + public Vector2 ControlPoint; - /// - /// The parallel value. - /// - /// This value defines whether the curve should be calculated as a - /// parallel curve to the original bezier curve. A value of 0.0f represents - /// the original curve, 5.0f i.e. stands for a curve that has always a distance - /// of 5.f to the orignal curve at any point. - public float Parallel; + /// + /// The parallel value. + /// + /// This value defines whether the curve should be calculated as a + /// parallel curve to the original bezier curve. A value of 0.0f represents + /// the original curve, 5.0f i.e. stands for a curve that has always a distance + /// of 5.f to the orignal curve at any point. + public float Parallel; - #endregion + #endregion - #region Constructors + #region Constructors - /// - /// Constructs a new . - /// - /// The start anchor. - /// The end anchor. - /// The control point. - public BezierCurveQuadric(Vector2 startAnchor, Vector2 endAnchor, Vector2 controlPoint) - { - this.StartAnchor = startAnchor; - this.EndAnchor = endAnchor; - this.ControlPoint = controlPoint; - this.Parallel = 0.0f; - } + /// + /// Constructs a new . + /// + /// The start anchor. + /// The end anchor. + /// The control point. + public BezierCurveQuadric(Vector2 startAnchor, Vector2 endAnchor, Vector2 controlPoint) + { + this.StartAnchor = startAnchor; + this.EndAnchor = endAnchor; + this.ControlPoint = controlPoint; + this.Parallel = 0.0f; + } - /// - /// Constructs a new . - /// - /// The parallel value. - /// The start anchor. - /// The end anchor. - /// The control point. - public BezierCurveQuadric(float parallel, Vector2 startAnchor, Vector2 endAnchor, Vector2 controlPoint) - { - this.Parallel = parallel; - this.StartAnchor = startAnchor; - this.EndAnchor = endAnchor; - this.ControlPoint = controlPoint; - } + /// + /// Constructs a new . + /// + /// The parallel value. + /// The start anchor. + /// The end anchor. + /// The control point. + public BezierCurveQuadric(float parallel, Vector2 startAnchor, Vector2 endAnchor, Vector2 controlPoint) + { + this.Parallel = parallel; + this.StartAnchor = startAnchor; + this.EndAnchor = endAnchor; + this.ControlPoint = controlPoint; + } - #endregion + #endregion - #region Functions + #region Functions - /// - /// Calculates the point with the specified t. - /// - /// The t value, between 0.0f and 1.0f. - /// Resulting point. - public Vector2 CalculatePoint(float t) - { - Vector2 r = new Vector2(); - float c = 1.0f - t; + /// + /// Calculates the point with the specified t. + /// + /// The t value, between 0.0f and 1.0f. + /// Resulting point. + public Vector2 CalculatePoint(float t) + { + Vector2 r = new Vector2(); + float c = 1.0f - t; - r.X = (c * c * StartAnchor.X) + (2 * t * c * ControlPoint.X) + (t * t * EndAnchor.X); - r.Y = (c * c * StartAnchor.Y) + (2 * t * c * ControlPoint.Y) + (t * t * EndAnchor.Y); + r.X = (c * c * StartAnchor.X) + (2 * t * c * ControlPoint.X) + (t * t * EndAnchor.X); + r.Y = (c * c * StartAnchor.Y) + (2 * t * c * ControlPoint.Y) + (t * t * EndAnchor.Y); - if (Parallel == 0.0f) - return r; + if (Parallel == 0.0f) + return r; - Vector2 perpendicular = new Vector2(); + Vector2 perpendicular = new Vector2(); - if (t == 0.0f) - perpendicular = ControlPoint - StartAnchor; - else - perpendicular = r - CalculatePointOfDerivative(t); + if (t == 0.0f) + perpendicular = ControlPoint - StartAnchor; + else + perpendicular = r - CalculatePointOfDerivative(t); - return r + Vector2.Normalize(perpendicular).PerpendicularRight * Parallel; - } + return r + Vector2.Normalize(perpendicular).PerpendicularRight * Parallel; + } - /// - /// Calculates the point with the specified t of the derivative of this function. - /// - /// The t, value between 0.0f and 1.0f. - /// Resulting point. - private Vector2 CalculatePointOfDerivative(float t) - { - Vector2 r = new Vector2(); + /// + /// Calculates the point with the specified t of the derivative of this function. + /// + /// The t, value between 0.0f and 1.0f. + /// Resulting point. + private Vector2 CalculatePointOfDerivative(float t) + { + Vector2 r = new Vector2(); - r.X = (1.0f - t) * StartAnchor.X + t * ControlPoint.X; - r.Y = (1.0f - t) * StartAnchor.Y + t * ControlPoint.Y; + r.X = (1.0f - t) * StartAnchor.X + t * ControlPoint.X; + r.Y = (1.0f - t) * StartAnchor.Y + t * ControlPoint.Y; - return r; - } + return r; + } - /// - /// Calculates the length of this bezier curve. - /// - /// The precision. - /// Length of curve. - /// The precision gets better when the - /// value gets smaller. - public float CalculateLength(float precision) - { - float length = 0.0f; - Vector2 old = CalculatePoint(0.0f); + /// + /// Calculates the length of this bezier curve. + /// + /// The precision. + /// Length of curve. + /// The precision gets better when the + /// value gets smaller. + public float CalculateLength(float precision) + { + float length = 0.0f; + Vector2 old = CalculatePoint(0.0f); - for (float i = precision; i < (1.0f + precision); i += precision) - { - Vector2 n = CalculatePoint(i); - length += (n - old).Length; - old = n; - } + for (float i = precision; i < (1.0f + precision); i += precision) + { + Vector2 n = CalculatePoint(i); + length += (n - old).Length; + old = n; + } - return length; - } + return length; + } - #endregion - } + #endregion + } } diff --git a/Source/OpenTK/Math/Functions.cs b/Source/OpenTK/Math/Functions.cs index 1e7ebfb4..00dd9396 100644 --- a/Source/OpenTK/Math/Functions.cs +++ b/Source/OpenTK/Math/Functions.cs @@ -48,31 +48,30 @@ namespace OpenTK #endregion + /// /// 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; + } + /// - /// 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; - } - - /// - /// 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)); - } + /// 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)); + } /// /// Returns an approximation of the inverse square root of left number. diff --git a/Source/OpenTK/Math/Half.cs b/Source/OpenTK/Math/Half.cs index dc8b3838..30e2caab 100644 --- a/Source/OpenTK/Math/Half.cs +++ b/Source/OpenTK/Math/Half.cs @@ -230,8 +230,8 @@ namespace OpenTK if ((mantissa & 0x00800000) == 1) { - mantissa = 0; // overflow in significand, - exponent += 1; // adjust exponent + mantissa = 0; // overflow in significand, + exponent += 1; // adjust exponent } // exponent overflow diff --git a/Source/OpenTK/Math/Matrix4.cs b/Source/OpenTK/Math/Matrix4.cs index ab975154..cc97b02b 100644 --- a/Source/OpenTK/Math/Matrix4.cs +++ b/Source/OpenTK/Math/Matrix4.cs @@ -36,46 +36,46 @@ namespace OpenTK { #region Fields - /// - /// Top row of the matrix - /// - public Vector4 Row0; - /// - /// 2nd row of the matrix - /// - public Vector4 Row1; - /// - /// 3rd row of the matrix - /// - public Vector4 Row2; - /// - /// Bottom row of the matrix - /// - public Vector4 Row3; + /// + /// Top row of the matrix + /// + public Vector4 Row0; + /// + /// 2nd row of the matrix + /// + public Vector4 Row1; + /// + /// 3rd row of the matrix + /// + public Vector4 Row2; + /// + /// Bottom row of the matrix + /// + public Vector4 Row3; - /// - /// The identity matrix - /// - public static Matrix4 Identity = new Matrix4(Vector4.UnitX, Vector4.UnitY, Vector4.UnitZ, Vector4.UnitW); + /// + /// The identity matrix + /// + public static Matrix4 Identity = new Matrix4(Vector4.UnitX, Vector4.UnitY, Vector4.UnitZ, Vector4.UnitW); #endregion #region Constructors - /// + /// /// Constructs a new instance. - /// + /// /// Top row of the matrix /// Second row of the matrix /// Third row of the matrix /// Bottom row of the matrix - public Matrix4(Vector4 row0, Vector4 row1, Vector4 row2, Vector4 row3) - { - Row0 = row0; - Row1 = row1; - Row2 = row2; - Row3 = row3; - } + public Matrix4(Vector4 row0, Vector4 row1, Vector4 row2, Vector4 row3) + { + Row0 = row0; + Row1 = row1; + Row2 = row2; + Row3 = row3; + } /// /// Constructs a new instance. @@ -271,9 +271,9 @@ namespace OpenTK #endregion #region Static - - #region CreateFromAxisAngle - + + #region CreateFromAxisAngle + /// /// Build a rotation matrix from the specified axis/angle rotation. /// @@ -289,11 +289,11 @@ namespace OpenTK axis.Normalize(); result = new Matrix4(t * axis.X * axis.X + cos, t * axis.X * axis.Y - sin * axis.Z, t * axis.X * axis.Z + sin * axis.Y, 0.0f, - t * axis.X * axis.Y + sin * axis.Z, t * axis.Y * axis.Y + cos, t * axis.Y * axis.Z - sin * axis.X, 0.0f, - t * axis.X * axis.Z - sin * axis.Y, t * axis.Y * axis.Z + sin * axis.X, t * axis.Z * axis.Z + cos, 0.0f, - 0, 0, 0, 1); + t * axis.X * axis.Y + sin * axis.Z, t * axis.Y * axis.Y + cos, t * axis.Y * axis.Z - sin * axis.X, 0.0f, + t * axis.X * axis.Z - sin * axis.Y, t * axis.Y * axis.Z + sin * axis.X, t * axis.Z * axis.Z + cos, 0.0f, + 0, 0, 0, 1); } - + /// /// Build a rotation matrix from the specified axis/angle rotation. /// @@ -303,11 +303,11 @@ namespace OpenTK public static Matrix4 CreateFromAxisAngle(Vector3 axis, float angle) { Matrix4 result; - CreateFromAxisAngle(axis, angle, out result); - return result; + CreateFromAxisAngle(axis, angle, out result); + return result; } - - #endregion + + #endregion #region CreateTranslation @@ -443,9 +443,9 @@ namespace OpenTK } #endregion - - #region CreatePerspectiveFieldOfView - + + #region CreatePerspectiveFieldOfView + /// /// Creates a perspective projection matrix. /// @@ -466,17 +466,17 @@ namespace OpenTK /// public static void CreatePerspectiveFieldOfView(float fovy, float aspect, float zNear, float zFar, out Matrix4 result) { - if (fovy <= 0 || fovy > Math.PI) - throw new ArgumentOutOfRangeException("fovy"); - if (aspect <= 0) - throw new ArgumentOutOfRangeException("aspect"); - if (zNear <= 0) - throw new ArgumentOutOfRangeException("zNear"); - if (zFar <= 0) - throw new ArgumentOutOfRangeException("zFar"); - if (zNear >= zFar) - throw new ArgumentOutOfRangeException("zNear"); - + if (fovy <= 0 || fovy > Math.PI) + throw new ArgumentOutOfRangeException("fovy"); + if (aspect <= 0) + throw new ArgumentOutOfRangeException("aspect"); + if (zNear <= 0) + throw new ArgumentOutOfRangeException("zNear"); + if (zFar <= 0) + throw new ArgumentOutOfRangeException("zFar"); + if (zNear >= zFar) + throw new ArgumentOutOfRangeException("zNear"); + float yMax = zNear * (float)System.Math.Tan(0.5f * fovy); float yMin = -yMax; float xMin = yMin * aspect; @@ -484,7 +484,7 @@ namespace OpenTK CreatePerspectiveOffCenter(xMin, xMax, yMin, yMax, zNear, zFar, out result); } - + /// /// Creates a perspective projection matrix. /// @@ -505,15 +505,15 @@ namespace OpenTK /// public static Matrix4 CreatePerspectiveFieldOfView(float fovy, float aspect, float zNear, float zFar) { - Matrix4 result; - CreatePerspectiveFieldOfView(fovy, aspect, zNear, zFar, out result); - return result; + Matrix4 result; + CreatePerspectiveFieldOfView(fovy, aspect, zNear, zFar, out result); + return result; } - - #endregion - - #region CreatePerspectiveOffCenter - + + #endregion + + #region CreatePerspectiveOffCenter + /// /// Creates an perspective projection matrix. /// @@ -534,26 +534,26 @@ namespace OpenTK /// public static void CreatePerspectiveOffCenter(float left, float right, float bottom, float top, float zNear, float zFar, out Matrix4 result) { - if (zNear <= 0) - throw new ArgumentOutOfRangeException("zNear"); - if (zFar <= 0) - throw new ArgumentOutOfRangeException("zFar"); - if (zNear >= zFar) - throw new ArgumentOutOfRangeException("zNear"); - - float x = (2.0f * zNear) / (right - left); - float y = (2.0f * zNear) / (top - bottom); - float a = (right + left) / (right - left); - float b = (top + bottom) / (top - bottom); - float c = -(zFar + zNear) / (zFar - zNear); - float d = -(2.0f * zFar * zNear) / (zFar - zNear); - + if (zNear <= 0) + throw new ArgumentOutOfRangeException("zNear"); + if (zFar <= 0) + throw new ArgumentOutOfRangeException("zFar"); + if (zNear >= zFar) + throw new ArgumentOutOfRangeException("zNear"); + + float x = (2.0f * zNear) / (right - left); + float y = (2.0f * zNear) / (top - bottom); + float a = (right + left) / (right - left); + float b = (top + bottom) / (top - bottom); + float c = -(zFar + zNear) / (zFar - zNear); + float d = -(2.0f * zFar * zNear) / (zFar - zNear); + result = new Matrix4(x, 0, 0, 0, 0, y, 0, 0, a, b, c, -1, - 0, 0, d, 0); + 0, 0, d, 0); } - + /// /// Creates an perspective projection matrix. /// @@ -574,12 +574,12 @@ namespace OpenTK /// public static Matrix4 CreatePerspectiveOffCenter(float left, float right, float bottom, float top, float zNear, float zFar) { - Matrix4 result; - CreatePerspectiveOffCenter(left, right, bottom, top, zNear, zFar, out result); - return result; + Matrix4 result; + CreatePerspectiveOffCenter(left, right, bottom, top, zNear, zFar, out result); + return result; } - - #endregion + + #endregion #region Obsolete Functions @@ -832,35 +832,35 @@ namespace OpenTK public static Matrix4 Mult(Matrix4 left, Matrix4 right) { Matrix4 result; - Mult(ref left, ref right, out result); - return result; + Mult(ref left, ref right, out result); + return result; } - /// - /// Multiplies two instances. - /// + /// + /// Multiplies two instances. + /// /// The left operand of the multiplication. /// The right operand of the multiplication. /// A new instance that is the result of the multiplication public static void Mult(ref Matrix4 left, ref Matrix4 right, out Matrix4 result) { - result = new Matrix4( - left.M11 * right.M11 + left.M12 * right.M21 + left.M13 * right.M31 + left.M14 * right.M41, - left.M11 * right.M12 + left.M12 * right.M22 + left.M13 * right.M32 + left.M14 * right.M42, - left.M11 * right.M13 + left.M12 * right.M23 + left.M13 * right.M33 + left.M14 * right.M43, - left.M11 * right.M14 + left.M12 * right.M24 + left.M13 * right.M34 + left.M14 * right.M44, - left.M21 * right.M11 + left.M22 * right.M21 + left.M23 * right.M31 + left.M24 * right.M41, - left.M21 * right.M12 + left.M22 * right.M22 + left.M23 * right.M32 + left.M24 * right.M42, - left.M21 * right.M13 + left.M22 * right.M23 + left.M23 * right.M33 + left.M24 * right.M43, - left.M21 * right.M14 + left.M22 * right.M24 + left.M23 * right.M34 + left.M24 * right.M44, - left.M31 * right.M11 + left.M32 * right.M21 + left.M33 * right.M31 + left.M34 * right.M41, - left.M31 * right.M12 + left.M32 * right.M22 + left.M33 * right.M32 + left.M34 * right.M42, - left.M31 * right.M13 + left.M32 * right.M23 + left.M33 * right.M33 + left.M34 * right.M43, - left.M31 * right.M14 + left.M32 * right.M24 + left.M33 * right.M34 + left.M34 * right.M44, - left.M41 * right.M11 + left.M42 * right.M21 + left.M43 * right.M31 + left.M44 * right.M41, - left.M41 * right.M12 + left.M42 * right.M22 + left.M43 * right.M32 + left.M44 * right.M42, - left.M41 * right.M13 + left.M42 * right.M23 + left.M43 * right.M33 + left.M44 * right.M43, - left.M41 * right.M14 + left.M42 * right.M24 + left.M43 * right.M34 + left.M44 * right.M44); + result = new Matrix4( + left.M11 * right.M11 + left.M12 * right.M21 + left.M13 * right.M31 + left.M14 * right.M41, + left.M11 * right.M12 + left.M12 * right.M22 + left.M13 * right.M32 + left.M14 * right.M42, + left.M11 * right.M13 + left.M12 * right.M23 + left.M13 * right.M33 + left.M14 * right.M43, + left.M11 * right.M14 + left.M12 * right.M24 + left.M13 * right.M34 + left.M14 * right.M44, + left.M21 * right.M11 + left.M22 * right.M21 + left.M23 * right.M31 + left.M24 * right.M41, + left.M21 * right.M12 + left.M22 * right.M22 + left.M23 * right.M32 + left.M24 * right.M42, + left.M21 * right.M13 + left.M22 * right.M23 + left.M23 * right.M33 + left.M24 * right.M43, + left.M21 * right.M14 + left.M22 * right.M24 + left.M23 * right.M34 + left.M24 * right.M44, + left.M31 * right.M11 + left.M32 * right.M21 + left.M33 * right.M31 + left.M34 * right.M41, + left.M31 * right.M12 + left.M32 * right.M22 + left.M33 * right.M32 + left.M34 * right.M42, + left.M31 * right.M13 + left.M32 * right.M23 + left.M33 * right.M33 + left.M34 * right.M43, + left.M31 * right.M14 + left.M32 * right.M24 + left.M33 * right.M34 + left.M34 * right.M44, + left.M41 * right.M11 + left.M42 * right.M21 + left.M43 * right.M31 + left.M44 * right.M41, + left.M41 * right.M12 + left.M42 * right.M22 + left.M43 * right.M32 + left.M44 * right.M42, + left.M41 * right.M13 + left.M42 * right.M23 + left.M43 * right.M33 + left.M44 * right.M43, + left.M41 * right.M14 + left.M42 * right.M24 + left.M43 * right.M34 + left.M44 * right.M44); } #endregion @@ -881,9 +881,9 @@ namespace OpenTK // convert the matrix to an array for easy looping float[,] inverse = {{mat.Row0.X, mat.Row0.Y, mat.Row0.Z, mat.Row0.W}, - {mat.Row1.X, mat.Row1.Y, mat.Row1.Z, mat.Row1.W}, - {mat.Row2.X, mat.Row2.Y, mat.Row2.Z, mat.Row2.W}, - {mat.Row3.X, mat.Row3.Y, mat.Row3.Z, mat.Row3.W} }; + {mat.Row1.X, mat.Row1.Y, mat.Row1.Z, mat.Row1.W}, + {mat.Row2.X, mat.Row2.Y, mat.Row2.Z, mat.Row2.W}, + {mat.Row3.X, mat.Row3.Y, mat.Row3.Z, mat.Row3.W} }; int icol = 0; int irow = 0; for (int i = 0; i < 4; i++) diff --git a/Source/OpenTK/Math/Matrix4d.cs b/Source/OpenTK/Math/Matrix4d.cs index 3b3fcbab..86b35b99 100644 --- a/Source/OpenTK/Math/Matrix4d.cs +++ b/Source/OpenTK/Math/Matrix4d.cs @@ -36,46 +36,46 @@ namespace OpenTK { #region Fields - /// - /// Top row of the matrix - /// + /// + /// Top row of the matrix + /// public Vector4d Row0; - /// - /// 2nd row of the matrix - /// + /// + /// 2nd row of the matrix + /// public Vector4d Row1; - /// - /// 3rd row of the matrix - /// + /// + /// 3rd row of the matrix + /// public Vector4d Row2; - /// - /// Bottom row of the matrix - /// + /// + /// Bottom row of the matrix + /// public Vector4d Row3; - /// - /// The identity matrix - /// - public static Matrix4d Identity = new Matrix4d(Vector4d .UnitX, Vector4d .UnitY, Vector4d .UnitZ, Vector4d .UnitW); + /// + /// The identity matrix + /// + public static Matrix4d Identity = new Matrix4d(Vector4d .UnitX, Vector4d .UnitY, Vector4d .UnitZ, Vector4d .UnitW); #endregion #region Constructors - /// - /// Constructs a new instance. - /// - /// Top row of the matrix - /// Second row of the matrix - /// Third row of the matrix - /// Bottom row of the matrix - public Matrix4d(Vector4d row0, Vector4d row1, Vector4d row2, Vector4d row3) - { - Row0 = row0; - Row1 = row1; - Row2 = row2; - Row3 = row3; - } + /// + /// Constructs a new instance. + /// + /// Top row of the matrix + /// Second row of the matrix + /// Third row of the matrix + /// Bottom row of the matrix + public Matrix4d(Vector4d row0, Vector4d row1, Vector4d row2, Vector4d row3) + { + Row0 = row0; + Row1 = row1; + Row2 = row2; + Row3 = row3; + } /// /// Constructs a new instance. @@ -680,35 +680,35 @@ namespace OpenTK public static Matrix4d Mult(Matrix4d left, Matrix4d right) { Matrix4d result; - Mult(ref left, ref right, out result); - return result; + Mult(ref left, ref right, out result); + return result; } - /// - /// Multiplies two instances. - /// + /// + /// Multiplies two instances. + /// /// The left operand of the multiplication. /// The right operand of the multiplication. /// A new instance that is the result of the multiplication public static void Mult(ref Matrix4d left, ref Matrix4d right, out Matrix4d result) { - result = new Matrix4d(); - result.M11 = left.M11 * right.M11 + left.M12 * right.M21 + left.M13 * right.M31 + left.M14 * right.M41; - result.M12 = left.M11 * right.M12 + left.M12 * right.M22 + left.M13 * right.M32 + left.M14 * right.M42; - result.M13 = left.M11 * right.M13 + left.M12 * right.M23 + left.M13 * right.M33 + left.M14 * right.M43; - result.M14 = left.M11 * right.M14 + left.M12 * right.M24 + left.M13 * right.M34 + left.M14 * right.M44; - result.M21 = left.M21 * right.M11 + left.M22 * right.M21 + left.M23 * right.M31 + left.M24 * right.M41; - result.M22 = left.M21 * right.M12 + left.M22 * right.M22 + left.M23 * right.M32 + left.M24 * right.M42; - result.M23 = left.M21 * right.M13 + left.M22 * right.M23 + left.M23 * right.M33 + left.M24 * right.M43; - result.M24 = left.M21 * right.M14 + left.M22 * right.M24 + left.M23 * right.M34 + left.M24 * right.M44; - result.M31 = left.M31 * right.M11 + left.M32 * right.M21 + left.M33 * right.M31 + left.M34 * right.M41; - result.M32 = left.M31 * right.M12 + left.M32 * right.M22 + left.M33 * right.M32 + left.M34 * right.M42; - result.M33 = left.M31 * right.M13 + left.M32 * right.M23 + left.M33 * right.M33 + left.M34 * right.M43; - result.M34 = left.M31 * right.M14 + left.M32 * right.M24 + left.M33 * right.M34 + left.M34 * right.M44; - result.M41 = left.M41 * right.M11 + left.M42 * right.M21 + left.M43 * right.M31 + left.M44 * right.M41; - result.M42 = left.M41 * right.M12 + left.M42 * right.M22 + left.M43 * right.M32 + left.M44 * right.M42; - result.M43 = left.M41 * right.M13 + left.M42 * right.M23 + left.M43 * right.M33 + left.M44 * right.M43; - result.M44 = left.M41 * right.M14 + left.M42 * right.M24 + left.M43 * right.M34 + left.M44 * right.M44; + result = new Matrix4d(); + result.M11 = left.M11 * right.M11 + left.M12 * right.M21 + left.M13 * right.M31 + left.M14 * right.M41; + result.M12 = left.M11 * right.M12 + left.M12 * right.M22 + left.M13 * right.M32 + left.M14 * right.M42; + result.M13 = left.M11 * right.M13 + left.M12 * right.M23 + left.M13 * right.M33 + left.M14 * right.M43; + result.M14 = left.M11 * right.M14 + left.M12 * right.M24 + left.M13 * right.M34 + left.M14 * right.M44; + result.M21 = left.M21 * right.M11 + left.M22 * right.M21 + left.M23 * right.M31 + left.M24 * right.M41; + result.M22 = left.M21 * right.M12 + left.M22 * right.M22 + left.M23 * right.M32 + left.M24 * right.M42; + result.M23 = left.M21 * right.M13 + left.M22 * right.M23 + left.M23 * right.M33 + left.M24 * right.M43; + result.M24 = left.M21 * right.M14 + left.M22 * right.M24 + left.M23 * right.M34 + left.M24 * right.M44; + result.M31 = left.M31 * right.M11 + left.M32 * right.M21 + left.M33 * right.M31 + left.M34 * right.M41; + result.M32 = left.M31 * right.M12 + left.M32 * right.M22 + left.M33 * right.M32 + left.M34 * right.M42; + result.M33 = left.M31 * right.M13 + left.M32 * right.M23 + left.M33 * right.M33 + left.M34 * right.M43; + result.M34 = left.M31 * right.M14 + left.M32 * right.M24 + left.M33 * right.M34 + left.M34 * right.M44; + result.M41 = left.M41 * right.M11 + left.M42 * right.M21 + left.M43 * right.M31 + left.M44 * right.M41; + result.M42 = left.M41 * right.M12 + left.M42 * right.M22 + left.M43 * right.M32 + left.M44 * right.M42; + result.M43 = left.M41 * right.M13 + left.M42 * right.M23 + left.M43 * right.M33 + left.M44 * right.M43; + result.M44 = left.M41 * right.M14 + left.M42 * right.M24 + left.M43 * right.M34 + left.M44 * right.M44; } #endregion @@ -729,9 +729,9 @@ namespace OpenTK // convert the matrix to an array for easy looping double[,] inverse = {{mat.Row0.X, mat.Row0.Y, mat.Row0.Z, mat.Row0.W}, - {mat.Row1.X, mat.Row1.Y, mat.Row1.Z, mat.Row1.W}, - {mat.Row2.X, mat.Row2.Y, mat.Row2.Z, mat.Row2.W}, - {mat.Row3.X, mat.Row3.Y, mat.Row3.Z, mat.Row3.W} }; + {mat.Row1.X, mat.Row1.Y, mat.Row1.Z, mat.Row1.W}, + {mat.Row2.X, mat.Row2.Y, mat.Row2.Z, mat.Row2.W}, + {mat.Row3.X, mat.Row3.Y, mat.Row3.Z, mat.Row3.W} }; int icol = 0; int irow = 0; for (int i = 0; i < 4; i++) diff --git a/Source/OpenTK/Math/Vector2.cs b/Source/OpenTK/Math/Vector2.cs index 84b72efc..6f005891 100644 --- a/Source/OpenTK/Math/Vector2.cs +++ b/Source/OpenTK/Math/Vector2.cs @@ -57,8 +57,8 @@ namespace OpenTK /// The y coordinate of the net Vector2. public Vector2(float x, float y) { - X = x; - Y = y; + X = x; + Y = y; } /// @@ -176,10 +176,10 @@ namespace OpenTK /// public float Length { - get - { - return (float)System.Math.Sqrt(X * X + Y * Y); - } + get + { + return (float)System.Math.Sqrt(X * X + Y * Y); + } } #endregion @@ -197,10 +197,10 @@ namespace OpenTK /// public float LengthFast { - get - { - return 1.0f /OpenTK.Functions.InverseSqrtFast(X * X + Y * Y); - } + get + { + return 1.0f /OpenTK.Functions.InverseSqrtFast(X * X + Y * Y); + } } #endregion @@ -218,43 +218,43 @@ namespace OpenTK /// public float LengthSquared { - get - { - return X * X + Y * Y; - } + get + { + return X * X + Y * Y; + } } - #endregion + #endregion - #region public Vector2 PerpendicularRight + #region public Vector2 PerpendicularRight - /// - /// Gets the perpendicular vector on the right side of this vector. - /// - public Vector2 PerpendicularRight - { - get - { - return new Vector2(Y, -X); - } - } + /// + /// Gets the perpendicular vector on the right side of this vector. + /// + public Vector2 PerpendicularRight + { + get + { + return new Vector2(Y, -X); + } + } - #endregion + #endregion - #region public Vector2 PerpendicularLeft + #region public Vector2 PerpendicularLeft - /// - /// Gets the perpendicular vector on the left side of this vector. - /// - public Vector2 PerpendicularLeft - { - get - { - return new Vector2(-Y, X); - } - } + /// + /// Gets the perpendicular vector on the left side of this vector. + /// + public Vector2 PerpendicularLeft + { + get + { + return new Vector2(-Y, X); + } + } - #endregion + #endregion #region public void Normalize() @@ -263,9 +263,9 @@ namespace OpenTK /// public void Normalize() { - float scale = 1.0f / this.Length; - X *= scale; - Y *= scale; + float scale = 1.0f / this.Length; + X *= scale; + Y *= scale; } #endregion @@ -277,9 +277,9 @@ namespace OpenTK /// public void NormalizeFast() { - float scale = Functions.InverseSqrtFast(X * X + Y * Y); - X *= scale; - Y *= scale; + float scale = Functions.InverseSqrtFast(X * X + Y * Y); + X *= scale; + Y *= scale; } #endregion @@ -293,8 +293,8 @@ namespace OpenTK /// The scale of the Y component. public void Scale(float sx, float sy) { - this.X = X * sx; - this.Y = Y * sy; + this.X = X * sx; + this.Y = Y * sy; } /// Scales this instance by the given parameter. @@ -751,12 +751,12 @@ namespace OpenTK /// Left operand. /// Right operand. /// Result of addition. - public static Vector2 operator +(Vector2 left, Vector2 right) - { - left.X += right.X; - left.Y += right.Y; - return left; - } + public static Vector2 operator +(Vector2 left, Vector2 right) + { + left.X += right.X; + left.Y += right.Y; + return left; + } /// /// Subtracts the specified instances. @@ -764,24 +764,24 @@ namespace OpenTK /// Left operand. /// Right operand. /// Result of subtraction. - public static Vector2 operator -(Vector2 left, Vector2 right) - { - left.X -= right.X; - left.Y -= right.Y; - return left; - } + public static Vector2 operator -(Vector2 left, Vector2 right) + { + left.X -= right.X; + left.Y -= right.Y; + return left; + } /// /// Negates the specified instance. /// /// Operand. /// Result of negation. - public static Vector2 operator -(Vector2 vec) - { - vec.X = -vec.X; - vec.Y = -vec.Y; - return vec; - } + public static Vector2 operator -(Vector2 vec) + { + vec.X = -vec.X; + vec.Y = -vec.Y; + return vec; + } /// /// Multiplies the specified instance by a scalar. @@ -789,12 +789,12 @@ namespace OpenTK /// Left operand. /// Right operand. /// Result of multiplication. - public static Vector2 operator *(Vector2 vec, float scale) - { + public static Vector2 operator *(Vector2 vec, float scale) + { vec.X *= scale; vec.Y *= scale; - return vec; - } + return vec; + } /// /// Multiplies the specified instance by a scalar. @@ -803,11 +803,11 @@ namespace OpenTK /// Right operand. /// Result of multiplication. public static Vector2 operator *(float scale, Vector2 vec) - { + { vec.X *= scale; vec.Y *= scale; - return vec; - } + return vec; + } /// /// Divides the specified instance by a scalar. @@ -815,13 +815,13 @@ namespace OpenTK /// Left operand /// Right operand /// Result of the division. - public static Vector2 operator /(Vector2 vec, float scale) - { + public static Vector2 operator /(Vector2 vec, float scale) + { float mult = 1.0f / scale; - vec.X *= mult; - vec.Y *= mult; - return vec; - } + vec.X *= mult; + vec.Y *= mult; + return vec; + } /// /// Compares the specified instances for equality. diff --git a/Source/OpenTK/Math/Vector4.cs b/Source/OpenTK/Math/Vector4.cs index 06d4472c..59ea2c10 100644 --- a/Source/OpenTK/Math/Vector4.cs +++ b/Source/OpenTK/Math/Vector4.cs @@ -60,7 +60,7 @@ namespace OpenTK /// /// Defines a unit-length Vector4 that points towards the X-axis. /// - public static Vector4 UnitX = new Vector4(1, 0, 0, 0); + public static Vector4 UnitX = new Vector4(1, 0, 0, 0); /// /// Defines a unit-length Vector4 that points towards the Y-axis. @@ -70,17 +70,17 @@ namespace OpenTK /// /// Defines a unit-length Vector4 that points towards the Z-axis. /// - public static Vector4 UnitZ = new Vector4(0, 0, 1, 0); + public static Vector4 UnitZ = new Vector4(0, 0, 1, 0); /// /// Defines a unit-length Vector4 that points towards the W-axis. /// - public static Vector4 UnitW = new Vector4(0, 0, 0, 1); + public static Vector4 UnitW = new Vector4(0, 0, 0, 1); /// /// Defines a zero-length Vector4. /// - public static Vector4 Zero = new Vector4(0, 0, 0, 0); + public static Vector4 Zero = new Vector4(0, 0, 0, 0); /// /// Defines an instance with all components set to 1. @@ -849,58 +849,58 @@ namespace OpenTK public static Vector4 operator +(Vector4 left, Vector4 right) { - left.X += right.X; - left.Y += right.Y; - left.Z += right.Z; - left.W += right.W; - return left; + left.X += right.X; + left.Y += right.Y; + left.Z += right.Z; + left.W += right.W; + return left; } public static Vector4 operator -(Vector4 left, Vector4 right) { - left.X -= right.X; - left.Y -= right.Y; - left.Z -= right.Z; - left.W -= right.W; - return left; + left.X -= right.X; + left.Y -= right.Y; + left.Z -= right.Z; + left.W -= right.W; + return left; } - public static Vector4 operator -(Vector4 vec) - { - vec.X = -vec.X; - vec.Y = -vec.Y; - vec.Z = -vec.Z; - vec.W = -vec.W; - return vec; - } + public static Vector4 operator -(Vector4 vec) + { + vec.X = -vec.X; + vec.Y = -vec.Y; + vec.Z = -vec.Z; + vec.W = -vec.W; + return vec; + } - public static Vector4 operator *(Vector4 vec, float f) - { - vec.X *= f; - vec.Y *= f; - vec.Z *= f; - vec.W *= f; - return vec; - } + public static Vector4 operator *(Vector4 vec, float f) + { + vec.X *= f; + vec.Y *= f; + vec.Z *= f; + vec.W *= f; + return vec; + } - public static Vector4 operator *(float f, Vector4 vec) - { - vec.X *= f; - vec.Y *= f; - vec.Z *= f; - vec.W *= f; - return vec; - } + public static Vector4 operator *(float f, Vector4 vec) + { + vec.X *= f; + vec.Y *= f; + vec.Z *= f; + vec.W *= f; + return vec; + } - public static Vector4 operator /(Vector4 vec, float f) - { - float mult = 1.0f / f; - vec.X *= mult; - vec.Y *= mult; - vec.Z *= mult; - vec.W *= mult; - return vec; - } + public static Vector4 operator /(Vector4 vec, float f) + { + float mult = 1.0f / f; + vec.X *= mult; + vec.Y *= mult; + vec.Z *= mult; + vec.W *= mult; + return vec; + } public static bool operator ==(Vector4 left, Vector4 right) { @@ -933,15 +933,15 @@ namespace OpenTK #region public override string ToString() /// - /// Returns a System.String that represents the current Vector4. - /// - /// - public override string ToString() + /// Returns a System.String that represents the current Vector4. + /// + /// + public override string ToString() { return String.Format("({0}, {1}, {2}, {3})", X, Y, Z, W); - } + } - #endregion + #endregion #region public override int GetHashCode()