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
{
/// <summary>
/// Represents a bezier curve with as many points as you want.
/// </summary>
[Serializable]
public struct BezierCurve
{
#region Fields
/// <summary>
/// Represents a bezier curve with as many points as you want.
/// </summary>
[Serializable]
public struct BezierCurve
{
#region Fields
private List<Vector2> points;
private List<Vector2> points;
/// <summary>
/// The parallel value.
/// </summary>
/// <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
/// 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>
public float Parallel;
/// <summary>
/// The parallel value.
/// </summary>
/// <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
/// 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>
public float Parallel;
#endregion
#endregion
#region Properties
#region Properties
/// <summary>
/// Gets the points of this curve.
/// </summary>
/// <remarks>The first point and the last points represent the anchor points.</remarks>
public IList<Vector2> Points
{
get
{
return points;
}
}
/// <summary>
/// Gets the points of this curve.
/// </summary>
/// <remarks>The first point and the last points represent the anchor points.</remarks>
public IList<Vector2> Points
{
get
{
return points;
}
}
#endregion
#endregion
#region Constructors
#region Constructors
/// <summary>
/// Constructs a new <see cref="BezierCurve"/>.
/// </summary>
/// <param name="points">The points.</param>
public BezierCurve(IEnumerable<Vector2> points)
{
if (points == null)
throw new ArgumentNullException("points", "Must point to a valid list of Vector2 structures.");
/// <summary>
/// Constructs a new <see cref="BezierCurve"/>.
/// </summary>
/// <param name="points">The points.</param>
public BezierCurve(IEnumerable<Vector2> points)
{
if (points == null)
throw new ArgumentNullException("points", "Must point to a valid list of Vector2 structures.");
this.points = new List<Vector2>(points);
this.Parallel = 0.0f;
}
this.points = new List<Vector2>(points);
this.Parallel = 0.0f;
}
/// <summary>
/// Constructs a new <see cref="BezierCurve"/>.
/// </summary>
/// <param name="points">The points.</param>
public BezierCurve(params Vector2[] points)
{
if (points == null)
throw new ArgumentNullException("points", "Must point to a valid list of Vector2 structures.");
/// <summary>
/// Constructs a new <see cref="BezierCurve"/>.
/// </summary>
/// <param name="points">The points.</param>
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<Vector2>(points);
this.Parallel = 0.0f;
}
this.points = new List<Vector2>(points);
this.Parallel = 0.0f;
}
/// <summary>
/// Constructs a new <see cref="BezierCurve"/>.
/// </summary>
/// <param name="parallel">The parallel value.</param>
/// <param name="points">The points.</param>
public BezierCurve(float parallel, params Vector2[] points)
{
if (points == null)
throw new ArgumentNullException("points", "Must point to a valid list of Vector2 structures.");
/// <summary>
/// Constructs a new <see cref="BezierCurve"/>.
/// </summary>
/// <param name="parallel">The parallel value.</param>
/// <param name="points">The points.</param>
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<Vector2>(points);
}
this.Parallel = parallel;
this.points = new List<Vector2>(points);
}
/// <summary>
/// Constructs a new <see cref="BezierCurve"/>.
/// </summary>
/// <param name="parallel">The parallel value.</param>
/// <param name="points">The points.</param>
public BezierCurve(float parallel, IEnumerable<Vector2> points)
{
if (points == null)
throw new ArgumentNullException("points", "Must point to a valid list of Vector2 structures.");
/// <summary>
/// Constructs a new <see cref="BezierCurve"/>.
/// </summary>
/// <param name="parallel">The parallel value.</param>
/// <param name="points">The points.</param>
public BezierCurve(float parallel, IEnumerable<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<Vector2>(points);
}
this.Parallel = parallel;
this.points = new List<Vector2>(points);
}
#endregion
#endregion
#region Functions
#region Functions
/// <summary>
/// Calculates the point with the specified t.
/// </summary>
/// <param name="t">The t value, between 0.0f and 1.0f.</param>
/// <returns>Resulting point.</returns>
public Vector2 CalculatePoint(float t)
{
return BezierCurve.CalculatePoint(points, t, Parallel);
}
/// <summary>
/// Calculates the point with the specified t.
/// </summary>
/// <param name="t">The t value, between 0.0f and 1.0f.</param>
/// <returns>Resulting point.</returns>
public Vector2 CalculatePoint(float t)
{
return BezierCurve.CalculatePoint(points, t, Parallel);
}
/// <summary>
/// Calculates the length of this bezier curve.
/// </summary>
/// <param name="precision">The precision.</param>
/// <returns>Length of curve.</returns>
/// <remarks>The precision gets better as the <paramref name="precision"/>
/// value gets smaller.</remarks>
public float CalculateLength(float precision)
{
return BezierCurve.CalculateLength(points, precision, Parallel);
}
/// <summary>
/// Calculates the length of this bezier curve.
/// </summary>
/// <param name="precision">The precision.</param>
/// <returns>Length of curve.</returns>
/// <remarks>The precision gets better as the <paramref name="precision"/>
/// value gets smaller.</remarks>
public float CalculateLength(float precision)
{
return BezierCurve.CalculateLength(points, precision, Parallel);
}
#region Static methods
#region Static methods
/// <summary>
/// Calculates the length of the specified bezier curve.
/// </summary>
/// <param name="points">The points.</param>
/// <param name="precision">The precision value.</param>
/// <returns>The precision gets better as the <paramref name="precision"/>
/// value gets smaller.</returns>
public static float CalculateLength(IList<Vector2> points, float precision)
{
return BezierCurve.CalculateLength(points, precision, 0.0f);
}
/// <summary>
/// Calculates the length of the specified bezier curve.
/// </summary>
/// <param name="points">The points.</param>
/// <param name="precision">The precision value.</param>
/// <returns>The precision gets better as the <paramref name="precision"/>
/// value gets smaller.</returns>
public static float CalculateLength(IList<Vector2> points, float precision)
{
return BezierCurve.CalculateLength(points, precision, 0.0f);
}
/// <summary>
/// Calculates the length of the specified bezier curve.
/// </summary>
/// <param name="points">The points.</param>
/// <param name="precision">The precision value.</param>
/// <param name="parallel">The parallel value.</param>
/// <returns>Length of curve.</returns>
/// <remarks><para>The precision gets better as the <paramref name="precision"/>
/// value gets smaller.</para>
/// <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
/// the original curve, 5.0f represents a curve that has always a distance
/// of 5.0f to the orignal curve.</para></remarks>
public static float CalculateLength(IList<Vector2> points, float precision, float parallel)
{
float length = 0.0f;
Vector2 old = BezierCurve.CalculatePoint(points, 0.0f, parallel);
/// <summary>
/// Calculates the length of the specified bezier curve.
/// </summary>
/// <param name="points">The points.</param>
/// <param name="precision">The precision value.</param>
/// <param name="parallel">The parallel value.</param>
/// <returns>Length of curve.</returns>
/// <remarks><para>The precision gets better as the <paramref name="precision"/>
/// value gets smaller.</para>
/// <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
/// the original curve, 5.0f represents a curve that has always a distance
/// of 5.0f to the orignal curve.</para></remarks>
public static float CalculateLength(IList<Vector2> 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;
}
/// <summary>
/// Calculates the point on the given bezier curve with the specified t parameter.
/// </summary>
/// <param name="points">The points.</param>
/// <param name="t">The t parameter, a value between 0.0f and 1.0f.</param>
/// <returns>Resulting point.</returns>
public static Vector2 CalculatePoint(IList<Vector2> points, float t)
{
return BezierCurve.CalculatePoint(points, t, 0.0f);
}
/// <summary>
/// Calculates the point on the given bezier curve with the specified t parameter.
/// </summary>
/// <param name="points">The points.</param>
/// <param name="t">The t parameter, a value between 0.0f and 1.0f.</param>
/// <returns>Resulting point.</returns>
public static Vector2 CalculatePoint(IList<Vector2> points, float t)
{
return BezierCurve.CalculatePoint(points, t, 0.0f);
}
/// <summary>
/// Calculates the point on the given bezier curve with the specified t parameter.
/// </summary>
/// <param name="points">The points.</param>
/// <param name="t">The t parameter, a value between 0.0f and 1.0f.</param>
/// <param name="parallel">The parallel value.</param>
/// <returns>Resulting point.</returns>
/// <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
/// the original curve, 5.0f represents a curve that has always a distance
/// of 5.0f to the orignal curve.</remarks>
public static Vector2 CalculatePoint(IList<Vector2> points, float t, float parallel)
{
Vector2 r = new Vector2();
double c = 1.0d - (double)t;
float temp;
int i = 0;
/// <summary>
/// Calculates the point on the given bezier curve with the specified t parameter.
/// </summary>
/// <param name="points">The points.</param>
/// <param name="t">The t parameter, a value between 0.0f and 1.0f.</param>
/// <param name="parallel">The parallel value.</param>
/// <returns>Resulting point.</returns>
/// <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
/// the original curve, 5.0f represents a curve that has always a distance
/// of 5.0f to the orignal curve.</remarks>
public static Vector2 CalculatePoint(IList<Vector2> 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;
}
/// <summary>
/// Calculates the point with the specified t of the derivative of the given bezier function.
/// </summary>
/// <param name="points">The points.</param>
/// <param name="t">The t parameter, value between 0.0f and 1.0f.</param>
/// <returns>Resulting point.</returns>
private static Vector2 CalculatePointOfDerivative(IList<Vector2> points, float t)
{
Vector2 r = new Vector2();
double c = 1.0d - (double)t;
float temp;
int i = 0;
/// <summary>
/// Calculates the point with the specified t of the derivative of the given bezier function.
/// </summary>
/// <param name="points">The points.</param>
/// <param name="t">The t parameter, value between 0.0f and 1.0f.</param>
/// <returns>Resulting point.</returns>
private static Vector2 CalculatePointOfDerivative(IList<Vector2> 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
}
}

View file

@ -14,150 +14,150 @@ using System.Text;
namespace OpenTK
{
/// <summary>
/// Represents a cubic bezier curve with two anchor and two control points.
/// </summary>
[Serializable]
public struct BezierCurveCubic
{
#region Fields
/// <summary>
/// Represents a cubic bezier curve with two anchor and two control points.
/// </summary>
[Serializable]
public struct BezierCurveCubic
{
#region Fields
/// <summary>
/// Start anchor point.
/// </summary>
public Vector2 StartAnchor;
/// <summary>
/// Start anchor point.
/// </summary>
public Vector2 StartAnchor;
/// <summary>
/// End anchor point.
/// </summary>
public Vector2 EndAnchor;
/// <summary>
/// End anchor point.
/// </summary>
public Vector2 EndAnchor;
/// <summary>
/// First control point, controls the direction of the curve start.
/// </summary>
public Vector2 FirstControlPoint;
/// <summary>
/// First control point, controls the direction of the curve start.
/// </summary>
public Vector2 FirstControlPoint;
/// <summary>
/// Second control point, controls the direction of the curve end.
/// </summary>
public Vector2 SecondControlPoint;
/// <summary>
/// Second control point, controls the direction of the curve end.
/// </summary>
public Vector2 SecondControlPoint;
/// <summary>
/// Gets or sets the parallel value.
/// </summary>
/// <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
/// 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>
public float Parallel;
/// <summary>
/// Gets or sets the parallel value.
/// </summary>
/// <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
/// 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>
public float Parallel;
#endregion
#endregion
#region Constructors
#region Constructors
/// <summary>
/// Constructs a new <see cref="BezierCurveCubic"/>.
/// </summary>
/// <param name="startAnchor">The start anchor point.</param>
/// <param name="endAnchor">The end anchor point.</param>
/// <param name="firstControlPoint">The first control point.</param>
/// <param name="secondControlPoint">The second control point.</param>
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;
}
/// <summary>
/// Constructs a new <see cref="BezierCurveCubic"/>.
/// </summary>
/// <param name="startAnchor">The start anchor point.</param>
/// <param name="endAnchor">The end anchor point.</param>
/// <param name="firstControlPoint">The first control point.</param>
/// <param name="secondControlPoint">The second control point.</param>
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;
}
/// <summary>
/// Constructs a new <see cref="BezierCurveCubic"/>.
/// </summary>
/// <param name="parallel">The parallel value.</param>
/// <param name="startAnchor">The start anchor point.</param>
/// <param name="endAnchor">The end anchor point.</param>
/// <param name="firstControlPoint">The first control point.</param>
/// <param name="secondControlPoint">The second control point.</param>
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;
}
/// <summary>
/// Constructs a new <see cref="BezierCurveCubic"/>.
/// </summary>
/// <param name="parallel">The parallel value.</param>
/// <param name="startAnchor">The start anchor point.</param>
/// <param name="endAnchor">The end anchor point.</param>
/// <param name="firstControlPoint">The first control point.</param>
/// <param name="secondControlPoint">The second control point.</param>
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
/// <summary>
/// Calculates the point with the specified t.
/// </summary>
/// <param name="t">The t value, between 0.0f and 1.0f.</param>
/// <returns>Resulting point.</returns>
public Vector2 CalculatePoint(float t)
{
Vector2 r = new Vector2();
float c = 1.0f - t;
/// <summary>
/// Calculates the point with the specified t.
/// </summary>
/// <param name="t">The t value, between 0.0f and 1.0f.</param>
/// <returns>Resulting point.</returns>
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;
}
/// <summary>
/// Calculates the point with the specified t of the derivative of this function.
/// </summary>
/// <param name="t">The t, value between 0.0f and 1.0f.</param>
/// <returns>Resulting point.</returns>
private Vector2 CalculatePointOfDerivative(float t)
{
Vector2 r = new Vector2();
float c = 1.0f - t;
/// <summary>
/// Calculates the point with the specified t of the derivative of this function.
/// </summary>
/// <param name="t">The t, value between 0.0f and 1.0f.</param>
/// <returns>Resulting point.</returns>
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;
}
/// <summary>
/// Calculates the length of this bezier curve.
/// </summary>
/// <param name="precision">The precision.</param>
/// <returns>Length of the curve.</returns>
/// <remarks>The precision gets better when the <paramref name="precision"/>
/// value gets smaller.</remarks>
public float CalculateLength(float precision)
{
float length = 0.0f;
Vector2 old = CalculatePoint(0.0f);
/// <summary>
/// Calculates the length of this bezier curve.
/// </summary>
/// <param name="precision">The precision.</param>
/// <returns>Length of the curve.</returns>
/// <remarks>The precision gets better when the <paramref name="precision"/>
/// value gets smaller.</remarks>
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
}
}

View file

@ -14,138 +14,138 @@ using System.Text;
namespace OpenTK
{
/// <summary>
/// Represents a quadric bezier curve with two anchor and one control point.
/// </summary>
[Serializable]
public struct BezierCurveQuadric
{
#region Fields
/// <summary>
/// Represents a quadric bezier curve with two anchor and one control point.
/// </summary>
[Serializable]
public struct BezierCurveQuadric
{
#region Fields
/// <summary>
/// Start anchor point.
/// </summary>
public Vector2 StartAnchor;
/// <summary>
/// Start anchor point.
/// </summary>
public Vector2 StartAnchor;
/// <summary>
/// End anchor point.
/// </summary>
public Vector2 EndAnchor;
/// <summary>
/// End anchor point.
/// </summary>
public Vector2 EndAnchor;
/// <summary>
/// Control point, controls the direction of both endings of the curve.
/// </summary>
public Vector2 ControlPoint;
/// <summary>
/// Control point, controls the direction of both endings of the curve.
/// </summary>
public Vector2 ControlPoint;
/// <summary>
/// The parallel value.
/// </summary>
/// <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
/// 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>
public float Parallel;
/// <summary>
/// The parallel value.
/// </summary>
/// <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
/// 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>
public float Parallel;
#endregion
#endregion
#region Constructors
#region Constructors
/// <summary>
/// Constructs a new <see cref="BezierCurveQuadric"/>.
/// </summary>
/// <param name="startAnchor">The start anchor.</param>
/// <param name="endAnchor">The end anchor.</param>
/// <param name="controlPoint">The control point.</param>
public BezierCurveQuadric(Vector2 startAnchor, Vector2 endAnchor, Vector2 controlPoint)
{
this.StartAnchor = startAnchor;
this.EndAnchor = endAnchor;
this.ControlPoint = controlPoint;
this.Parallel = 0.0f;
}
/// <summary>
/// Constructs a new <see cref="BezierCurveQuadric"/>.
/// </summary>
/// <param name="startAnchor">The start anchor.</param>
/// <param name="endAnchor">The end anchor.</param>
/// <param name="controlPoint">The control point.</param>
public BezierCurveQuadric(Vector2 startAnchor, Vector2 endAnchor, Vector2 controlPoint)
{
this.StartAnchor = startAnchor;
this.EndAnchor = endAnchor;
this.ControlPoint = controlPoint;
this.Parallel = 0.0f;
}
/// <summary>
/// Constructs a new <see cref="BezierCurveQuadric"/>.
/// </summary>
/// <param name="parallel">The parallel value.</param>
/// <param name="startAnchor">The start anchor.</param>
/// <param name="endAnchor">The end anchor.</param>
/// <param name="controlPoint">The control point.</param>
public BezierCurveQuadric(float parallel, Vector2 startAnchor, Vector2 endAnchor, Vector2 controlPoint)
{
this.Parallel = parallel;
this.StartAnchor = startAnchor;
this.EndAnchor = endAnchor;
this.ControlPoint = controlPoint;
}
/// <summary>
/// Constructs a new <see cref="BezierCurveQuadric"/>.
/// </summary>
/// <param name="parallel">The parallel value.</param>
/// <param name="startAnchor">The start anchor.</param>
/// <param name="endAnchor">The end anchor.</param>
/// <param name="controlPoint">The control point.</param>
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
/// <summary>
/// Calculates the point with the specified t.
/// </summary>
/// <param name="t">The t value, between 0.0f and 1.0f.</param>
/// <returns>Resulting point.</returns>
public Vector2 CalculatePoint(float t)
{
Vector2 r = new Vector2();
float c = 1.0f - t;
/// <summary>
/// Calculates the point with the specified t.
/// </summary>
/// <param name="t">The t value, between 0.0f and 1.0f.</param>
/// <returns>Resulting point.</returns>
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;
}
/// <summary>
/// Calculates the point with the specified t of the derivative of this function.
/// </summary>
/// <param name="t">The t, value between 0.0f and 1.0f.</param>
/// <returns>Resulting point.</returns>
private Vector2 CalculatePointOfDerivative(float t)
{
Vector2 r = new Vector2();
/// <summary>
/// Calculates the point with the specified t of the derivative of this function.
/// </summary>
/// <param name="t">The t, value between 0.0f and 1.0f.</param>
/// <returns>Resulting point.</returns>
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;
}
/// <summary>
/// Calculates the length of this bezier curve.
/// </summary>
/// <param name="precision">The precision.</param>
/// <returns>Length of curve.</returns>
/// <remarks>The precision gets better when the <paramref name="precision"/>
/// value gets smaller.</remarks>
public float CalculateLength(float precision)
{
float length = 0.0f;
Vector2 old = CalculatePoint(0.0f);
/// <summary>
/// Calculates the length of this bezier curve.
/// </summary>
/// <param name="precision">The precision.</param>
/// <returns>Length of curve.</returns>
/// <remarks>The precision gets better when the <paramref name="precision"/>
/// value gets smaller.</remarks>
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
}
}

View file

@ -48,31 +48,30 @@ namespace OpenTK
#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>
/// 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>
/// 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));
}
/// 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>
/// Returns an approximation of the inverse square root of left number.

View file

@ -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

View file

@ -36,46 +36,46 @@ namespace OpenTK
{
#region Fields
/// <summary>
/// Top row of the matrix
/// </summary>
public Vector4 Row0;
/// <summary>
/// 2nd row of the matrix
/// </summary>
public Vector4 Row1;
/// <summary>
/// 3rd row of the matrix
/// </summary>
public Vector4 Row2;
/// <summary>
/// Bottom row of the matrix
/// </summary>
public Vector4 Row3;
/// <summary>
/// Top row of the matrix
/// </summary>
public Vector4 Row0;
/// <summary>
/// 2nd row of the matrix
/// </summary>
public Vector4 Row1;
/// <summary>
/// 3rd row of the matrix
/// </summary>
public Vector4 Row2;
/// <summary>
/// Bottom row of the matrix
/// </summary>
public Vector4 Row3;
/// <summary>
/// The identity matrix
/// </summary>
public static Matrix4 Identity = new Matrix4(Vector4.UnitX, Vector4.UnitY, Vector4.UnitZ, Vector4.UnitW);
/// <summary>
/// The identity matrix
/// </summary>
public static Matrix4 Identity = new Matrix4(Vector4.UnitX, Vector4.UnitY, Vector4.UnitZ, Vector4.UnitW);
#endregion
#region Constructors
/// <summary>
/// <summary>
/// Constructs a new instance.
/// </summary>
/// </summary>
/// <param name="row0">Top 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="row3">Bottom row of the matrix</param>
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;
}
/// <summary>
/// Constructs a new instance.
@ -272,7 +272,7 @@ namespace OpenTK
#region Static
#region CreateFromAxisAngle
#region CreateFromAxisAngle
/// <summary>
/// Build a rotation matrix from the specified axis/angle rotation.
@ -289,9 +289,9 @@ 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);
}
/// <summary>
@ -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
@ -444,7 +444,7 @@ namespace OpenTK
#endregion
#region CreatePerspectiveFieldOfView
#region CreatePerspectiveFieldOfView
/// <summary>
/// Creates a perspective projection matrix.
@ -466,16 +466,16 @@ namespace OpenTK
/// </exception>
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;
@ -505,14 +505,14 @@ namespace OpenTK
/// </exception>
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
#endregion
#region CreatePerspectiveOffCenter
#region CreatePerspectiveOffCenter
/// <summary>
/// Creates an perspective projection matrix.
@ -534,24 +534,24 @@ namespace OpenTK
/// </exception>
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");
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);
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);
}
/// <summary>
@ -574,12 +574,12 @@ namespace OpenTK
/// </exception>
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;
}
/// <summary>
/// Multiplies two instances.
/// </summary>
/// <summary>
/// Multiplies two instances.
/// </summary>
/// <param name="left">The left 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>
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++)

View file

@ -36,46 +36,46 @@ namespace OpenTK
{
#region Fields
/// <summary>
/// Top row of the matrix
/// </summary>
/// <summary>
/// Top row of the matrix
/// </summary>
public Vector4d Row0;
/// <summary>
/// 2nd row of the matrix
/// </summary>
/// <summary>
/// 2nd row of the matrix
/// </summary>
public Vector4d Row1;
/// <summary>
/// 3rd row of the matrix
/// </summary>
/// <summary>
/// 3rd row of the matrix
/// </summary>
public Vector4d Row2;
/// <summary>
/// Bottom row of the matrix
/// </summary>
/// <summary>
/// Bottom row of the matrix
/// </summary>
public Vector4d Row3;
/// <summary>
/// The identity matrix
/// </summary>
public static Matrix4d Identity = new Matrix4d(Vector4d .UnitX, Vector4d .UnitY, Vector4d .UnitZ, Vector4d .UnitW);
/// <summary>
/// The identity matrix
/// </summary>
public static Matrix4d Identity = new Matrix4d(Vector4d .UnitX, Vector4d .UnitY, Vector4d .UnitZ, Vector4d .UnitW);
#endregion
#region Constructors
/// <summary>
/// Constructs a new instance.
/// </summary>
/// <param name="row0">Top 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="row3">Bottom row of the matrix</param>
public Matrix4d(Vector4d row0, Vector4d row1, Vector4d row2, Vector4d row3)
{
Row0 = row0;
Row1 = row1;
Row2 = row2;
Row3 = row3;
}
/// <summary>
/// Constructs a new instance.
/// </summary>
/// <param name="row0">Top 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="row3">Bottom row of the matrix</param>
public Matrix4d(Vector4d row0, Vector4d row1, Vector4d row2, Vector4d row3)
{
Row0 = row0;
Row1 = row1;
Row2 = row2;
Row3 = row3;
}
/// <summary>
/// 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;
}
/// <summary>
/// Multiplies two instances.
/// </summary>
/// <summary>
/// Multiplies two instances.
/// </summary>
/// <param name="left">The left 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>
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++)

View file

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

View file

@ -60,7 +60,7 @@ namespace OpenTK
/// <summary>
/// Defines a unit-length Vector4 that points towards the X-axis.
/// </summary>
public static Vector4 UnitX = new Vector4(1, 0, 0, 0);
public static Vector4 UnitX = new Vector4(1, 0, 0, 0);
/// <summary>
/// Defines a unit-length Vector4 that points towards the Y-axis.
@ -70,17 +70,17 @@ namespace OpenTK
/// <summary>
/// Defines a unit-length Vector4 that points towards the Z-axis.
/// </summary>
public static Vector4 UnitZ = new Vector4(0, 0, 1, 0);
public static Vector4 UnitZ = new Vector4(0, 0, 1, 0);
/// <summary>
/// Defines a unit-length Vector4 that points towards the W-axis.
/// </summary>
public static Vector4 UnitW = new Vector4(0, 0, 0, 1);
public static Vector4 UnitW = new Vector4(0, 0, 0, 1);
/// <summary>
/// Defines a zero-length Vector4.
/// </summary>
public static Vector4 Zero = new Vector4(0, 0, 0, 0);
public static Vector4 Zero = new Vector4(0, 0, 0, 0);
/// <summary>
/// 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()
/// <summary>
/// Returns a System.String that represents the current Vector4.
/// </summary>
/// <returns></returns>
public override string ToString()
/// Returns a System.String that represents the current Vector4.
/// </summary>
/// <returns></returns>
public override string ToString()
{
return String.Format("({0}, {1}, {2}, {3})", X, Y, Z, W);
}
}
#endregion
#endregion
#region public override int GetHashCode()