From 01e971741d5045f70c81bb04a4cb4253b0c1d2b0 Mon Sep 17 00:00:00 2001 From: chrisbrandtner Date: Fri, 23 Jan 2009 15:04:53 +0000 Subject: [PATCH] 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) --- Source/OpenTK/Math/Vector2.cs | 32 ++++++++++++++++++---- Source/OpenTK/Math/Vector2d.cs | Bin 38062 -> 40424 bytes Source/OpenTK/Math/Vector3.cs | 47 ++++++++++++++++++++++++--------- Source/OpenTK/Math/Vector3d.cs | Bin 58538 -> 60882 bytes Source/OpenTK/Math/Vector4.cs | 39 +++++++++++++++++++++++---- Source/OpenTK/Math/Vector4d.cs | 34 +++++++++++++++++++++--- 6 files changed, 125 insertions(+), 27 deletions(-) diff --git a/Source/OpenTK/Math/Vector2.cs b/Source/OpenTK/Math/Vector2.cs index 2cc8776a..e4a98ae7 100644 --- a/Source/OpenTK/Math/Vector2.cs +++ b/Source/OpenTK/Math/Vector2.cs @@ -27,9 +27,7 @@ using System.Runtime.InteropServices; namespace OpenTK.Math { - /// - /// Represents a 2D vector. - /// + /// Represents a 2D vector using two single-precision floating-point numbers. /// /// The Vector2 structure is suitable for interoperation with unmanaged code requiring two consecutive floats. /// @@ -562,7 +560,7 @@ namespace OpenTK.Math #region Dot /// - /// Caclulate the dot (scalar) product of two vectors + /// Calculate the dot (scalar) product of two vectors /// /// First operand /// Second operand @@ -572,6 +570,17 @@ namespace OpenTK.Math return left.X * right.X + left.Y * right.Y; } + /// + /// Calculate the dot (scalar) product of two vectors + /// + /// First operand + /// Second operand + /// The dot product of the two inputs + 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 /// /// First input vector /// Second input vector - /// The blend factor + /// The blend factor. a when blend=0, b when blend=1. /// a when blend=0, b when blend=1, and a linear combination otherwise public static Vector2 Lerp(Vector2 a, Vector2 b, float blend) { @@ -590,6 +599,19 @@ namespace OpenTK.Math return a; } + /// + /// Returns a new Vector that is the linear blend of the 2 given Vectors + /// + /// First input vector + /// Second input vector + /// The blend factor. a when blend=0, b when blend=1. + /// a when blend=0, b when blend=1, and a linear combination otherwise + 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 diff --git a/Source/OpenTK/Math/Vector2d.cs b/Source/OpenTK/Math/Vector2d.cs index bf9f9a54803f97cc3e8f8450da3660e9d74b277c..1b1ac53c08ee1c1eba49c2eaada59b9017f16bf1 100644 GIT binary patch delta 359 zcmZ3tlIg{6rVTqd8G|Ovw~J~fGAJ+@F}MK9GKN%!WQG!ke1;+*uau#fA(J7GAsxsr zVJK(FpZuQFlu>uHDpzC54MF;D)$Z#H?Crwou&z&P1JL}IdBu*77y0=vn} z^xW88fJT)tXiOH=mz^xo!ZSH6R%)_d3zxbM(8zqC1tmZ_1`^~dTBA7r9*c?~%j}ay}NyKAv zo}R$uStT8lE2$?HlbCM(&NOlB(+5>;SGV$frV z0J=aIh!Y{~$(m)lK>PV7U$Er>sgj4NibPTcVrv4iHb~dxKx6626J*0S>ypQn8B!QB8FCp?8S)s4fvkKWoyd>_lq&;@B{P%&MT&sD zQm||uL;B?JoTiKln{~MwQ<#$(ayD - /// Represents a three-dimensional vector. - /// + /// Represents a 3D vector using three single-precision floating-point numbers. + /// + /// The Vector3 structure is suitable for interoperation with unmanaged code requiring three consecutive floats. + /// [Serializable] [StructLayout(LayoutKind.Sequential)] public struct Vector3 : IEquatable @@ -563,7 +564,7 @@ namespace OpenTK.Math #region Dot /// - /// Caclulate the dot (scalar) product of two vectors + /// Calculate the dot (scalar) product of two vectors /// /// First operand /// Second operand @@ -573,6 +574,17 @@ namespace OpenTK.Math return left.X * right.X + left.Y * right.Y + left.Z * right.Z; } + /// + /// Calculate the dot (scalar) product of two vectors + /// + /// First operand + /// Second operand + /// The dot product of the two inputs + 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 /// The cross product of the two inputs 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); } /// @@ -618,7 +625,7 @@ namespace OpenTK.Math /// /// First input vector /// Second input vector - /// The blend factor + /// The blend factor. a when blend=0, b when blend=1. /// a when blend=0, b when blend=1, and a linear combination otherwise public static Vector3 Lerp(Vector3 a, Vector3 b, float blend) { @@ -628,6 +635,20 @@ namespace OpenTK.Math return a; } + /// + /// Returns a new Vector that is the linear blend of the 2 given Vectors + /// + /// First input vector + /// Second input vector + /// The blend factor. a when blend=0, b when blend=1. + /// a when blend=0, b when blend=1, and a linear combination otherwise + 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 diff --git a/Source/OpenTK/Math/Vector3d.cs b/Source/OpenTK/Math/Vector3d.cs index 9558639662e45b92ca7f1a99d0755dd26dcf0cdf..86beac1709c36d02b6c01beddc2156aff20bba40 100644 GIT binary patch delta 459 zcmZ2=lKIkY<_+68or4%s844JRfMhWc=P{H3X$6KvAU0-j0g`1v(PW@#K2VJULn%-; z6R0X3$Sz^X0P9Pg{Fc*{QFpU4*Ve|#b}15@KXjWgPZG44Y?C4dWEU__-cW8ZxuVx@ za^G|}P8Xm_B@7x23X=mXq$lsonWQ%P!zuwV4x7R^`PL+X$rh9S;9`?zx=k*+Vgz)_ z=3V_fOp{`5Hv3KYVrA9?nt64O?c`6#4JKa*5SZ+>m~ZowIm?(P37SoIxGAuC)vR}n zNQyir*SQKzzBZ?0vYD?Nw-3;PMZf@qd0>MR+vGiV3X@;Wm6$Bosl^C#uJ>f8c|!6E zK=0@=L;$^`3&e>~wkD9R4dPD@Ot%E76NRXYL{bN2Pd+$Lcd~)I*yLYu6;Vhkfb7Y# M^Hnz&%(rp{0D~Ek761SM delta 228 zcmca~n|akq<_+68%^evO7>pTo8B!QB8FCp?8S)s4fvkKWoyd>_lq&;@B{P%&MT&sD zQm||uL;B>OoTiKloAtT2Hcob!A+h;Sw+ZuPfgGF74wLzqCp$FqOm?_f6+xwFN4vn5-x) z59D!iMuIc|aV1F%?$p-yan;m9MV4r-dP;axtf+I{|SG-&C#03Bb CpGaZ= diff --git a/Source/OpenTK/Math/Vector4.cs b/Source/OpenTK/Math/Vector4.cs index 18d68d75..cd52aa0b 100644 --- a/Source/OpenTK/Math/Vector4.cs +++ b/Source/OpenTK/Math/Vector4.cs @@ -27,9 +27,10 @@ using System.Runtime.InteropServices; namespace OpenTK.Math { - /// - /// Represents a four-dimensional vector. - /// + /// Represents a 4D vector using four single-precision floating-point numbers. + /// + /// The Vector4 structure is suitable for interoperation with unmanaged code requiring four consecutive floats. + /// [Serializable] [StructLayout(LayoutKind.Sequential)] public struct Vector4 : IEquatable @@ -566,7 +567,7 @@ namespace OpenTK.Math #region Dot /// - /// Caclulate the dot product of two vectors + /// Calculate the dot product of two vectors /// /// First operand /// Second operand @@ -576,6 +577,19 @@ namespace OpenTK.Math return left.X * right.X + left.Y * right.Y + left.Z * right.Z + left.W * right.W; } + /// + /// Calculate the dot product of two vectors + /// + /// First operand + /// Second operand + /// The dot product of the two inputs + 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 /// /// First input vector /// Second input vector - /// The blend factor + /// The blend factor. a when blend=0, b when blend=1. /// a when blend=0, b when blend=1, and a linear combination otherwise public static Vector4 Lerp(Vector4 a, Vector4 b, float blend) { @@ -596,6 +610,21 @@ namespace OpenTK.Math return a; } + /// + /// Returns a new Vector that is the linear blend of the 2 given Vectors + /// + /// First input vector + /// Second input vector + /// The blend factor. a when blend=0, b when blend=1. + /// a when blend=0, b when blend=1, and a linear combination otherwise + 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 diff --git a/Source/OpenTK/Math/Vector4d.cs b/Source/OpenTK/Math/Vector4d.cs index 8a09c2c3..b0a9eb75 100644 --- a/Source/OpenTK/Math/Vector4d.cs +++ b/Source/OpenTK/Math/Vector4d.cs @@ -27,12 +27,12 @@ using System.Runtime.InteropServices; namespace OpenTK.Math { - /// A 4-dimensional vector using double-precision floating point numbers. + /// Represents a 4D vector using four double-precision floating-point numbers. [Serializable] [StructLayout(LayoutKind.Sequential)] public struct Vector4d : IEquatable { - #region Fields + #region Fields /// /// The X component of the Vector4d. @@ -564,7 +564,7 @@ namespace OpenTK.Math #region Dot /// - /// Caclulate the dot product of two vectors + /// Calculate the dot product of two vectors /// /// First operand /// Second operand @@ -574,6 +574,17 @@ namespace OpenTK.Math return left.X * right.X + left.Y * right.Y + left.Z * right.Z + left.W * right.W; } + /// + /// Calculate the dot product of two vectors + /// + /// First operand + /// Second operand + /// The dot product of the two inputs + 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 /// /// First input vector /// Second input vector - /// The blend factor + /// The blend factor. a when blend=0, b when blend=1. /// a when blend=0, b when blend=1, and a linear combination otherwise public static Vector4d Lerp(Vector4d a, Vector4d b, double blend) { @@ -594,6 +605,21 @@ namespace OpenTK.Math return a; } + /// + /// Returns a new Vector that is the linear blend of the 2 given Vectors + /// + /// First input vector + /// Second input vector + /// The blend factor. a when blend=0, b when blend=1. + /// a when blend=0, b when blend=1, and a linear combination otherwise + 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