Added ref/out overloads to static Vector*.Dot and Vector*.Lerp methods. Simplified the slow Vector3/Vector3d's static Cross methods. Occasional tweaks to inline documentation (spelling, consistency)

This commit is contained in:
chrisbrandtner 2009-01-23 15:04:53 +00:00
parent d45f6f7d6d
commit 01e971741d
6 changed files with 125 additions and 27 deletions

View file

@ -27,9 +27,7 @@ using System.Runtime.InteropServices;
namespace OpenTK.Math
{
/// <summary>
/// Represents a 2D vector.
/// </summary>
/// <summary>Represents a 2D vector using two single-precision floating-point numbers.</summary>
/// <remarks>
/// The Vector2 structure is suitable for interoperation with unmanaged code requiring two consecutive floats.
/// </remarks>
@ -562,7 +560,7 @@ namespace OpenTK.Math
#region Dot
/// <summary>
/// Caclulate the dot (scalar) product of two vectors
/// Calculate the dot (scalar) product of two vectors
/// </summary>
/// <param name="left">First operand</param>
/// <param name="right">Second operand</param>
@ -572,6 +570,17 @@ namespace OpenTK.Math
return left.X * right.X + left.Y * right.Y;
}
/// <summary>
/// Calculate the dot (scalar) product of two vectors
/// </summary>
/// <param name="left">First operand</param>
/// <param name="right">Second operand</param>
/// <param name="result">The dot product of the two inputs</param>
public static void Dot( ref Vector2 left, ref Vector2 right, out float result )
{
result = left.X * right.X + left.Y * right.Y;
}
#endregion
#region Lerp
@ -581,7 +590,7 @@ namespace OpenTK.Math
/// </summary>
/// <param name="a">First input vector</param>
/// <param name="b">Second input vector</param>
/// <param name="blend">The blend factor</param>
/// <param name="blend">The blend factor. a when blend=0, b when blend=1.</param>
/// <returns>a when blend=0, b when blend=1, and a linear combination otherwise</returns>
public static Vector2 Lerp(Vector2 a, Vector2 b, float blend)
{
@ -590,6 +599,19 @@ namespace OpenTK.Math
return a;
}
/// <summary>
/// Returns a new Vector that is the linear blend of the 2 given Vectors
/// </summary>
/// <param name="a">First input vector</param>
/// <param name="b">Second input vector</param>
/// <param name="blend">The blend factor. a when blend=0, b when blend=1.</param>
/// <param name="result">a when blend=0, b when blend=1, and a linear combination otherwise</param>
public static void Lerp( ref Vector2 a, ref Vector2 b, float blend, out Vector2 result )
{
result.X = blend * ( b.X - a.X ) + a.X;
result.Y = blend * ( b.Y - a.Y ) + a.Y;
}
#endregion
#region Barycentric

Binary file not shown.

View file

@ -27,9 +27,10 @@ using System.Runtime.InteropServices;
namespace OpenTK.Math
{
/// <summary>
/// Represents a three-dimensional vector.
/// </summary>
/// <summary>Represents a 3D vector using three single-precision floating-point numbers.</summary>
/// <remarks>
/// The Vector3 structure is suitable for interoperation with unmanaged code requiring three consecutive floats.
/// </remarks>
[Serializable]
[StructLayout(LayoutKind.Sequential)]
public struct Vector3 : IEquatable<Vector3>
@ -563,7 +564,7 @@ namespace OpenTK.Math
#region Dot
/// <summary>
/// Caclulate the dot (scalar) product of two vectors
/// Calculate the dot (scalar) product of two vectors
/// </summary>
/// <param name="left">First operand</param>
/// <param name="right">Second operand</param>
@ -573,6 +574,17 @@ namespace OpenTK.Math
return left.X * right.X + left.Y * right.Y + left.Z * right.Z;
}
/// <summary>
/// Calculate the dot (scalar) product of two vectors
/// </summary>
/// <param name="left">First operand</param>
/// <param name="right">Second operand</param>
/// <param name="result">The dot product of the two inputs</param>
public static void Dot( ref Vector3 left, ref Vector3 right, out float result )
{
result = left.X * right.X + left.Y * right.Y + left.Z * right.Z;
}
#endregion
#region Cross
@ -585,14 +597,9 @@ namespace OpenTK.Math
/// <returns>The cross product of the two inputs</returns>
public static Vector3 Cross(Vector3 left, Vector3 right)
{
float
x = left.Y * right.Z - left.Z * right.Y,
y = left.Z * right.X - left.X * right.Z,
z = left.X * right.Y - left.Y * right.X;
left.X = x;
left.Y = y;
left.Z = z;
return left;
return new Vector3(left.Y * right.Z - left.Z * right.Y,
left.Z * right.X - left.X * right.Z,
left.X * right.Y - left.Y * right.X);
}
/// <summary>
@ -618,7 +625,7 @@ namespace OpenTK.Math
/// </summary>
/// <param name="a">First input vector</param>
/// <param name="b">Second input vector</param>
/// <param name="blend">The blend factor</param>
/// <param name="blend">The blend factor. a when blend=0, b when blend=1.</param>
/// <returns>a when blend=0, b when blend=1, and a linear combination otherwise</returns>
public static Vector3 Lerp(Vector3 a, Vector3 b, float blend)
{
@ -628,6 +635,20 @@ namespace OpenTK.Math
return a;
}
/// <summary>
/// Returns a new Vector that is the linear blend of the 2 given Vectors
/// </summary>
/// <param name="a">First input vector</param>
/// <param name="b">Second input vector</param>
/// <param name="blend">The blend factor. a when blend=0, b when blend=1.</param>
/// <param name="result">a when blend=0, b when blend=1, and a linear combination otherwise</param>
public static void Lerp( ref Vector3 a, ref Vector3 b, float blend, out Vector3 result )
{
result.X = blend * ( b.X - a.X ) + a.X;
result.Y = blend * ( b.Y - a.Y ) + a.Y;
result.Z = blend * ( b.Z - a.Z ) + a.Z;
}
#endregion
#region Barycentric

Binary file not shown.

View file

@ -27,9 +27,10 @@ using System.Runtime.InteropServices;
namespace OpenTK.Math
{
/// <summary>
/// Represents a four-dimensional vector.
/// </summary>
/// <summary>Represents a 4D vector using four single-precision floating-point numbers.</summary>
/// <remarks>
/// The Vector4 structure is suitable for interoperation with unmanaged code requiring four consecutive floats.
/// </remarks>
[Serializable]
[StructLayout(LayoutKind.Sequential)]
public struct Vector4 : IEquatable<Vector4>
@ -566,7 +567,7 @@ namespace OpenTK.Math
#region Dot
/// <summary>
/// Caclulate the dot product of two vectors
/// Calculate the dot product of two vectors
/// </summary>
/// <param name="left">First operand</param>
/// <param name="right">Second operand</param>
@ -576,6 +577,19 @@ namespace OpenTK.Math
return left.X * right.X + left.Y * right.Y + left.Z * right.Z + left.W * right.W;
}
/// <summary>
/// Calculate the dot product of two vectors
/// </summary>
/// <param name="left">First operand</param>
/// <param name="right">Second operand</param>
/// <param name="result">The dot product of the two inputs</param>
public static void Dot( ref Vector4 left, ref Vector4 right, out float result )
{
result = left.X * right.X + left.Y * right.Y + left.Z * right.Z + left.W * right.W;
}
#endregion
#region Lerp
@ -585,7 +599,7 @@ namespace OpenTK.Math
/// </summary>
/// <param name="a">First input vector</param>
/// <param name="b">Second input vector</param>
/// <param name="blend">The blend factor</param>
/// <param name="blend">The blend factor. a when blend=0, b when blend=1.</param>
/// <returns>a when blend=0, b when blend=1, and a linear combination otherwise</returns>
public static Vector4 Lerp(Vector4 a, Vector4 b, float blend)
{
@ -596,6 +610,21 @@ namespace OpenTK.Math
return a;
}
/// <summary>
/// Returns a new Vector that is the linear blend of the 2 given Vectors
/// </summary>
/// <param name="a">First input vector</param>
/// <param name="b">Second input vector</param>
/// <param name="blend">The blend factor. a when blend=0, b when blend=1.</param>
/// <param name="result">a when blend=0, b when blend=1, and a linear combination otherwise</param>
public static void Lerp( ref Vector4 a, ref Vector4 b, float blend, out Vector4 result )
{
result.X = blend * ( b.X - a.X ) + a.X;
result.Y = blend * ( b.Y - a.Y ) + a.Y;
result.Z = blend * ( b.Z - a.Z ) + a.Z;
result.W = blend * ( b.W - a.W ) + a.W;
}
#endregion
#region Barycentric

View file

@ -27,12 +27,12 @@ using System.Runtime.InteropServices;
namespace OpenTK.Math
{
/// <summary>A 4-dimensional vector using double-precision floating point numbers.</summary>
/// <summary>Represents a 4D vector using four double-precision floating-point numbers.</summary>
[Serializable]
[StructLayout(LayoutKind.Sequential)]
public struct Vector4d : IEquatable<Vector4d>
{
#region Fields
#region Fields
/// <summary>
/// The X component of the Vector4d.
@ -564,7 +564,7 @@ namespace OpenTK.Math
#region Dot
/// <summary>
/// Caclulate the dot product of two vectors
/// Calculate the dot product of two vectors
/// </summary>
/// <param name="left">First operand</param>
/// <param name="right">Second operand</param>
@ -574,6 +574,17 @@ namespace OpenTK.Math
return left.X * right.X + left.Y * right.Y + left.Z * right.Z + left.W * right.W;
}
/// <summary>
/// Calculate the dot product of two vectors
/// </summary>
/// <param name="left">First operand</param>
/// <param name="right">Second operand</param>
/// <param name="result">The dot product of the two inputs</param>
public static void Dot( ref Vector4d left, ref Vector4d right, out double result )
{
result = left.X * right.X + left.Y * right.Y + left.Z * right.Z + left.W * right.W;
}
#endregion
#region Lerp
@ -583,7 +594,7 @@ namespace OpenTK.Math
/// </summary>
/// <param name="a">First input vector</param>
/// <param name="b">Second input vector</param>
/// <param name="blend">The blend factor</param>
/// <param name="blend">The blend factor. a when blend=0, b when blend=1.</param>
/// <returns>a when blend=0, b when blend=1, and a linear combination otherwise</returns>
public static Vector4d Lerp(Vector4d a, Vector4d b, double blend)
{
@ -594,6 +605,21 @@ namespace OpenTK.Math
return a;
}
/// <summary>
/// Returns a new Vector that is the linear blend of the 2 given Vectors
/// </summary>
/// <param name="a">First input vector</param>
/// <param name="b">Second input vector</param>
/// <param name="blend">The blend factor. a when blend=0, b when blend=1.</param>
/// <param name="result">a when blend=0, b when blend=1, and a linear combination otherwise</param>
public static void Lerp( ref Vector4d a, ref Vector4d b, double blend, out Vector4d result )
{
result.X = blend * ( b.X - a.X ) + a.X;
result.Y = blend * ( b.Y - a.Y ) + a.Y;
result.Z = blend * ( b.Z - a.Z ) + a.Z;
result.W = blend * ( b.W - a.W ) + a.W;
}
#endregion
#region Barycentric