Overloaded instance methods Add, Sub, Scale to pass-vector-by-value and set CLS compliance flags.

Overloaded static method BaryCentric to pass-by-reference.
This commit is contained in:
chrisbrandtner 2009-01-24 14:54:52 +00:00
parent 49e132911d
commit 8c56d505b7
6 changed files with 211 additions and 0 deletions

View file

@ -105,6 +105,15 @@ namespace OpenTK.Math
/// <summary>Add the Vector passed as parameter to this instance.</summary> /// <summary>Add the Vector passed as parameter to this instance.</summary>
/// <param name="right">Right operand. This parameter is only read from.</param> /// <param name="right">Right operand. This parameter is only read from.</param>
public void Add( Vector2 right )
{
this.X += right.X;
this.Y += right.Y;
}
/// <summary>Add the Vector passed as parameter to this instance.</summary>
/// <param name="right">Right operand. This parameter is only read from.</param>
[CLSCompliant(false)]
public void Add( ref Vector2 right ) public void Add( ref Vector2 right )
{ {
this.X += right.X; this.X += right.X;
@ -117,6 +126,15 @@ namespace OpenTK.Math
/// <summary>Subtract the Vector passed as parameter from this instance.</summary> /// <summary>Subtract the Vector passed as parameter from this instance.</summary>
/// <param name="right">Right operand. This parameter is only read from.</param> /// <param name="right">Right operand. This parameter is only read from.</param>
public void Sub( Vector2 right )
{
this.X -= right.X;
this.Y -= right.Y;
}
/// <summary>Subtract the Vector passed as parameter from this instance.</summary>
/// <param name="right">Right operand. This parameter is only read from.</param>
[CLSCompliant(false)]
public void Sub( ref Vector2 right ) public void Sub( ref Vector2 right )
{ {
this.X -= right.X; this.X -= right.X;
@ -283,6 +301,15 @@ namespace OpenTK.Math
/// <summary>Scales this instance by the given parameter.</summary> /// <summary>Scales this instance by the given parameter.</summary>
/// <param name="scale">The scaling of the individual components.</param> /// <param name="scale">The scaling of the individual components.</param>
public void Scale( Vector2 scale )
{
this.X *= scale.X;
this.Y *= scale.Y;
}
/// <summary>Scales this instance by the given parameter.</summary>
/// <param name="scale">The scaling of the individual components.</param>
[CLSCompliant(false)]
public void Scale( ref Vector2 scale ) public void Scale( ref Vector2 scale )
{ {
this.X *= scale.X; this.X *= scale.X;
@ -687,6 +714,28 @@ namespace OpenTK.Math
return a + u * (b - a) + v * (c - a); return a + u * (b - a) + v * (c - a);
} }
/// <summary>Interpolate 3 Vectors using Barycentric coordinates</summary>
/// <param name="a">First input Vector.</param>
/// <param name="b">Second input Vector.</param>
/// <param name="c">Third input Vector.</param>
/// <param name="u">First Barycentric Coordinate.</param>
/// <param name="v">Second Barycentric Coordinate.</param>
/// <param name="result">Output Vector. a when u=v=0, b when u=1,v=0, c when u=0,v=1, and a linear combination of a,b,c otherwise</param>
public static void BaryCentric( ref Vector2 a, ref Vector2 b, ref Vector2 c, float u, float v, out Vector2 result )
{
result = a; // copy
Vector2 temp = b; // copy
temp.Sub( ref a );
temp.Mult( u );
result.Add( ref temp );
temp = c; // copy
temp.Sub( ref a );
temp.Mult( v );
result.Add( ref temp );
}
#endregion #endregion
#endregion #endregion

Binary file not shown.

View file

@ -112,6 +112,16 @@ namespace OpenTK.Math
/// <summary>Add the Vector passed as parameter to this instance.</summary> /// <summary>Add the Vector passed as parameter to this instance.</summary>
/// <param name="right">Right operand. This parameter is only read from.</param> /// <param name="right">Right operand. This parameter is only read from.</param>
public void Add( Vector3 right )
{
this.X += right.X;
this.Y += right.Y;
this.Z += right.Z;
}
/// <summary>Add the Vector passed as parameter to this instance.</summary>
/// <param name="right">Right operand. This parameter is only read from.</param>
[CLSCompliant(false)]
public void Add( ref Vector3 right ) public void Add( ref Vector3 right )
{ {
this.X += right.X; this.X += right.X;
@ -125,6 +135,16 @@ namespace OpenTK.Math
/// <summary>Subtract the Vector passed as parameter from this instance.</summary> /// <summary>Subtract the Vector passed as parameter from this instance.</summary>
/// <param name="right">Right operand. This parameter is only read from.</param> /// <param name="right">Right operand. This parameter is only read from.</param>
public void Sub( Vector3 right )
{
this.X -= right.X;
this.Y -= right.Y;
this.Z -= right.Z;
}
/// <summary>Subtract the Vector passed as parameter from this instance.</summary>
/// <param name="right">Right operand. This parameter is only read from.</param>
[CLSCompliant(false)]
public void Sub( ref Vector3 right ) public void Sub( ref Vector3 right )
{ {
this.X -= right.X; this.X -= right.X;
@ -268,6 +288,16 @@ namespace OpenTK.Math
/// <summary>Scales this instance by the given parameter.</summary> /// <summary>Scales this instance by the given parameter.</summary>
/// <param name="scale">The scaling of the individual components.</param> /// <param name="scale">The scaling of the individual components.</param>
public void Scale( Vector3 scale )
{
this.X *= scale.X;
this.Y *= scale.Y;
this.Z *= scale.Z;
}
/// <summary>Scales this instance by the given parameter.</summary>
/// <param name="scale">The scaling of the individual components.</param>
[CLSCompliant(false)]
public void Scale( ref Vector3 scale ) public void Scale( ref Vector3 scale )
{ {
this.X *= scale.X; this.X *= scale.X;
@ -729,6 +759,28 @@ namespace OpenTK.Math
return a + u * (b - a) + v * (c - a); return a + u * (b - a) + v * (c - a);
} }
/// <summary>Interpolate 3 Vectors using Barycentric coordinates</summary>
/// <param name="a">First input Vector.</param>
/// <param name="b">Second input Vector.</param>
/// <param name="c">Third input Vector.</param>
/// <param name="u">First Barycentric Coordinate.</param>
/// <param name="v">Second Barycentric Coordinate.</param>
/// <param name="result">Output Vector. a when u=v=0, b when u=1,v=0, c when u=0,v=1, and a linear combination of a,b,c otherwise</param>
public static void BaryCentric( ref Vector3 a, ref Vector3 b, ref Vector3 c, float u, float v, out Vector3 result )
{
result = a; // copy
Vector3 temp = b; // copy
temp.Sub( ref a );
temp.Mult( u );
result.Add( ref temp );
temp = c; // copy
temp.Sub( ref a );
temp.Mult( v );
result.Add( ref temp );
}
#endregion #endregion
#region Transform #region Transform

Binary file not shown.

View file

@ -152,6 +152,17 @@ namespace OpenTK.Math
/// <summary>Add the Vector passed as parameter to this instance.</summary> /// <summary>Add the Vector passed as parameter to this instance.</summary>
/// <param name="right">Right operand. This parameter is only read from.</param> /// <param name="right">Right operand. This parameter is only read from.</param>
public void Add( Vector4 right )
{
this.X += right.X;
this.Y += right.Y;
this.Z += right.Z;
this.W += right.W;
}
/// <summary>Add the Vector passed as parameter to this instance.</summary>
/// <param name="right">Right operand. This parameter is only read from.</param>
[CLSCompliant(false)]
public void Add( ref Vector4 right ) public void Add( ref Vector4 right )
{ {
this.X += right.X; this.X += right.X;
@ -166,6 +177,17 @@ namespace OpenTK.Math
/// <summary>Subtract the Vector passed as parameter from this instance.</summary> /// <summary>Subtract the Vector passed as parameter from this instance.</summary>
/// <param name="right">Right operand. This parameter is only read from.</param> /// <param name="right">Right operand. This parameter is only read from.</param>
public void Sub( Vector4 right )
{
this.X -= right.X;
this.Y -= right.Y;
this.Z -= right.Z;
this.W -= right.W;
}
/// <summary>Subtract the Vector passed as parameter from this instance.</summary>
/// <param name="right">Right operand. This parameter is only read from.</param>
[CLSCompliant(false)]
public void Sub( ref Vector4 right ) public void Sub( ref Vector4 right )
{ {
this.X -= right.X; this.X -= right.X;
@ -316,6 +338,17 @@ namespace OpenTK.Math
/// <summary>Scales this instance by the given parameter.</summary> /// <summary>Scales this instance by the given parameter.</summary>
/// <param name="scale">The scaling of the individual components.</param> /// <param name="scale">The scaling of the individual components.</param>
public void Scale( Vector4 scale )
{
this.X *= scale.X;
this.Y *= scale.Y;
this.Z *= scale.Z;
this.W *= scale.W;
}
/// <summary>Scales this instance by the given parameter.</summary>
/// <param name="scale">The scaling of the individual components.</param>
[CLSCompliant(false)]
public void Scale( ref Vector4 scale ) public void Scale( ref Vector4 scale )
{ {
this.X *= scale.X; this.X *= scale.X;
@ -710,6 +743,28 @@ namespace OpenTK.Math
return a + u * (b - a) + v * (c - a); return a + u * (b - a) + v * (c - a);
} }
/// <summary>Interpolate 3 Vectors using Barycentric coordinates</summary>
/// <param name="a">First input Vector.</param>
/// <param name="b">Second input Vector.</param>
/// <param name="c">Third input Vector.</param>
/// <param name="u">First Barycentric Coordinate.</param>
/// <param name="v">Second Barycentric Coordinate.</param>
/// <param name="result">Output Vector. a when u=v=0, b when u=1,v=0, c when u=0,v=1, and a linear combination of a,b,c otherwise</param>
public static void BaryCentric( ref Vector4 a, ref Vector4 b, ref Vector4 c, float u, float v, out Vector4 result )
{
result = a; // copy
Vector4 temp = b; // copy
temp.Sub( ref a );
temp.Mult( u );
result.Add( ref temp );
temp = c; // copy
temp.Sub( ref a );
temp.Mult( v );
result.Add( ref temp );
}
#endregion #endregion
#region Transform #region Transform

View file

@ -149,6 +149,17 @@ namespace OpenTK.Math
/// <summary>Add the Vector passed as parameter to this instance.</summary> /// <summary>Add the Vector passed as parameter to this instance.</summary>
/// <param name="right">Right operand. This parameter is only read from.</param> /// <param name="right">Right operand. This parameter is only read from.</param>
public void Add( Vector4d right )
{
this.X += right.X;
this.Y += right.Y;
this.Z += right.Z;
this.W += right.W;
}
/// <summary>Add the Vector passed as parameter to this instance.</summary>
/// <param name="right">Right operand. This parameter is only read from.</param>
[CLSCompliant(false)]
public void Add( ref Vector4d right ) public void Add( ref Vector4d right )
{ {
this.X += right.X; this.X += right.X;
@ -163,6 +174,17 @@ namespace OpenTK.Math
/// <summary>Subtract the Vector passed as parameter from this instance.</summary> /// <summary>Subtract the Vector passed as parameter from this instance.</summary>
/// <param name="right">Right operand. This parameter is only read from.</param> /// <param name="right">Right operand. This parameter is only read from.</param>
public void Sub( Vector4d right )
{
this.X -= right.X;
this.Y -= right.Y;
this.Z -= right.Z;
this.W -= right.W;
}
/// <summary>Subtract the Vector passed as parameter from this instance.</summary>
/// <param name="right">Right operand. This parameter is only read from.</param>
[CLSCompliant(false)]
public void Sub( ref Vector4d right ) public void Sub( ref Vector4d right )
{ {
this.X -= right.X; this.X -= right.X;
@ -313,6 +335,17 @@ namespace OpenTK.Math
/// <summary>Scales this instance by the given parameter.</summary> /// <summary>Scales this instance by the given parameter.</summary>
/// <param name="scale">The scaling of the individual components.</param> /// <param name="scale">The scaling of the individual components.</param>
public void Scale( Vector4d scale )
{
this.X *= scale.X;
this.Y *= scale.Y;
this.Z *= scale.Z;
this.W *= scale.W;
}
/// <summary>Scales this instance by the given parameter.</summary>
/// <param name="scale">The scaling of the individual components.</param>
[CLSCompliant(false)]
public void Scale( ref Vector4d scale ) public void Scale( ref Vector4d scale )
{ {
this.X *= scale.X; this.X *= scale.X;
@ -705,6 +738,28 @@ namespace OpenTK.Math
return a + u * (b - a) + v * (c - a); return a + u * (b - a) + v * (c - a);
} }
/// <summary>Interpolate 3 Vectors using Barycentric coordinates</summary>
/// <param name="a">First input Vector.</param>
/// <param name="b">Second input Vector.</param>
/// <param name="c">Third input Vector.</param>
/// <param name="u">First Barycentric Coordinate.</param>
/// <param name="v">Second Barycentric Coordinate.</param>
/// <param name="result">Output Vector. a when u=v=0, b when u=1,v=0, c when u=0,v=1, and a linear combination of a,b,c otherwise</param>
public static void BaryCentric( ref Vector4d a, ref Vector4d b, ref Vector4d c, float u, float v, out Vector4d result )
{
result = a; // copy
Vector4d temp = b; // copy
temp.Sub( ref a );
temp.Mult( u );
result.Add( ref temp );
temp = c; // copy
temp.Sub( ref a );
temp.Mult( v );
result.Add( ref temp );
}
#endregion #endregion
#region Transform #region Transform