aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llmath/v3dmath.h
diff options
context:
space:
mode:
authorJacek Antonelli2008-09-06 18:24:57 -0500
committerJacek Antonelli2008-09-06 18:25:07 -0500
commit798d367d54a6c6379ad355bd8345fa40e31e7fe9 (patch)
tree1921f1708cd0240648c97bc02df2c2ab5f2fc41e /linden/indra/llmath/v3dmath.h
parentSecond Life viewer sources 1.20.15 (diff)
downloadmeta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.zip
meta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.tar.gz
meta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.tar.bz2
meta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.tar.xz
Second Life viewer sources 1.21.0-RC
Diffstat (limited to 'linden/indra/llmath/v3dmath.h')
-rw-r--r--linden/indra/llmath/v3dmath.h48
1 files changed, 42 insertions, 6 deletions
diff --git a/linden/indra/llmath/v3dmath.h b/linden/indra/llmath/v3dmath.h
index 9bd80b8..ecb333a 100644
--- a/linden/indra/llmath/v3dmath.h
+++ b/linden/indra/llmath/v3dmath.h
@@ -95,6 +95,10 @@ class LLVector3d
95 F64 magVecSquared() const; // Returns magnitude squared of LLVector3d 95 F64 magVecSquared() const; // Returns magnitude squared of LLVector3d
96 inline F64 normVec(); // Normalizes and returns the magnitude of LLVector3d 96 inline F64 normVec(); // Normalizes and returns the magnitude of LLVector3d
97 97
98 F64 length() const; // Returns magnitude of LLVector3d
99 F64 lengthSquared() const; // Returns magnitude squared of LLVector3d
100 inline F64 normalize(); // Normalizes and returns the magnitude of LLVector3d
101
98 const LLVector3d& rotVec(const F64 angle, const LLVector3d &vec); // Rotates about vec by angle radians 102 const LLVector3d& rotVec(const F64 angle, const LLVector3d &vec); // Rotates about vec by angle radians
99 const LLVector3d& rotVec(const F64 angle, const F64 x, const F64 y, const F64 z); // Rotates about x,y,z by angle radians 103 const LLVector3d& rotVec(const F64 angle, const F64 x, const F64 y, const F64 z); // Rotates about x,y,z by angle radians
100 const LLVector3d& rotVec(const LLMatrix3 &mat); // Rotates by LLMatrix4 mat 104 const LLVector3d& rotVec(const LLMatrix3 &mat); // Rotates by LLMatrix4 mat
@@ -128,7 +132,7 @@ class LLVector3d
128 132
129 friend std::ostream& operator<<(std::ostream& s, const LLVector3d &a); // Stream a 133 friend std::ostream& operator<<(std::ostream& s, const LLVector3d &a); // Stream a
130 134
131 static BOOL parseVector3d(const char* buf, LLVector3d* value); 135 static BOOL parseVector3d(const std::string& buf, LLVector3d* value);
132 136
133}; 137};
134 138
@@ -261,6 +265,28 @@ inline F64 LLVector3d::normVec(void)
261 return (mag); 265 return (mag);
262} 266}
263 267
268inline F64 LLVector3d::normalize(void)
269{
270 F64 mag = fsqrtf(mdV[0]*mdV[0] + mdV[1]*mdV[1] + mdV[2]*mdV[2]);
271 F64 oomag;
272
273 if (mag > FP_MAG_THRESHOLD)
274 {
275 oomag = 1.f/mag;
276 mdV[0] *= oomag;
277 mdV[1] *= oomag;
278 mdV[2] *= oomag;
279 }
280 else
281 {
282 mdV[0] = 0.f;
283 mdV[1] = 0.f;
284 mdV[2] = 0.f;
285 mag = 0;
286 }
287 return (mag);
288}
289
264// LLVector3d Magnitude and Normalization Functions 290// LLVector3d Magnitude and Normalization Functions
265 291
266inline F64 LLVector3d::magVec(void) const 292inline F64 LLVector3d::magVec(void) const
@@ -273,6 +299,16 @@ inline F64 LLVector3d::magVecSquared(void) const
273 return mdV[0]*mdV[0] + mdV[1]*mdV[1] + mdV[2]*mdV[2]; 299 return mdV[0]*mdV[0] + mdV[1]*mdV[1] + mdV[2]*mdV[2];
274} 300}
275 301
302inline F64 LLVector3d::length(void) const
303{
304 return fsqrtf(mdV[0]*mdV[0] + mdV[1]*mdV[1] + mdV[2]*mdV[2]);
305}
306
307inline F64 LLVector3d::lengthSquared(void) const
308{
309 return mdV[0]*mdV[0] + mdV[1]*mdV[1] + mdV[2]*mdV[2];
310}
311
276inline LLVector3d operator+(const LLVector3d &a, const LLVector3d &b) 312inline LLVector3d operator+(const LLVector3d &a, const LLVector3d &b)
277{ 313{
278 LLVector3d c(a); 314 LLVector3d c(a);
@@ -416,8 +452,8 @@ inline F64 angle_between(const LLVector3d& a, const LLVector3d& b)
416{ 452{
417 LLVector3d an = a; 453 LLVector3d an = a;
418 LLVector3d bn = b; 454 LLVector3d bn = b;
419 an.normVec(); 455 an.normalize();
420 bn.normVec(); 456 bn.normalize();
421 F64 cosine = an * bn; 457 F64 cosine = an * bn;
422 F64 angle = (cosine >= 1.0f) ? 0.0f : 458 F64 angle = (cosine >= 1.0f) ? 0.0f :
423 (cosine <= -1.0f) ? F_PI : 459 (cosine <= -1.0f) ? F_PI :
@@ -429,8 +465,8 @@ inline BOOL are_parallel(const LLVector3d &a, const LLVector3d &b, const F64 eps
429{ 465{
430 LLVector3d an = a; 466 LLVector3d an = a;
431 LLVector3d bn = b; 467 LLVector3d bn = b;
432 an.normVec(); 468 an.normalize();
433 bn.normVec(); 469 bn.normalize();
434 F64 dot = an * bn; 470 F64 dot = an * bn;
435 if ( (1.0f - fabs(dot)) < epsilon) 471 if ( (1.0f - fabs(dot)) < epsilon)
436 { 472 {
@@ -443,7 +479,7 @@ inline BOOL are_parallel(const LLVector3d &a, const LLVector3d &b, const F64 eps
443inline LLVector3d projected_vec(const LLVector3d &a, const LLVector3d &b) 479inline LLVector3d projected_vec(const LLVector3d &a, const LLVector3d &b)
444{ 480{
445 LLVector3d project_axis = b; 481 LLVector3d project_axis = b;
446 project_axis.normVec(); 482 project_axis.normalize();
447 return project_axis * (a * project_axis); 483 return project_axis * (a * project_axis);
448} 484}
449 485