From 49e132911d34ba03746cc75841d3b5bac1c2311f Mon Sep 17 00:00:00 2001 From: chrisbrandtner Date: Fri, 23 Jan 2009 21:55:21 +0000 Subject: [PATCH] Added instance methods to all single and double precision Vector structs: Add(ref vec) Sub(ref vec) Mult(float) Div(float) Scale(ref vec) --- Source/OpenTK/Math/Vector2.cs | 61 ++++++++++++++++++++++++++- Source/OpenTK/Math/Vector2d.cs | Bin 40424 -> 43950 bytes Source/OpenTK/Math/Vector3.cs | 66 ++++++++++++++++++++++++++++- Source/OpenTK/Math/Vector3d.cs | Bin 60882 -> 64714 bytes Source/OpenTK/Math/Vector4.cs | 75 +++++++++++++++++++++++++++++++-- Source/OpenTK/Math/Vector4d.cs | 73 ++++++++++++++++++++++++++++++-- 6 files changed, 264 insertions(+), 11 deletions(-) diff --git a/Source/OpenTK/Math/Vector2.cs b/Source/OpenTK/Math/Vector2.cs index e4a98ae7..6d78ea61 100644 --- a/Source/OpenTK/Math/Vector2.cs +++ b/Source/OpenTK/Math/Vector2.cs @@ -101,6 +101,55 @@ namespace OpenTK.Math #region Instance + #region public void Add() + + /// Add the Vector passed as parameter to this instance. + /// Right operand. This parameter is only read from. + public void Add( ref Vector2 right ) + { + this.X += right.X; + this.Y += right.Y; + } + + #endregion public void Add() + + #region public void Sub() + + /// Subtract the Vector passed as parameter from this instance. + /// Right operand. This parameter is only read from. + public void Sub( ref Vector2 right ) + { + this.X -= right.X; + this.Y -= right.Y; + } + + #endregion public void Sub() + + #region public void Mult() + + /// Multiply this instance by a scalar. + /// Scalar operand. + public void Mult( float f ) + { + this.X *= f; + this.Y *= f; + } + + #endregion public void Mult() + + #region public void Div() + + /// Divide this instance by a scalar. + /// Scalar operand. + public void Div( float f ) + { + float mult = 1.0f / f; + this.X *= mult; + this.Y *= mult; + } + + #endregion public void Div() + #region public float Length /// @@ -219,7 +268,7 @@ namespace OpenTK.Math #endregion - #region public void Scale(float sx, float sy) + #region public void Scale() /// /// Scales the current Vector2 by the given amounts. @@ -232,7 +281,15 @@ namespace OpenTK.Math this.Y = Y * sy; } - #endregion + /// Scales this instance by the given parameter. + /// The scaling of the individual components. + public void Scale( ref Vector2 scale ) + { + this.X *= scale.X; + this.Y *= scale.Y; + } + + #endregion public void Scale() #endregion diff --git a/Source/OpenTK/Math/Vector2d.cs b/Source/OpenTK/Math/Vector2d.cs index 1b1ac53c08ee1c1eba49c2eaada59b9017f16bf1..0e41b703d779f43afedc09d30ec5c190c87b61c0 100644 GIT binary patch delta 998 zcmc&yO-~bH5T0TT(l+hdu*Eh)SK3gjp`xg8K$1-g;UGauO}G%#+7DNYi|y8w8=Pvu zL&IZ;Y5W142n23iiANJpdX&V2M??Gp&b!;))MyMhvw1g@`FduaXTBeI?S1are;7n7 z=Dw&>p7J<|j<+p;tZzi2RmxJ8zXC@U)3$sSwpZ9|@T+jdARUpNe*E-Y$NKXazUtoP zG-*_#ryNsA=T0IsOE0)nl06xYXx#bl{j7-2*=1VeoC;TG%^8Yp>$HM}dK~+buVeOk zBZ7g38z;uSZo}%1>Bcp@&s@Qb?7MJ-?nA9TLNX+ER2@Y7p@arZ&mz?*Cpf^_SO9@o z@2&GQV9)jcSg@w=V8P#Jf%#ry4o5K82-$4l-Rm&iqf-tW_U;ZF_%Z3mQS^>~j#(+Q ziW+OkYOu}`e4Gm6Tk8QnObjAjAF`D&Yi@4_Tne%`?>Z_hY{~dCY^s3zmJdrc2e*w9 zwl#p1x+G9NDaL!nFHePkB8q$q@nve+Rm7*^h=Z%DV?ufCzUf6%m9Q!&?S0!g0(au@ zS@0x)=Hswuk)H6GmHF7J0yL2`k5AB8U;<0#NCiI1KaList@)m+U5(SYoX|M0#F;u3 z`EU0S-n_F~O`u^TF1xCo2MzC#7ir_F$LUDF6M8w(J-3R KlZQKrwDAj9Fby04 delta 27 jcmZ2?o$1AHrVRmNo98Ir6PoOxqBnVikk#fG^Pmy{t%wU_ diff --git a/Source/OpenTK/Math/Vector3.cs b/Source/OpenTK/Math/Vector3.cs index c6ed429a..c7446cd9 100644 --- a/Source/OpenTK/Math/Vector3.cs +++ b/Source/OpenTK/Math/Vector3.cs @@ -107,6 +107,59 @@ namespace OpenTK.Math #region Public Members #region Instance + + #region public void Add() + + /// Add the Vector passed as parameter to this instance. + /// Right operand. This parameter is only read from. + public void Add( ref Vector3 right ) + { + this.X += right.X; + this.Y += right.Y; + this.Z += right.Z; + } + + #endregion public void Add() + + #region public void Sub() + + /// Subtract the Vector passed as parameter from this instance. + /// Right operand. This parameter is only read from. + public void Sub( ref Vector3 right ) + { + this.X -= right.X; + this.Y -= right.Y; + this.Z -= right.Z; + } + + #endregion public void Sub() + + #region public void Mult() + + /// Multiply this instance by a scalar. + /// Scalar operand. + public void Mult( float f ) + { + this.X *= f; + this.Y *= f; + this.Z *= f; + } + + #endregion public void Mult() + + #region public void Div() + + /// Divide this instance by a scalar. + /// Scalar operand. + public void Div( float f ) + { + float mult = 1.0f / f; + this.X *= mult; + this.Y *= mult; + this.Z *= mult; + } + + #endregion public void Div() #region public float Length @@ -198,7 +251,7 @@ namespace OpenTK.Math #endregion - #region public void Scale(float sx, float sy, float sz) + #region public void Scale() /// /// Scales the current Vector3 by the given amounts. @@ -213,7 +266,16 @@ namespace OpenTK.Math this.Z = Z * sz; } - #endregion + /// Scales this instance by the given parameter. + /// The scaling of the individual components. + public void Scale( ref Vector3 scale ) + { + this.X *= scale.X; + this.Y *= scale.Y; + this.Z *= scale.Z; + } + + #endregion public void Scale() #endregion diff --git a/Source/OpenTK/Math/Vector3d.cs b/Source/OpenTK/Math/Vector3d.cs index 86beac1709c36d02b6c01beddc2156aff20bba40..0ba6d87a1f16896d9a3067a2016289ce5a1c92f1 100644 GIT binary patch delta 946 zcmb`FL2DCH6oqdHK{G>=G0iw;H0fA{+EQbch@0A45GiURCanc`(P?a9YD$v|x)8hR zO4=r;OBebN3fa1GD+p0Efhu&Pt8Q!;f*|63FU}-jbtOZXlQ)<9&Ufy8_tF3QyMME& zLW^tlN9sxl#i0>AA3ccLb~-RlHreoLMvp}cRG>0HGkj(Vjkh~`z@iG3@a9Xxm%^(< z*U;Dq9bJH9L3kF!fJWy zJhb63zI`z9BYK3j0;`$CGhJ%mZ5(gv__=xxniE4ZuDM;fM0eQh zBHwwJD*s{%T2$n^63zb?E_SdlSFzRMT5ol8Ra<{@wK+Vl0~zLVm}71GLgcsRgcn4% z?7A1({9&HRi$(_P*DYK!(jtw7TX~A}x0z66;_w^BB_-E71-~E8Ad9(I&GVQnM43@JexbG(}OGCH!8psq#wsn)BB{Zt;Dc5 VHsQt_^g8p9Ibdg`K6-ZJAdd the Vector passed as parameter to this instance. + /// Right operand. This parameter is only read from. + public void Add( ref Vector4 right ) + { + this.X += right.X; + this.Y += right.Y; + this.Z += right.Z; + this.W += right.W; + } + + #endregion public void Add() + + #region public void Sub() + + /// Subtract the Vector passed as parameter from this instance. + /// Right operand. This parameter is only read from. + public void Sub( ref Vector4 right ) + { + this.X -= right.X; + this.Y -= right.Y; + this.Z -= right.Z; + this.W -= right.W; + } + + #endregion public void Sub() + + #region public void Mult() + + /// Multiply this instance by a scalar. + /// Scalar operand. + public void Mult( float f ) + { + this.X *= f; + this.Y *= f; + this.Z *= f; + this.W *= f; + } + + #endregion public void Mult() + + #region public void Div() + + /// Divide this instance by a scalar. + /// Scalar operand. + public void Div( float f ) + { + float mult = 1.0f / f; + this.X *= mult; + this.Y *= mult; + this.Z *= mult; + this.W *= mult; + } + + #endregion public void Div() + #region public float Length /// @@ -240,7 +297,7 @@ namespace OpenTK.Math #endregion - #region public void Scale(float sx, float sy, float sz, float sw) + #region public void Scale() /// /// Scales the current Vector4 by the given amounts. @@ -249,15 +306,25 @@ namespace OpenTK.Math /// The scale of the Y component. /// The scale of the Z component. /// The scale of the Z component. - public void Scale(float sx, float sy, float sz, float sw) + public void Scale( float sx, float sy, float sz, float sw ) { this.X = X * sx; this.Y = Y * sy; this.Z = Z * sz; this.W = W * sw; - } + } - #endregion + /// Scales this instance by the given parameter. + /// The scaling of the individual components. + public void Scale( ref Vector4 scale ) + { + this.X *= scale.X; + this.Y *= scale.Y; + this.Z *= scale.Z; + this.W *= scale.W; + } + + #endregion public void Scale() #endregion diff --git a/Source/OpenTK/Math/Vector4d.cs b/Source/OpenTK/Math/Vector4d.cs index b0a9eb75..4a3a60a4 100644 --- a/Source/OpenTK/Math/Vector4d.cs +++ b/Source/OpenTK/Math/Vector4d.cs @@ -145,6 +145,63 @@ namespace OpenTK.Math #region Instance + #region public void Add() + + /// Add the Vector passed as parameter to this instance. + /// Right operand. This parameter is only read from. + public void Add( ref Vector4d right ) + { + this.X += right.X; + this.Y += right.Y; + this.Z += right.Z; + this.W += right.W; + } + + #endregion public void Add() + + #region public void Sub() + + /// Subtract the Vector passed as parameter from this instance. + /// Right operand. This parameter is only read from. + public void Sub( ref Vector4d right ) + { + this.X -= right.X; + this.Y -= right.Y; + this.Z -= right.Z; + this.W -= right.W; + } + + #endregion public void Sub() + + #region public void Mult() + + /// Multiply this instance by a scalar. + /// Scalar operand. + public void Mult( double f ) + { + this.X *= f; + this.Y *= f; + this.Z *= f; + this.W *= f; + } + + #endregion public void Mult() + + #region public void Div() + + /// Divide this instance by a scalar. + /// Scalar operand. + public void Div( double f ) + { + double mult = 1.0 / f; + this.X *= mult; + this.Y *= mult; + this.Z *= mult; + this.W *= mult; + } + + #endregion public void Div() + #region public double Length /// @@ -237,7 +294,7 @@ namespace OpenTK.Math #endregion - #region public void Scale(double sx, double sy, double sz, double sw) + #region public void Scale() /// /// Scales the current Vector4d by the given amounts. @@ -252,9 +309,19 @@ namespace OpenTK.Math this.Y = Y * sy; this.Z = Z * sz; this.W = W * sw; - } + } - #endregion + /// Scales this instance by the given parameter. + /// The scaling of the individual components. + public void Scale( ref Vector4d scale ) + { + this.X *= scale.X; + this.Y *= scale.Y; + this.Z *= scale.Z; + this.W *= scale.W; + } + + #endregion public void Scale() #endregion