Replaced tabs with spaces.

This commit is contained in:
the_fiddler 2009-07-17 08:27:25 +00:00
parent a65ed72e72
commit 7726212921
9 changed files with 758 additions and 759 deletions

View file

@ -14,248 +14,248 @@ using System.Text;
namespace OpenTK namespace OpenTK
{ {
/// <summary> /// <summary>
/// Represents a bezier curve with as many points as you want. /// Represents a bezier curve with as many points as you want.
/// </summary> /// </summary>
[Serializable] [Serializable]
public struct BezierCurve public struct BezierCurve
{ {
#region Fields #region Fields
private List<Vector2> points; private List<Vector2> points;
/// <summary> /// <summary>
/// The parallel value. /// The parallel value.
/// </summary> /// </summary>
/// <remarks>This value defines whether the curve should be calculated as a /// <remarks>This value defines whether the curve should be calculated as a
/// parallel curve to the original bezier curve. A value of 0.0f represents /// 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 /// 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.</remarks> /// of 5.0f to the orignal curve at any point.</remarks>
public float Parallel; public float Parallel;
#endregion #endregion
#region Properties #region Properties
/// <summary> /// <summary>
/// Gets the points of this curve. /// Gets the points of this curve.
/// </summary> /// </summary>
/// <remarks>The first point and the last points represent the anchor points.</remarks> /// <remarks>The first point and the last points represent the anchor points.</remarks>
public IList<Vector2> Points public IList<Vector2> Points
{ {
get get
{ {
return points; return points;
} }
} }
#endregion #endregion
#region Constructors #region Constructors
/// <summary> /// <summary>
/// Constructs a new <see cref="BezierCurve"/>. /// Constructs a new <see cref="BezierCurve"/>.
/// </summary> /// </summary>
/// <param name="points">The points.</param> /// <param name="points">The points.</param>
public BezierCurve(IEnumerable<Vector2> points) public BezierCurve(IEnumerable<Vector2> points)
{ {
if (points == null) if (points == null)
throw new ArgumentNullException("points", "Must point to a valid list of Vector2 structures."); throw new ArgumentNullException("points", "Must point to a valid list of Vector2 structures.");
this.points = new List<Vector2>(points); this.points = new List<Vector2>(points);
this.Parallel = 0.0f; this.Parallel = 0.0f;
} }
/// <summary> /// <summary>
/// Constructs a new <see cref="BezierCurve"/>. /// Constructs a new <see cref="BezierCurve"/>.
/// </summary> /// </summary>
/// <param name="points">The points.</param> /// <param name="points">The points.</param>
public BezierCurve(params Vector2[] points) public BezierCurve(params Vector2[] points)
{ {
if (points == null) if (points == null)
throw new ArgumentNullException("points", "Must point to a valid list of Vector2 structures."); throw new ArgumentNullException("points", "Must point to a valid list of Vector2 structures.");
this.points = new List<Vector2>(points); this.points = new List<Vector2>(points);
this.Parallel = 0.0f; this.Parallel = 0.0f;
} }
/// <summary> /// <summary>
/// Constructs a new <see cref="BezierCurve"/>. /// Constructs a new <see cref="BezierCurve"/>.
/// </summary> /// </summary>
/// <param name="parallel">The parallel value.</param> /// <param name="parallel">The parallel value.</param>
/// <param name="points">The points.</param> /// <param name="points">The points.</param>
public BezierCurve(float parallel, params Vector2[] points) public BezierCurve(float parallel, params Vector2[] points)
{ {
if (points == null) if (points == null)
throw new ArgumentNullException("points", "Must point to a valid list of Vector2 structures."); throw new ArgumentNullException("points", "Must point to a valid list of Vector2 structures.");
this.Parallel = parallel; this.Parallel = parallel;
this.points = new List<Vector2>(points); this.points = new List<Vector2>(points);
} }
/// <summary> /// <summary>
/// Constructs a new <see cref="BezierCurve"/>. /// Constructs a new <see cref="BezierCurve"/>.
/// </summary> /// </summary>
/// <param name="parallel">The parallel value.</param> /// <param name="parallel">The parallel value.</param>
/// <param name="points">The points.</param> /// <param name="points">The points.</param>
public BezierCurve(float parallel, IEnumerable<Vector2> points) public BezierCurve(float parallel, IEnumerable<Vector2> points)
{ {
if (points == null) if (points == null)
throw new ArgumentNullException("points", "Must point to a valid list of Vector2 structures."); throw new ArgumentNullException("points", "Must point to a valid list of Vector2 structures.");
this.Parallel = parallel; this.Parallel = parallel;
this.points = new List<Vector2>(points); this.points = new List<Vector2>(points);
} }
#endregion #endregion
#region Functions #region Functions
/// <summary> /// <summary>
/// Calculates the point with the specified t. /// Calculates the point with the specified t.
/// </summary> /// </summary>
/// <param name="t">The t value, between 0.0f and 1.0f.</param> /// <param name="t">The t value, between 0.0f and 1.0f.</param>
/// <returns>Resulting point.</returns> /// <returns>Resulting point.</returns>
public Vector2 CalculatePoint(float t) public Vector2 CalculatePoint(float t)
{ {
return BezierCurve.CalculatePoint(points, t, Parallel); return BezierCurve.CalculatePoint(points, t, Parallel);
} }
/// <summary> /// <summary>
/// Calculates the length of this bezier curve. /// Calculates the length of this bezier curve.
/// </summary> /// </summary>
/// <param name="precision">The precision.</param> /// <param name="precision">The precision.</param>
/// <returns>Length of curve.</returns> /// <returns>Length of curve.</returns>
/// <remarks>The precision gets better as the <paramref name="precision"/> /// <remarks>The precision gets better as the <paramref name="precision"/>
/// value gets smaller.</remarks> /// value gets smaller.</remarks>
public float CalculateLength(float precision) public float CalculateLength(float precision)
{ {
return BezierCurve.CalculateLength(points, precision, Parallel); return BezierCurve.CalculateLength(points, precision, Parallel);
} }
#region Static methods #region Static methods
/// <summary> /// <summary>
/// Calculates the length of the specified bezier curve. /// Calculates the length of the specified bezier curve.
/// </summary> /// </summary>
/// <param name="points">The points.</param> /// <param name="points">The points.</param>
/// <param name="precision">The precision value.</param> /// <param name="precision">The precision value.</param>
/// <returns>The precision gets better as the <paramref name="precision"/> /// <returns>The precision gets better as the <paramref name="precision"/>
/// value gets smaller.</returns> /// value gets smaller.</returns>
public static float CalculateLength(IList<Vector2> points, float precision) public static float CalculateLength(IList<Vector2> points, float precision)
{ {
return BezierCurve.CalculateLength(points, precision, 0.0f); return BezierCurve.CalculateLength(points, precision, 0.0f);
} }
/// <summary> /// <summary>
/// Calculates the length of the specified bezier curve. /// Calculates the length of the specified bezier curve.
/// </summary> /// </summary>
/// <param name="points">The points.</param> /// <param name="points">The points.</param>
/// <param name="precision">The precision value.</param> /// <param name="precision">The precision value.</param>
/// <param name="parallel">The parallel value.</param> /// <param name="parallel">The parallel value.</param>
/// <returns>Length of curve.</returns> /// <returns>Length of curve.</returns>
/// <remarks><para>The precision gets better as the <paramref name="precision"/> /// <remarks><para>The precision gets better as the <paramref name="precision"/>
/// value gets smaller.</para> /// value gets smaller.</para>
/// <para>The <paramref name="parallel"/> parameter defines whether the curve should be calculated as a /// <para>The <paramref name="parallel"/> parameter defines whether the curve should be calculated as a
/// parallel curve to the original bezier curve. A value of 0.0f represents /// 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 /// the original curve, 5.0f represents a curve that has always a distance
/// of 5.0f to the orignal curve.</para></remarks> /// of 5.0f to the orignal curve.</para></remarks>
public static float CalculateLength(IList<Vector2> points, float precision, float parallel) public static float CalculateLength(IList<Vector2> points, float precision, float parallel)
{ {
float length = 0.0f; float length = 0.0f;
Vector2 old = BezierCurve.CalculatePoint(points, 0.0f, parallel); Vector2 old = BezierCurve.CalculatePoint(points, 0.0f, parallel);
for (float i = precision; i < (1.0f + precision); i += precision) for (float i = precision; i < (1.0f + precision); i += precision)
{ {
Vector2 n = CalculatePoint(points, i, parallel); Vector2 n = CalculatePoint(points, i, parallel);
length += (n - old).Length; length += (n - old).Length;
old = n; old = n;
} }
return length; return length;
} }
/// <summary> /// <summary>
/// Calculates the point on the given bezier curve with the specified t parameter. /// Calculates the point on the given bezier curve with the specified t parameter.
/// </summary> /// </summary>
/// <param name="points">The points.</param> /// <param name="points">The points.</param>
/// <param name="t">The t parameter, a value between 0.0f and 1.0f.</param> /// <param name="t">The t parameter, a value between 0.0f and 1.0f.</param>
/// <returns>Resulting point.</returns> /// <returns>Resulting point.</returns>
public static Vector2 CalculatePoint(IList<Vector2> points, float t) public static Vector2 CalculatePoint(IList<Vector2> points, float t)
{ {
return BezierCurve.CalculatePoint(points, t, 0.0f); return BezierCurve.CalculatePoint(points, t, 0.0f);
} }
/// <summary> /// <summary>
/// Calculates the point on the given bezier curve with the specified t parameter. /// Calculates the point on the given bezier curve with the specified t parameter.
/// </summary> /// </summary>
/// <param name="points">The points.</param> /// <param name="points">The points.</param>
/// <param name="t">The t parameter, a value between 0.0f and 1.0f.</param> /// <param name="t">The t parameter, a value between 0.0f and 1.0f.</param>
/// <param name="parallel">The parallel value.</param> /// <param name="parallel">The parallel value.</param>
/// <returns>Resulting point.</returns> /// <returns>Resulting point.</returns>
/// <remarks>The <paramref name="parallel"/> parameter defines whether the curve should be calculated as a /// <remarks>The <paramref name="parallel"/> parameter defines whether the curve should be calculated as a
/// parallel curve to the original bezier curve. A value of 0.0f represents /// 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 /// the original curve, 5.0f represents a curve that has always a distance
/// of 5.0f to the orignal curve.</remarks> /// of 5.0f to the orignal curve.</remarks>
public static Vector2 CalculatePoint(IList<Vector2> points, float t, float parallel) public static Vector2 CalculatePoint(IList<Vector2> points, float t, float parallel)
{ {
Vector2 r = new Vector2(); Vector2 r = new Vector2();
double c = 1.0d - (double)t; double c = 1.0d - (double)t;
float temp; float temp;
int i = 0; int i = 0;
foreach (Vector2 pt in points) foreach (Vector2 pt in points)
{ {
temp = (float)Functions.BinomialCoefficient(points.Count - 1, i) * (float)(System.Math.Pow(t, i) * temp = (float)Functions.BinomialCoefficient(points.Count - 1, i) * (float)(System.Math.Pow(t, i) *
System.Math.Pow(c, (points.Count - 1) - i)); System.Math.Pow(c, (points.Count - 1) - i));
r.X += temp * pt.X; r.X += temp * pt.X;
r.Y += temp * pt.Y; r.Y += temp * pt.Y;
i++; i++;
} }
if (parallel == 0.0f) if (parallel == 0.0f)
return r; return r;
Vector2 perpendicular = new Vector2(); Vector2 perpendicular = new Vector2();
if (t != 0.0f) if (t != 0.0f)
perpendicular = r - BezierCurve.CalculatePointOfDerivative(points, t); perpendicular = r - BezierCurve.CalculatePointOfDerivative(points, t);
else else
perpendicular = points[1] - points[0]; perpendicular = points[1] - points[0];
return r + Vector2.Normalize(perpendicular).PerpendicularRight * parallel; return r + Vector2.Normalize(perpendicular).PerpendicularRight * parallel;
} }
/// <summary> /// <summary>
/// Calculates the point with the specified t of the derivative of the given bezier function. /// Calculates the point with the specified t of the derivative of the given bezier function.
/// </summary> /// </summary>
/// <param name="points">The points.</param> /// <param name="points">The points.</param>
/// <param name="t">The t parameter, value between 0.0f and 1.0f.</param> /// <param name="t">The t parameter, value between 0.0f and 1.0f.</param>
/// <returns>Resulting point.</returns> /// <returns>Resulting point.</returns>
private static Vector2 CalculatePointOfDerivative(IList<Vector2> points, float t) private static Vector2 CalculatePointOfDerivative(IList<Vector2> points, float t)
{ {
Vector2 r = new Vector2(); Vector2 r = new Vector2();
double c = 1.0d - (double)t; double c = 1.0d - (double)t;
float temp; float temp;
int i = 0; int i = 0;
foreach (Vector2 pt in points) foreach (Vector2 pt in points)
{ {
temp = (float)Functions.BinomialCoefficient(points.Count - 2, i) * (float)(System.Math.Pow(t, i) * temp = (float)Functions.BinomialCoefficient(points.Count - 2, i) * (float)(System.Math.Pow(t, i) *
System.Math.Pow(c, (points.Count - 2) - i)); System.Math.Pow(c, (points.Count - 2) - i));
r.X += temp * pt.X; r.X += temp * pt.X;
r.Y += temp * pt.Y; r.Y += temp * pt.Y;
i++; i++;
} }
return r; return r;
} }
#endregion #endregion
#endregion #endregion
} }
} }

View file

@ -14,150 +14,150 @@ using System.Text;
namespace OpenTK namespace OpenTK
{ {
/// <summary> /// <summary>
/// Represents a cubic bezier curve with two anchor and two control points. /// Represents a cubic bezier curve with two anchor and two control points.
/// </summary> /// </summary>
[Serializable] [Serializable]
public struct BezierCurveCubic public struct BezierCurveCubic
{ {
#region Fields #region Fields
/// <summary> /// <summary>
/// Start anchor point. /// Start anchor point.
/// </summary> /// </summary>
public Vector2 StartAnchor; public Vector2 StartAnchor;
/// <summary> /// <summary>
/// End anchor point. /// End anchor point.
/// </summary> /// </summary>
public Vector2 EndAnchor; public Vector2 EndAnchor;
/// <summary> /// <summary>
/// First control point, controls the direction of the curve start. /// First control point, controls the direction of the curve start.
/// </summary> /// </summary>
public Vector2 FirstControlPoint; public Vector2 FirstControlPoint;
/// <summary> /// <summary>
/// Second control point, controls the direction of the curve end. /// Second control point, controls the direction of the curve end.
/// </summary> /// </summary>
public Vector2 SecondControlPoint; public Vector2 SecondControlPoint;
/// <summary> /// <summary>
/// Gets or sets the parallel value. /// Gets or sets the parallel value.
/// </summary> /// </summary>
/// <remarks>This value defines whether the curve should be calculated as a /// <remarks>This value defines whether the curve should be calculated as a
/// parallel curve to the original bezier curve. A value of 0.0f represents /// 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 /// 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.</remarks> /// of 5.f to the orignal curve at any point.</remarks>
public float Parallel; public float Parallel;
#endregion #endregion
#region Constructors #region Constructors
/// <summary> /// <summary>
/// Constructs a new <see cref="BezierCurveCubic"/>. /// Constructs a new <see cref="BezierCurveCubic"/>.
/// </summary> /// </summary>
/// <param name="startAnchor">The start anchor point.</param> /// <param name="startAnchor">The start anchor point.</param>
/// <param name="endAnchor">The end anchor point.</param> /// <param name="endAnchor">The end anchor point.</param>
/// <param name="firstControlPoint">The first control point.</param> /// <param name="firstControlPoint">The first control point.</param>
/// <param name="secondControlPoint">The second control point.</param> /// <param name="secondControlPoint">The second control point.</param>
public BezierCurveCubic(Vector2 startAnchor, Vector2 endAnchor, Vector2 firstControlPoint, Vector2 secondControlPoint) public BezierCurveCubic(Vector2 startAnchor, Vector2 endAnchor, Vector2 firstControlPoint, Vector2 secondControlPoint)
{ {
this.StartAnchor = startAnchor; this.StartAnchor = startAnchor;
this.EndAnchor = endAnchor; this.EndAnchor = endAnchor;
this.FirstControlPoint = firstControlPoint; this.FirstControlPoint = firstControlPoint;
this.SecondControlPoint = secondControlPoint; this.SecondControlPoint = secondControlPoint;
this.Parallel = 0.0f; this.Parallel = 0.0f;
} }
/// <summary> /// <summary>
/// Constructs a new <see cref="BezierCurveCubic"/>. /// Constructs a new <see cref="BezierCurveCubic"/>.
/// </summary> /// </summary>
/// <param name="parallel">The parallel value.</param> /// <param name="parallel">The parallel value.</param>
/// <param name="startAnchor">The start anchor point.</param> /// <param name="startAnchor">The start anchor point.</param>
/// <param name="endAnchor">The end anchor point.</param> /// <param name="endAnchor">The end anchor point.</param>
/// <param name="firstControlPoint">The first control point.</param> /// <param name="firstControlPoint">The first control point.</param>
/// <param name="secondControlPoint">The second control point.</param> /// <param name="secondControlPoint">The second control point.</param>
public BezierCurveCubic(float parallel, Vector2 startAnchor, Vector2 endAnchor, Vector2 firstControlPoint, Vector2 secondControlPoint) public BezierCurveCubic(float parallel, Vector2 startAnchor, Vector2 endAnchor, Vector2 firstControlPoint, Vector2 secondControlPoint)
{ {
this.Parallel = parallel; this.Parallel = parallel;
this.StartAnchor = startAnchor; this.StartAnchor = startAnchor;
this.EndAnchor = endAnchor; this.EndAnchor = endAnchor;
this.FirstControlPoint = firstControlPoint; this.FirstControlPoint = firstControlPoint;
this.SecondControlPoint = secondControlPoint; this.SecondControlPoint = secondControlPoint;
} }
#endregion #endregion
#region Functions #region Functions
/// <summary> /// <summary>
/// Calculates the point with the specified t. /// Calculates the point with the specified t.
/// </summary> /// </summary>
/// <param name="t">The t value, between 0.0f and 1.0f.</param> /// <param name="t">The t value, between 0.0f and 1.0f.</param>
/// <returns>Resulting point.</returns> /// <returns>Resulting point.</returns>
public Vector2 CalculatePoint(float t) public Vector2 CalculatePoint(float t)
{ {
Vector2 r = new Vector2(); Vector2 r = new Vector2();
float c = 1.0f - t; float c = 1.0f - t;
r.X = (StartAnchor.X * c * c * c) + (FirstControlPoint.X * 3 * t * c * c) + (SecondControlPoint.X * 3 * t * t * c) r.X = (StartAnchor.X * c * c * c) + (FirstControlPoint.X * 3 * t * c * c) + (SecondControlPoint.X * 3 * t * t * c)
+ EndAnchor.X * t * t * t; + EndAnchor.X * t * t * t;
r.Y = (StartAnchor.Y * c * c * c) + (FirstControlPoint.Y * 3 * t * c * c) + (SecondControlPoint.Y * 3 * t * t * c) r.Y = (StartAnchor.Y * c * c * c) + (FirstControlPoint.Y * 3 * t * c * c) + (SecondControlPoint.Y * 3 * t * t * c)
+ EndAnchor.Y * t * t * t; + EndAnchor.Y * t * t * t;
if (Parallel == 0.0f) if (Parallel == 0.0f)
return r; return r;
Vector2 perpendicular = new Vector2(); Vector2 perpendicular = new Vector2();
if (t == 0.0f) if (t == 0.0f)
perpendicular = FirstControlPoint - StartAnchor; perpendicular = FirstControlPoint - StartAnchor;
else else
perpendicular = r - CalculatePointOfDerivative(t); perpendicular = r - CalculatePointOfDerivative(t);
return r + Vector2.Normalize(perpendicular).PerpendicularRight * Parallel; return r + Vector2.Normalize(perpendicular).PerpendicularRight * Parallel;
} }
/// <summary> /// <summary>
/// Calculates the point with the specified t of the derivative of this function. /// Calculates the point with the specified t of the derivative of this function.
/// </summary> /// </summary>
/// <param name="t">The t, value between 0.0f and 1.0f.</param> /// <param name="t">The t, value between 0.0f and 1.0f.</param>
/// <returns>Resulting point.</returns> /// <returns>Resulting point.</returns>
private Vector2 CalculatePointOfDerivative(float t) private Vector2 CalculatePointOfDerivative(float t)
{ {
Vector2 r = new Vector2(); Vector2 r = new Vector2();
float c = 1.0f - t; float c = 1.0f - t;
r.X = (c * c * StartAnchor.X) + (2 * t * c * FirstControlPoint.X) + (t * t * SecondControlPoint.X); 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.Y = (c * c * StartAnchor.Y) + (2 * t * c * FirstControlPoint.Y) + (t * t * SecondControlPoint.Y);
return r; return r;
} }
/// <summary> /// <summary>
/// Calculates the length of this bezier curve. /// Calculates the length of this bezier curve.
/// </summary> /// </summary>
/// <param name="precision">The precision.</param> /// <param name="precision">The precision.</param>
/// <returns>Length of the curve.</returns> /// <returns>Length of the curve.</returns>
/// <remarks>The precision gets better when the <paramref name="precision"/> /// <remarks>The precision gets better when the <paramref name="precision"/>
/// value gets smaller.</remarks> /// value gets smaller.</remarks>
public float CalculateLength(float precision) public float CalculateLength(float precision)
{ {
float length = 0.0f; float length = 0.0f;
Vector2 old = CalculatePoint(0.0f); Vector2 old = CalculatePoint(0.0f);
for (float i = precision; i < (1.0f + precision); i += precision) for (float i = precision; i < (1.0f + precision); i += precision)
{ {
Vector2 n = CalculatePoint(i); Vector2 n = CalculatePoint(i);
length += (n - old).Length; length += (n - old).Length;
old = n; old = n;
} }
return length; return length;
} }
#endregion #endregion
} }
} }

View file

@ -14,138 +14,138 @@ using System.Text;
namespace OpenTK namespace OpenTK
{ {
/// <summary> /// <summary>
/// Represents a quadric bezier curve with two anchor and one control point. /// Represents a quadric bezier curve with two anchor and one control point.
/// </summary> /// </summary>
[Serializable] [Serializable]
public struct BezierCurveQuadric public struct BezierCurveQuadric
{ {
#region Fields #region Fields
/// <summary> /// <summary>
/// Start anchor point. /// Start anchor point.
/// </summary> /// </summary>
public Vector2 StartAnchor; public Vector2 StartAnchor;
/// <summary> /// <summary>
/// End anchor point. /// End anchor point.
/// </summary> /// </summary>
public Vector2 EndAnchor; public Vector2 EndAnchor;
/// <summary> /// <summary>
/// Control point, controls the direction of both endings of the curve. /// Control point, controls the direction of both endings of the curve.
/// </summary> /// </summary>
public Vector2 ControlPoint; public Vector2 ControlPoint;
/// <summary> /// <summary>
/// The parallel value. /// The parallel value.
/// </summary> /// </summary>
/// <remarks>This value defines whether the curve should be calculated as a /// <remarks>This value defines whether the curve should be calculated as a
/// parallel curve to the original bezier curve. A value of 0.0f represents /// 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 /// 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.</remarks> /// of 5.f to the orignal curve at any point.</remarks>
public float Parallel; public float Parallel;
#endregion #endregion
#region Constructors #region Constructors
/// <summary> /// <summary>
/// Constructs a new <see cref="BezierCurveQuadric"/>. /// Constructs a new <see cref="BezierCurveQuadric"/>.
/// </summary> /// </summary>
/// <param name="startAnchor">The start anchor.</param> /// <param name="startAnchor">The start anchor.</param>
/// <param name="endAnchor">The end anchor.</param> /// <param name="endAnchor">The end anchor.</param>
/// <param name="controlPoint">The control point.</param> /// <param name="controlPoint">The control point.</param>
public BezierCurveQuadric(Vector2 startAnchor, Vector2 endAnchor, Vector2 controlPoint) public BezierCurveQuadric(Vector2 startAnchor, Vector2 endAnchor, Vector2 controlPoint)
{ {
this.StartAnchor = startAnchor; this.StartAnchor = startAnchor;
this.EndAnchor = endAnchor; this.EndAnchor = endAnchor;
this.ControlPoint = controlPoint; this.ControlPoint = controlPoint;
this.Parallel = 0.0f; this.Parallel = 0.0f;
} }
/// <summary> /// <summary>
/// Constructs a new <see cref="BezierCurveQuadric"/>. /// Constructs a new <see cref="BezierCurveQuadric"/>.
/// </summary> /// </summary>
/// <param name="parallel">The parallel value.</param> /// <param name="parallel">The parallel value.</param>
/// <param name="startAnchor">The start anchor.</param> /// <param name="startAnchor">The start anchor.</param>
/// <param name="endAnchor">The end anchor.</param> /// <param name="endAnchor">The end anchor.</param>
/// <param name="controlPoint">The control point.</param> /// <param name="controlPoint">The control point.</param>
public BezierCurveQuadric(float parallel, Vector2 startAnchor, Vector2 endAnchor, Vector2 controlPoint) public BezierCurveQuadric(float parallel, Vector2 startAnchor, Vector2 endAnchor, Vector2 controlPoint)
{ {
this.Parallel = parallel; this.Parallel = parallel;
this.StartAnchor = startAnchor; this.StartAnchor = startAnchor;
this.EndAnchor = endAnchor; this.EndAnchor = endAnchor;
this.ControlPoint = controlPoint; this.ControlPoint = controlPoint;
} }
#endregion #endregion
#region Functions #region Functions
/// <summary> /// <summary>
/// Calculates the point with the specified t. /// Calculates the point with the specified t.
/// </summary> /// </summary>
/// <param name="t">The t value, between 0.0f and 1.0f.</param> /// <param name="t">The t value, between 0.0f and 1.0f.</param>
/// <returns>Resulting point.</returns> /// <returns>Resulting point.</returns>
public Vector2 CalculatePoint(float t) public Vector2 CalculatePoint(float t)
{ {
Vector2 r = new Vector2(); Vector2 r = new Vector2();
float c = 1.0f - t; float c = 1.0f - t;
r.X = (c * c * StartAnchor.X) + (2 * t * c * ControlPoint.X) + (t * t * EndAnchor.X); 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.Y = (c * c * StartAnchor.Y) + (2 * t * c * ControlPoint.Y) + (t * t * EndAnchor.Y);
if (Parallel == 0.0f) if (Parallel == 0.0f)
return r; return r;
Vector2 perpendicular = new Vector2(); Vector2 perpendicular = new Vector2();
if (t == 0.0f) if (t == 0.0f)
perpendicular = ControlPoint - StartAnchor; perpendicular = ControlPoint - StartAnchor;
else else
perpendicular = r - CalculatePointOfDerivative(t); perpendicular = r - CalculatePointOfDerivative(t);
return r + Vector2.Normalize(perpendicular).PerpendicularRight * Parallel; return r + Vector2.Normalize(perpendicular).PerpendicularRight * Parallel;
} }
/// <summary> /// <summary>
/// Calculates the point with the specified t of the derivative of this function. /// Calculates the point with the specified t of the derivative of this function.
/// </summary> /// </summary>
/// <param name="t">The t, value between 0.0f and 1.0f.</param> /// <param name="t">The t, value between 0.0f and 1.0f.</param>
/// <returns>Resulting point.</returns> /// <returns>Resulting point.</returns>
private Vector2 CalculatePointOfDerivative(float t) private Vector2 CalculatePointOfDerivative(float t)
{ {
Vector2 r = new Vector2(); Vector2 r = new Vector2();
r.X = (1.0f - t) * StartAnchor.X + t * ControlPoint.X; r.X = (1.0f - t) * StartAnchor.X + t * ControlPoint.X;
r.Y = (1.0f - t) * StartAnchor.Y + t * ControlPoint.Y; r.Y = (1.0f - t) * StartAnchor.Y + t * ControlPoint.Y;
return r; return r;
} }
/// <summary> /// <summary>
/// Calculates the length of this bezier curve. /// Calculates the length of this bezier curve.
/// </summary> /// </summary>
/// <param name="precision">The precision.</param> /// <param name="precision">The precision.</param>
/// <returns>Length of curve.</returns> /// <returns>Length of curve.</returns>
/// <remarks>The precision gets better when the <paramref name="precision"/> /// <remarks>The precision gets better when the <paramref name="precision"/>
/// value gets smaller.</remarks> /// value gets smaller.</remarks>
public float CalculateLength(float precision) public float CalculateLength(float precision)
{ {
float length = 0.0f; float length = 0.0f;
Vector2 old = CalculatePoint(0.0f); Vector2 old = CalculatePoint(0.0f);
for (float i = precision; i < (1.0f + precision); i += precision) for (float i = precision; i < (1.0f + precision); i += precision)
{ {
Vector2 n = CalculatePoint(i); Vector2 n = CalculatePoint(i);
length += (n - old).Length; length += (n - old).Length;
old = n; old = n;
} }
return length; return length;
} }
#endregion #endregion
} }
} }

View file

@ -48,31 +48,30 @@ namespace OpenTK
#endregion #endregion
/// <summary> /// Calculates the factorial of a given natural number.
/// </summary>
/// <param name="n">The number.</param>
/// <returns>n!</returns>
public static long Factorial(int n)
{
long result = 1;
for (; n > 1; n--)
result *= n;
return result;
}
/// <summary> /// <summary>
/// Calculates the factorial of a given natural number. /// Calculates the binomial coefficient <paramref name="n"/> above <paramref name="k"/>.
/// </summary> /// </summary>
/// <param name="n">The number.</param> /// <param name="n">The n.</param>
/// <returns>n!</returns> /// <param name="k">The k.</param>
public static long Factorial(int n) /// <returns>n! / (k! * (n - k)!)</returns>
{ public static long BinomialCoefficient(int n, int k)
long result = 1; {
return Factorial(n) / (Factorial(k) * Factorial(n - k));
for (; n > 1; n--) }
result *= n;
return result;
}
/// <summary>
/// Calculates the binomial coefficient <paramref name="n"/> above <paramref name="k"/>.
/// </summary>
/// <param name="n">The n.</param>
/// <param name="k">The k.</param>
/// <returns>n! / (k! * (n - k)!)</returns>
public static long BinomialCoefficient(int n, int k)
{
return Factorial(n) / (Factorial(k) * Factorial(n - k));
}
/// <summary> /// <summary>
/// Returns an approximation of the inverse square root of left number. /// Returns an approximation of the inverse square root of left number.

View file

@ -230,8 +230,8 @@ namespace OpenTK
if ((mantissa & 0x00800000) == 1) if ((mantissa & 0x00800000) == 1)
{ {
mantissa = 0; // overflow in significand, mantissa = 0; // overflow in significand,
exponent += 1; // adjust exponent exponent += 1; // adjust exponent
} }
// exponent overflow // exponent overflow

View file

@ -36,46 +36,46 @@ namespace OpenTK
{ {
#region Fields #region Fields
/// <summary> /// <summary>
/// Top row of the matrix /// Top row of the matrix
/// </summary> /// </summary>
public Vector4 Row0; public Vector4 Row0;
/// <summary> /// <summary>
/// 2nd row of the matrix /// 2nd row of the matrix
/// </summary> /// </summary>
public Vector4 Row1; public Vector4 Row1;
/// <summary> /// <summary>
/// 3rd row of the matrix /// 3rd row of the matrix
/// </summary> /// </summary>
public Vector4 Row2; public Vector4 Row2;
/// <summary> /// <summary>
/// Bottom row of the matrix /// Bottom row of the matrix
/// </summary> /// </summary>
public Vector4 Row3; public Vector4 Row3;
/// <summary> /// <summary>
/// The identity matrix /// The identity matrix
/// </summary> /// </summary>
public static Matrix4 Identity = new Matrix4(Vector4.UnitX, Vector4.UnitY, Vector4.UnitZ, Vector4.UnitW); public static Matrix4 Identity = new Matrix4(Vector4.UnitX, Vector4.UnitY, Vector4.UnitZ, Vector4.UnitW);
#endregion #endregion
#region Constructors #region Constructors
/// <summary> /// <summary>
/// Constructs a new instance. /// Constructs a new instance.
/// </summary> /// </summary>
/// <param name="row0">Top row of the matrix</param> /// <param name="row0">Top row of the matrix</param>
/// <param name="row1">Second row of the matrix</param> /// <param name="row1">Second row of the matrix</param>
/// <param name="row2">Third row of the matrix</param> /// <param name="row2">Third row of the matrix</param>
/// <param name="row3">Bottom row of the matrix</param> /// <param name="row3">Bottom row of the matrix</param>
public Matrix4(Vector4 row0, Vector4 row1, Vector4 row2, Vector4 row3) public Matrix4(Vector4 row0, Vector4 row1, Vector4 row2, Vector4 row3)
{ {
Row0 = row0; Row0 = row0;
Row1 = row1; Row1 = row1;
Row2 = row2; Row2 = row2;
Row3 = row3; Row3 = row3;
} }
/// <summary> /// <summary>
/// Constructs a new instance. /// Constructs a new instance.
@ -272,7 +272,7 @@ namespace OpenTK
#region Static #region Static
#region CreateFromAxisAngle #region CreateFromAxisAngle
/// <summary> /// <summary>
/// Build a rotation matrix from the specified axis/angle rotation. /// Build a rotation matrix from the specified axis/angle rotation.
@ -289,9 +289,9 @@ namespace OpenTK
axis.Normalize(); 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, 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.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, 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); 0, 0, 0, 1);
} }
/// <summary> /// <summary>
@ -303,11 +303,11 @@ namespace OpenTK
public static Matrix4 CreateFromAxisAngle(Vector3 axis, float angle) public static Matrix4 CreateFromAxisAngle(Vector3 axis, float angle)
{ {
Matrix4 result; Matrix4 result;
CreateFromAxisAngle(axis, angle, out result); CreateFromAxisAngle(axis, angle, out result);
return result; return result;
} }
#endregion #endregion
#region CreateTranslation #region CreateTranslation
@ -444,7 +444,7 @@ namespace OpenTK
#endregion #endregion
#region CreatePerspectiveFieldOfView #region CreatePerspectiveFieldOfView
/// <summary> /// <summary>
/// Creates a perspective projection matrix. /// Creates a perspective projection matrix.
@ -466,16 +466,16 @@ namespace OpenTK
/// </exception> /// </exception>
public static void CreatePerspectiveFieldOfView(float fovy, float aspect, float zNear, float zFar, out Matrix4 result) public static void CreatePerspectiveFieldOfView(float fovy, float aspect, float zNear, float zFar, out Matrix4 result)
{ {
if (fovy <= 0 || fovy > Math.PI) if (fovy <= 0 || fovy > Math.PI)
throw new ArgumentOutOfRangeException("fovy"); throw new ArgumentOutOfRangeException("fovy");
if (aspect <= 0) if (aspect <= 0)
throw new ArgumentOutOfRangeException("aspect"); throw new ArgumentOutOfRangeException("aspect");
if (zNear <= 0) if (zNear <= 0)
throw new ArgumentOutOfRangeException("zNear"); throw new ArgumentOutOfRangeException("zNear");
if (zFar <= 0) if (zFar <= 0)
throw new ArgumentOutOfRangeException("zFar"); throw new ArgumentOutOfRangeException("zFar");
if (zNear >= zFar) if (zNear >= zFar)
throw new ArgumentOutOfRangeException("zNear"); throw new ArgumentOutOfRangeException("zNear");
float yMax = zNear * (float)System.Math.Tan(0.5f * fovy); float yMax = zNear * (float)System.Math.Tan(0.5f * fovy);
float yMin = -yMax; float yMin = -yMax;
@ -505,14 +505,14 @@ namespace OpenTK
/// </exception> /// </exception>
public static Matrix4 CreatePerspectiveFieldOfView(float fovy, float aspect, float zNear, float zFar) public static Matrix4 CreatePerspectiveFieldOfView(float fovy, float aspect, float zNear, float zFar)
{ {
Matrix4 result; Matrix4 result;
CreatePerspectiveFieldOfView(fovy, aspect, zNear, zFar, out result); CreatePerspectiveFieldOfView(fovy, aspect, zNear, zFar, out result);
return result; return result;
} }
#endregion #endregion
#region CreatePerspectiveOffCenter #region CreatePerspectiveOffCenter
/// <summary> /// <summary>
/// Creates an perspective projection matrix. /// Creates an perspective projection matrix.
@ -534,24 +534,24 @@ namespace OpenTK
/// </exception> /// </exception>
public static void CreatePerspectiveOffCenter(float left, float right, float bottom, float top, float zNear, float zFar, out Matrix4 result) public static void CreatePerspectiveOffCenter(float left, float right, float bottom, float top, float zNear, float zFar, out Matrix4 result)
{ {
if (zNear <= 0) if (zNear <= 0)
throw new ArgumentOutOfRangeException("zNear"); throw new ArgumentOutOfRangeException("zNear");
if (zFar <= 0) if (zFar <= 0)
throw new ArgumentOutOfRangeException("zFar"); throw new ArgumentOutOfRangeException("zFar");
if (zNear >= zFar) if (zNear >= zFar)
throw new ArgumentOutOfRangeException("zNear"); throw new ArgumentOutOfRangeException("zNear");
float x = (2.0f * zNear) / (right - left); float x = (2.0f * zNear) / (right - left);
float y = (2.0f * zNear) / (top - bottom); float y = (2.0f * zNear) / (top - bottom);
float a = (right + left) / (right - left); float a = (right + left) / (right - left);
float b = (top + bottom) / (top - bottom); float b = (top + bottom) / (top - bottom);
float c = -(zFar + zNear) / (zFar - zNear); float c = -(zFar + zNear) / (zFar - zNear);
float d = -(2.0f * zFar * zNear) / (zFar - zNear); float d = -(2.0f * zFar * zNear) / (zFar - zNear);
result = new Matrix4(x, 0, 0, 0, result = new Matrix4(x, 0, 0, 0,
0, y, 0, 0, 0, y, 0, 0,
a, b, c, -1, a, b, c, -1,
0, 0, d, 0); 0, 0, d, 0);
} }
/// <summary> /// <summary>
@ -574,12 +574,12 @@ namespace OpenTK
/// </exception> /// </exception>
public static Matrix4 CreatePerspectiveOffCenter(float left, float right, float bottom, float top, float zNear, float zFar) public static Matrix4 CreatePerspectiveOffCenter(float left, float right, float bottom, float top, float zNear, float zFar)
{ {
Matrix4 result; Matrix4 result;
CreatePerspectiveOffCenter(left, right, bottom, top, zNear, zFar, out result); CreatePerspectiveOffCenter(left, right, bottom, top, zNear, zFar, out result);
return result; return result;
} }
#endregion #endregion
#region Obsolete Functions #region Obsolete Functions
@ -832,35 +832,35 @@ namespace OpenTK
public static Matrix4 Mult(Matrix4 left, Matrix4 right) public static Matrix4 Mult(Matrix4 left, Matrix4 right)
{ {
Matrix4 result; Matrix4 result;
Mult(ref left, ref right, out result); Mult(ref left, ref right, out result);
return result; return result;
} }
/// <summary> /// <summary>
/// Multiplies two instances. /// Multiplies two instances.
/// </summary> /// </summary>
/// <param name="left">The left operand of the multiplication.</param> /// <param name="left">The left operand of the multiplication.</param>
/// <param name="right">The right operand of the multiplication.</param> /// <param name="right">The right operand of the multiplication.</param>
/// <param name="result">A new instance that is the result of the multiplication</param> /// <param name="result">A new instance that is the result of the multiplication</param>
public static void Mult(ref Matrix4 left, ref Matrix4 right, out Matrix4 result) public static void Mult(ref Matrix4 left, ref Matrix4 right, out Matrix4 result)
{ {
result = new Matrix4( result = new Matrix4(
left.M11 * right.M11 + left.M12 * right.M21 + left.M13 * right.M31 + left.M14 * right.M41, 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.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.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.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.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.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.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.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.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.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.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.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.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.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.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); left.M41 * right.M14 + left.M42 * right.M24 + left.M43 * right.M34 + left.M44 * right.M44);
} }
#endregion #endregion
@ -881,9 +881,9 @@ namespace OpenTK
// convert the matrix to an array for easy looping // convert the matrix to an array for easy looping
float[,] inverse = {{mat.Row0.X, mat.Row0.Y, mat.Row0.Z, mat.Row0.W}, 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.Row1.X, mat.Row1.Y, mat.Row1.Z, mat.Row1.W},
{mat.Row2.X, mat.Row2.Y, mat.Row2.Z, mat.Row2.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.Row3.X, mat.Row3.Y, mat.Row3.Z, mat.Row3.W} };
int icol = 0; int icol = 0;
int irow = 0; int irow = 0;
for (int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)

View file

@ -36,46 +36,46 @@ namespace OpenTK
{ {
#region Fields #region Fields
/// <summary> /// <summary>
/// Top row of the matrix /// Top row of the matrix
/// </summary> /// </summary>
public Vector4d Row0; public Vector4d Row0;
/// <summary> /// <summary>
/// 2nd row of the matrix /// 2nd row of the matrix
/// </summary> /// </summary>
public Vector4d Row1; public Vector4d Row1;
/// <summary> /// <summary>
/// 3rd row of the matrix /// 3rd row of the matrix
/// </summary> /// </summary>
public Vector4d Row2; public Vector4d Row2;
/// <summary> /// <summary>
/// Bottom row of the matrix /// Bottom row of the matrix
/// </summary> /// </summary>
public Vector4d Row3; public Vector4d Row3;
/// <summary> /// <summary>
/// The identity matrix /// The identity matrix
/// </summary> /// </summary>
public static Matrix4d Identity = new Matrix4d(Vector4d .UnitX, Vector4d .UnitY, Vector4d .UnitZ, Vector4d .UnitW); public static Matrix4d Identity = new Matrix4d(Vector4d .UnitX, Vector4d .UnitY, Vector4d .UnitZ, Vector4d .UnitW);
#endregion #endregion
#region Constructors #region Constructors
/// <summary> /// <summary>
/// Constructs a new instance. /// Constructs a new instance.
/// </summary> /// </summary>
/// <param name="row0">Top row of the matrix</param> /// <param name="row0">Top row of the matrix</param>
/// <param name="row1">Second row of the matrix</param> /// <param name="row1">Second row of the matrix</param>
/// <param name="row2">Third row of the matrix</param> /// <param name="row2">Third row of the matrix</param>
/// <param name="row3">Bottom row of the matrix</param> /// <param name="row3">Bottom row of the matrix</param>
public Matrix4d(Vector4d row0, Vector4d row1, Vector4d row2, Vector4d row3) public Matrix4d(Vector4d row0, Vector4d row1, Vector4d row2, Vector4d row3)
{ {
Row0 = row0; Row0 = row0;
Row1 = row1; Row1 = row1;
Row2 = row2; Row2 = row2;
Row3 = row3; Row3 = row3;
} }
/// <summary> /// <summary>
/// Constructs a new instance. /// Constructs a new instance.
@ -680,35 +680,35 @@ namespace OpenTK
public static Matrix4d Mult(Matrix4d left, Matrix4d right) public static Matrix4d Mult(Matrix4d left, Matrix4d right)
{ {
Matrix4d result; Matrix4d result;
Mult(ref left, ref right, out result); Mult(ref left, ref right, out result);
return result; return result;
} }
/// <summary> /// <summary>
/// Multiplies two instances. /// Multiplies two instances.
/// </summary> /// </summary>
/// <param name="left">The left operand of the multiplication.</param> /// <param name="left">The left operand of the multiplication.</param>
/// <param name="right">The right operand of the multiplication.</param> /// <param name="right">The right operand of the multiplication.</param>
/// <param name="result">A new instance that is the result of the multiplication</param> /// <param name="result">A new instance that is the result of the multiplication</param>
public static void Mult(ref Matrix4d left, ref Matrix4d right, out Matrix4d result) public static void Mult(ref Matrix4d left, ref Matrix4d right, out Matrix4d result)
{ {
result = new Matrix4d(); result = new Matrix4d();
result.M11 = left.M11 * right.M11 + left.M12 * right.M21 + left.M13 * right.M31 + left.M14 * right.M41; 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.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.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.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.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.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.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.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.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.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.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.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.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.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.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.M44 = left.M41 * right.M14 + left.M42 * right.M24 + left.M43 * right.M34 + left.M44 * right.M44;
} }
#endregion #endregion
@ -729,9 +729,9 @@ namespace OpenTK
// convert the matrix to an array for easy looping // convert the matrix to an array for easy looping
double[,] inverse = {{mat.Row0.X, mat.Row0.Y, mat.Row0.Z, mat.Row0.W}, 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.Row1.X, mat.Row1.Y, mat.Row1.Z, mat.Row1.W},
{mat.Row2.X, mat.Row2.Y, mat.Row2.Z, mat.Row2.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.Row3.X, mat.Row3.Y, mat.Row3.Z, mat.Row3.W} };
int icol = 0; int icol = 0;
int irow = 0; int irow = 0;
for (int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)

View file

@ -57,8 +57,8 @@ namespace OpenTK
/// <param name="y">The y coordinate of the net Vector2.</param> /// <param name="y">The y coordinate of the net Vector2.</param>
public Vector2(float x, float y) public Vector2(float x, float y)
{ {
X = x; X = x;
Y = y; Y = y;
} }
/// <summary> /// <summary>
@ -176,10 +176,10 @@ namespace OpenTK
/// <seealso cref="LengthSquared"/> /// <seealso cref="LengthSquared"/>
public float Length public float Length
{ {
get get
{ {
return (float)System.Math.Sqrt(X * X + Y * Y); return (float)System.Math.Sqrt(X * X + Y * Y);
} }
} }
#endregion #endregion
@ -197,10 +197,10 @@ namespace OpenTK
/// <seealso cref="LengthSquared"/> /// <seealso cref="LengthSquared"/>
public float LengthFast public float LengthFast
{ {
get get
{ {
return 1.0f /OpenTK.Functions.InverseSqrtFast(X * X + Y * Y); return 1.0f /OpenTK.Functions.InverseSqrtFast(X * X + Y * Y);
} }
} }
#endregion #endregion
@ -218,43 +218,43 @@ namespace OpenTK
/// <seealso cref="LengthFast"/> /// <seealso cref="LengthFast"/>
public float LengthSquared public float LengthSquared
{ {
get get
{ {
return X * X + Y * Y; return X * X + Y * Y;
} }
} }
#endregion #endregion
#region public Vector2 PerpendicularRight #region public Vector2 PerpendicularRight
/// <summary> /// <summary>
/// Gets the perpendicular vector on the right side of this vector. /// Gets the perpendicular vector on the right side of this vector.
/// </summary> /// </summary>
public Vector2 PerpendicularRight public Vector2 PerpendicularRight
{ {
get get
{ {
return new Vector2(Y, -X); return new Vector2(Y, -X);
} }
} }
#endregion #endregion
#region public Vector2 PerpendicularLeft #region public Vector2 PerpendicularLeft
/// <summary> /// <summary>
/// Gets the perpendicular vector on the left side of this vector. /// Gets the perpendicular vector on the left side of this vector.
/// </summary> /// </summary>
public Vector2 PerpendicularLeft public Vector2 PerpendicularLeft
{ {
get get
{ {
return new Vector2(-Y, X); return new Vector2(-Y, X);
} }
} }
#endregion #endregion
#region public void Normalize() #region public void Normalize()
@ -263,9 +263,9 @@ namespace OpenTK
/// </summary> /// </summary>
public void Normalize() public void Normalize()
{ {
float scale = 1.0f / this.Length; float scale = 1.0f / this.Length;
X *= scale; X *= scale;
Y *= scale; Y *= scale;
} }
#endregion #endregion
@ -277,9 +277,9 @@ namespace OpenTK
/// </summary> /// </summary>
public void NormalizeFast() public void NormalizeFast()
{ {
float scale = Functions.InverseSqrtFast(X * X + Y * Y); float scale = Functions.InverseSqrtFast(X * X + Y * Y);
X *= scale; X *= scale;
Y *= scale; Y *= scale;
} }
#endregion #endregion
@ -293,8 +293,8 @@ namespace OpenTK
/// <param name="sy">The scale of the Y component.</param> /// <param name="sy">The scale of the Y component.</param>
public void Scale(float sx, float sy) public void Scale(float sx, float sy)
{ {
this.X = X * sx; this.X = X * sx;
this.Y = Y * sy; this.Y = Y * sy;
} }
/// <summary>Scales this instance by the given parameter.</summary> /// <summary>Scales this instance by the given parameter.</summary>
@ -751,12 +751,12 @@ namespace OpenTK
/// <param name="left">Left operand.</param> /// <param name="left">Left operand.</param>
/// <param name="right">Right operand.</param> /// <param name="right">Right operand.</param>
/// <returns>Result of addition.</returns> /// <returns>Result of addition.</returns>
public static Vector2 operator +(Vector2 left, Vector2 right) public static Vector2 operator +(Vector2 left, Vector2 right)
{ {
left.X += right.X; left.X += right.X;
left.Y += right.Y; left.Y += right.Y;
return left; return left;
} }
/// <summary> /// <summary>
/// Subtracts the specified instances. /// Subtracts the specified instances.
@ -764,24 +764,24 @@ namespace OpenTK
/// <param name="left">Left operand.</param> /// <param name="left">Left operand.</param>
/// <param name="right">Right operand.</param> /// <param name="right">Right operand.</param>
/// <returns>Result of subtraction.</returns> /// <returns>Result of subtraction.</returns>
public static Vector2 operator -(Vector2 left, Vector2 right) public static Vector2 operator -(Vector2 left, Vector2 right)
{ {
left.X -= right.X; left.X -= right.X;
left.Y -= right.Y; left.Y -= right.Y;
return left; return left;
} }
/// <summary> /// <summary>
/// Negates the specified instance. /// Negates the specified instance.
/// </summary> /// </summary>
/// <param name="vec">Operand.</param> /// <param name="vec">Operand.</param>
/// <returns>Result of negation.</returns> /// <returns>Result of negation.</returns>
public static Vector2 operator -(Vector2 vec) public static Vector2 operator -(Vector2 vec)
{ {
vec.X = -vec.X; vec.X = -vec.X;
vec.Y = -vec.Y; vec.Y = -vec.Y;
return vec; return vec;
} }
/// <summary> /// <summary>
/// Multiplies the specified instance by a scalar. /// Multiplies the specified instance by a scalar.
@ -789,12 +789,12 @@ namespace OpenTK
/// <param name="vec">Left operand.</param> /// <param name="vec">Left operand.</param>
/// <param name="scale">Right operand.</param> /// <param name="scale">Right operand.</param>
/// <returns>Result of multiplication.</returns> /// <returns>Result of multiplication.</returns>
public static Vector2 operator *(Vector2 vec, float scale) public static Vector2 operator *(Vector2 vec, float scale)
{ {
vec.X *= scale; vec.X *= scale;
vec.Y *= scale; vec.Y *= scale;
return vec; return vec;
} }
/// <summary> /// <summary>
/// Multiplies the specified instance by a scalar. /// Multiplies the specified instance by a scalar.
@ -803,11 +803,11 @@ namespace OpenTK
/// <param name="vec">Right operand.</param> /// <param name="vec">Right operand.</param>
/// <returns>Result of multiplication.</returns> /// <returns>Result of multiplication.</returns>
public static Vector2 operator *(float scale, Vector2 vec) public static Vector2 operator *(float scale, Vector2 vec)
{ {
vec.X *= scale; vec.X *= scale;
vec.Y *= scale; vec.Y *= scale;
return vec; return vec;
} }
/// <summary> /// <summary>
/// Divides the specified instance by a scalar. /// Divides the specified instance by a scalar.
@ -815,13 +815,13 @@ namespace OpenTK
/// <param name="vec">Left operand</param> /// <param name="vec">Left operand</param>
/// <param name="scale">Right operand</param> /// <param name="scale">Right operand</param>
/// <returns>Result of the division.</returns> /// <returns>Result of the division.</returns>
public static Vector2 operator /(Vector2 vec, float scale) public static Vector2 operator /(Vector2 vec, float scale)
{ {
float mult = 1.0f / scale; float mult = 1.0f / scale;
vec.X *= mult; vec.X *= mult;
vec.Y *= mult; vec.Y *= mult;
return vec; return vec;
} }
/// <summary> /// <summary>
/// Compares the specified instances for equality. /// Compares the specified instances for equality.

View file

@ -60,7 +60,7 @@ namespace OpenTK
/// <summary> /// <summary>
/// Defines a unit-length Vector4 that points towards the X-axis. /// Defines a unit-length Vector4 that points towards the X-axis.
/// </summary> /// </summary>
public static Vector4 UnitX = new Vector4(1, 0, 0, 0); public static Vector4 UnitX = new Vector4(1, 0, 0, 0);
/// <summary> /// <summary>
/// Defines a unit-length Vector4 that points towards the Y-axis. /// Defines a unit-length Vector4 that points towards the Y-axis.
@ -70,17 +70,17 @@ namespace OpenTK
/// <summary> /// <summary>
/// Defines a unit-length Vector4 that points towards the Z-axis. /// Defines a unit-length Vector4 that points towards the Z-axis.
/// </summary> /// </summary>
public static Vector4 UnitZ = new Vector4(0, 0, 1, 0); public static Vector4 UnitZ = new Vector4(0, 0, 1, 0);
/// <summary> /// <summary>
/// Defines a unit-length Vector4 that points towards the W-axis. /// Defines a unit-length Vector4 that points towards the W-axis.
/// </summary> /// </summary>
public static Vector4 UnitW = new Vector4(0, 0, 0, 1); public static Vector4 UnitW = new Vector4(0, 0, 0, 1);
/// <summary> /// <summary>
/// Defines a zero-length Vector4. /// Defines a zero-length Vector4.
/// </summary> /// </summary>
public static Vector4 Zero = new Vector4(0, 0, 0, 0); public static Vector4 Zero = new Vector4(0, 0, 0, 0);
/// <summary> /// <summary>
/// Defines an instance with all components set to 1. /// Defines an instance with all components set to 1.
@ -849,58 +849,58 @@ namespace OpenTK
public static Vector4 operator +(Vector4 left, Vector4 right) public static Vector4 operator +(Vector4 left, Vector4 right)
{ {
left.X += right.X; left.X += right.X;
left.Y += right.Y; left.Y += right.Y;
left.Z += right.Z; left.Z += right.Z;
left.W += right.W; left.W += right.W;
return left; return left;
} }
public static Vector4 operator -(Vector4 left, Vector4 right) public static Vector4 operator -(Vector4 left, Vector4 right)
{ {
left.X -= right.X; left.X -= right.X;
left.Y -= right.Y; left.Y -= right.Y;
left.Z -= right.Z; left.Z -= right.Z;
left.W -= right.W; left.W -= right.W;
return left; return left;
} }
public static Vector4 operator -(Vector4 vec) public static Vector4 operator -(Vector4 vec)
{ {
vec.X = -vec.X; vec.X = -vec.X;
vec.Y = -vec.Y; vec.Y = -vec.Y;
vec.Z = -vec.Z; vec.Z = -vec.Z;
vec.W = -vec.W; vec.W = -vec.W;
return vec; return vec;
} }
public static Vector4 operator *(Vector4 vec, float f) public static Vector4 operator *(Vector4 vec, float f)
{ {
vec.X *= f; vec.X *= f;
vec.Y *= f; vec.Y *= f;
vec.Z *= f; vec.Z *= f;
vec.W *= f; vec.W *= f;
return vec; return vec;
} }
public static Vector4 operator *(float f, Vector4 vec) public static Vector4 operator *(float f, Vector4 vec)
{ {
vec.X *= f; vec.X *= f;
vec.Y *= f; vec.Y *= f;
vec.Z *= f; vec.Z *= f;
vec.W *= f; vec.W *= f;
return vec; return vec;
} }
public static Vector4 operator /(Vector4 vec, float f) public static Vector4 operator /(Vector4 vec, float f)
{ {
float mult = 1.0f / f; float mult = 1.0f / f;
vec.X *= mult; vec.X *= mult;
vec.Y *= mult; vec.Y *= mult;
vec.Z *= mult; vec.Z *= mult;
vec.W *= mult; vec.W *= mult;
return vec; return vec;
} }
public static bool operator ==(Vector4 left, Vector4 right) public static bool operator ==(Vector4 left, Vector4 right)
{ {
@ -933,15 +933,15 @@ namespace OpenTK
#region public override string ToString() #region public override string ToString()
/// <summary> /// <summary>
/// Returns a System.String that represents the current Vector4. /// Returns a System.String that represents the current Vector4.
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public override string ToString() public override string ToString()
{ {
return String.Format("({0}, {1}, {2}, {3})", X, Y, Z, W); return String.Format("({0}, {1}, {2}, {3})", X, Y, Z, W);
} }
#endregion #endregion
#region public override int GetHashCode() #region public override int GetHashCode()