aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llmath/v3math.h
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:45:42 -0500
committerJacek Antonelli2008-08-15 23:45:42 -0500
commitce28e056c20bf2723f565bbf464b87781ec248a2 (patch)
treeef7b0501c4de4b631a916305cbc2a5fdc125e52d /linden/indra/llmath/v3math.h
parentSecond Life viewer sources 1.19.1.4b (diff)
downloadmeta-impy-ce28e056c20bf2723f565bbf464b87781ec248a2.zip
meta-impy-ce28e056c20bf2723f565bbf464b87781ec248a2.tar.gz
meta-impy-ce28e056c20bf2723f565bbf464b87781ec248a2.tar.bz2
meta-impy-ce28e056c20bf2723f565bbf464b87781ec248a2.tar.xz
Second Life viewer sources 1.20.2
Diffstat (limited to 'linden/indra/llmath/v3math.h')
-rw-r--r--linden/indra/llmath/v3math.h123
1 files changed, 108 insertions, 15 deletions
diff --git a/linden/indra/llmath/v3math.h b/linden/indra/llmath/v3math.h
index f1c1b39..ddb5e1f 100644
--- a/linden/indra/llmath/v3math.h
+++ b/linden/indra/llmath/v3math.h
@@ -81,18 +81,33 @@ class LLVector3
81 81
82 BOOL abs(); // sets all values to absolute value of original value (first octant), returns TRUE if changed 82 BOOL abs(); // sets all values to absolute value of original value (first octant), returns TRUE if changed
83 83
84 inline void clearVec(); // Clears LLVector3 to (0, 0, 0, 1) 84 inline void clear(); // Clears LLVector3 to (0, 0, 0)
85 inline void zeroVec(); // Zero LLVector3 to (0, 0, 0, 0) 85 inline void setZero(); // Clears LLVector3 to (0, 0, 0)
86 inline void setVec(F32 x, F32 y, F32 z); // Sets LLVector3 to (x, y, z, 1) 86 inline void clearVec(); // deprecated
87 inline void setVec(const LLVector3 &vec); // Sets LLVector3 to vec 87 inline void zeroVec(); // deprecated
88 inline void setVec(const F32 *vec); // Sets LLVector3 to vec
89 88
90 const LLVector3& setVec(const LLVector4 &vec); 89 inline void set(F32 x, F32 y, F32 z); // Sets LLVector3 to (x, y, z, 1)
91 const LLVector3& setVec(const LLVector3d &vec); // Sets LLVector3 to vec 90 inline void set(const LLVector3 &vec); // Sets LLVector3 to vec
91 inline void set(const F32 *vec); // Sets LLVector3 to vec
92 const LLVector3& set(const LLVector4 &vec);
93 const LLVector3& set(const LLVector3d &vec);// Sets LLVector3 to vec
92 94
93 F32 magVec() const; // Returns magnitude of LLVector3 95 inline void setVec(F32 x, F32 y, F32 z); // deprecated
94 F32 magVecSquared() const; // Returns magnitude squared of LLVector3 96 inline void setVec(const LLVector3 &vec); // deprecated
95 inline F32 normVec(); // Normalizes and returns the magnitude of LLVector3 97 inline void setVec(const F32 *vec); // deprecated
98
99 const LLVector3& setVec(const LLVector4 &vec); // deprecated
100 const LLVector3& setVec(const LLVector3d &vec); // deprecated
101
102 F32 length() const; // Returns magnitude of LLVector3
103 F32 lengthSquared() const; // Returns magnitude squared of LLVector3
104 F32 magVec() const; // deprecated
105 F32 magVecSquared() const; // deprecated
106
107 inline F32 normalize(); // Normalizes and returns the magnitude of LLVector3
108 inline F32 normVec(); // deprecated
109
110 inline BOOL inRange( F32 min, F32 max ) const; // Returns true if all values of the vector are between min and max
96 111
97 const LLVector3& rotVec(F32 angle, const LLVector3 &vec); // Rotates about vec by angle radians 112 const LLVector3& rotVec(F32 angle, const LLVector3 &vec); // Rotates about vec by angle radians
98 const LLVector3& rotVec(F32 angle, F32 x, F32 y, F32 z); // Rotates about x,y,z by angle radians 113 const LLVector3& rotVec(F32 angle, F32 x, F32 y, F32 z); // Rotates about x,y,z by angle radians
@@ -188,6 +203,20 @@ inline BOOL LLVector3::isFinite() const
188 203
189// Clear and Assignment Functions 204// Clear and Assignment Functions
190 205
206inline void LLVector3::clear(void)
207{
208 mV[0] = 0.f;
209 mV[1] = 0.f;
210 mV[2] = 0.f;
211}
212
213inline void LLVector3::setZero(void)
214{
215 mV[0] = 0.f;
216 mV[1] = 0.f;
217 mV[2] = 0.f;
218}
219
191inline void LLVector3::clearVec(void) 220inline void LLVector3::clearVec(void)
192{ 221{
193 mV[0] = 0.f; 222 mV[0] = 0.f;
@@ -202,6 +231,28 @@ inline void LLVector3::zeroVec(void)
202 mV[2] = 0.f; 231 mV[2] = 0.f;
203} 232}
204 233
234inline void LLVector3::set(F32 x, F32 y, F32 z)
235{
236 mV[VX] = x;
237 mV[VY] = y;
238 mV[VZ] = z;
239}
240
241inline void LLVector3::set(const LLVector3 &vec)
242{
243 mV[0] = vec.mV[0];
244 mV[1] = vec.mV[1];
245 mV[2] = vec.mV[2];
246}
247
248inline void LLVector3::set(const F32 *vec)
249{
250 mV[0] = vec[0];
251 mV[1] = vec[1];
252 mV[2] = vec[2];
253}
254
255// deprecated
205inline void LLVector3::setVec(F32 x, F32 y, F32 z) 256inline void LLVector3::setVec(F32 x, F32 y, F32 z)
206{ 257{
207 mV[VX] = x; 258 mV[VX] = x;
@@ -209,6 +260,7 @@ inline void LLVector3::setVec(F32 x, F32 y, F32 z)
209 mV[VZ] = z; 260 mV[VZ] = z;
210} 261}
211 262
263// deprecated
212inline void LLVector3::setVec(const LLVector3 &vec) 264inline void LLVector3::setVec(const LLVector3 &vec)
213{ 265{
214 mV[0] = vec.mV[0]; 266 mV[0] = vec.mV[0];
@@ -216,6 +268,7 @@ inline void LLVector3::setVec(const LLVector3 &vec)
216 mV[2] = vec.mV[2]; 268 mV[2] = vec.mV[2];
217} 269}
218 270
271// deprecated
219inline void LLVector3::setVec(const F32 *vec) 272inline void LLVector3::setVec(const F32 *vec)
220{ 273{
221 mV[0] = vec[0]; 274 mV[0] = vec[0];
@@ -223,6 +276,29 @@ inline void LLVector3::setVec(const F32 *vec)
223 mV[2] = vec[2]; 276 mV[2] = vec[2];
224} 277}
225 278
279inline F32 LLVector3::normalize(void)
280{
281 F32 mag = fsqrtf(mV[0]*mV[0] + mV[1]*mV[1] + mV[2]*mV[2]);
282 F32 oomag;
283
284 if (mag > FP_MAG_THRESHOLD)
285 {
286 oomag = 1.f/mag;
287 mV[0] *= oomag;
288 mV[1] *= oomag;
289 mV[2] *= oomag;
290 }
291 else
292 {
293 mV[0] = 0.f;
294 mV[1] = 0.f;
295 mV[2] = 0.f;
296 mag = 0;
297 }
298 return (mag);
299}
300
301// deprecated
226inline F32 LLVector3::normVec(void) 302inline F32 LLVector3::normVec(void)
227{ 303{
228 F32 mag = fsqrtf(mV[0]*mV[0] + mV[1]*mV[1] + mV[2]*mV[2]); 304 F32 mag = fsqrtf(mV[0]*mV[0] + mV[1]*mV[1] + mV[2]*mV[2]);
@@ -247,6 +323,16 @@ inline F32 LLVector3::normVec(void)
247 323
248// LLVector3 Magnitude and Normalization Functions 324// LLVector3 Magnitude and Normalization Functions
249 325
326inline F32 LLVector3::length(void) const
327{
328 return fsqrtf(mV[0]*mV[0] + mV[1]*mV[1] + mV[2]*mV[2]);
329}
330
331inline F32 LLVector3::lengthSquared(void) const
332{
333 return mV[0]*mV[0] + mV[1]*mV[1] + mV[2]*mV[2];
334}
335
250inline F32 LLVector3::magVec(void) const 336inline F32 LLVector3::magVec(void) const
251{ 337{
252 return fsqrtf(mV[0]*mV[0] + mV[1]*mV[1] + mV[2]*mV[2]); 338 return fsqrtf(mV[0]*mV[0] + mV[1]*mV[1] + mV[2]*mV[2]);
@@ -257,6 +343,13 @@ inline F32 LLVector3::magVecSquared(void) const
257 return mV[0]*mV[0] + mV[1]*mV[1] + mV[2]*mV[2]; 343 return mV[0]*mV[0] + mV[1]*mV[1] + mV[2]*mV[2];
258} 344}
259 345
346inline BOOL LLVector3::inRange( F32 min, F32 max ) const
347{
348 return mV[0] >= min && mV[0] <= max &&
349 mV[1] >= min && mV[1] <= max &&
350 mV[2] >= min && mV[2] <= max;
351}
352
260inline LLVector3 operator+(const LLVector3 &a, const LLVector3 &b) 353inline LLVector3 operator+(const LLVector3 &a, const LLVector3 &b)
261{ 354{
262 LLVector3 c(a); 355 LLVector3 c(a);
@@ -397,7 +490,7 @@ inline F32 dist_vec_squared2D(const LLVector3 &a, const LLVector3 &b)
397inline LLVector3 projected_vec(const LLVector3 &a, const LLVector3 &b) 490inline LLVector3 projected_vec(const LLVector3 &a, const LLVector3 &b)
398{ 491{
399 LLVector3 project_axis = b; 492 LLVector3 project_axis = b;
400 project_axis.normVec(); 493 project_axis.normalize();
401 return project_axis * (a * project_axis); 494 return project_axis * (a * project_axis);
402} 495}
403 496
@@ -438,8 +531,8 @@ inline F32 angle_between(const LLVector3& a, const LLVector3& b)
438{ 531{
439 LLVector3 an = a; 532 LLVector3 an = a;
440 LLVector3 bn = b; 533 LLVector3 bn = b;
441 an.normVec(); 534 an.normalize();
442 bn.normVec(); 535 bn.normalize();
443 F32 cosine = an * bn; 536 F32 cosine = an * bn;
444 F32 angle = (cosine >= 1.0f) ? 0.0f : 537 F32 angle = (cosine >= 1.0f) ? 0.0f :
445 (cosine <= -1.0f) ? F_PI : 538 (cosine <= -1.0f) ? F_PI :
@@ -451,8 +544,8 @@ inline BOOL are_parallel(const LLVector3 &a, const LLVector3 &b, F32 epsilon)
451{ 544{
452 LLVector3 an = a; 545 LLVector3 an = a;
453 LLVector3 bn = b; 546 LLVector3 bn = b;
454 an.normVec(); 547 an.normalize();
455 bn.normVec(); 548 bn.normalize();
456 F32 dot = an * bn; 549 F32 dot = an * bn;
457 if ( (1.0f - fabs(dot)) < epsilon) 550 if ( (1.0f - fabs(dot)) < epsilon)
458 { 551 {