diff options
Diffstat (limited to 'indra/llmath')
-rw-r--r-- | indra/llmath/llmath.h | 3 | ||||
-rw-r--r-- | indra/llmath/llvolumemgr.cpp | 4 | ||||
-rw-r--r-- | indra/llmath/llvolumemgr.h | 2 | ||||
-rw-r--r-- | indra/llmath/v3dmath.h | 46 |
4 files changed, 47 insertions, 8 deletions
diff --git a/indra/llmath/llmath.h b/indra/llmath/llmath.h index bf98801508..9d31df12e2 100644 --- a/indra/llmath/llmath.h +++ b/indra/llmath/llmath.h @@ -92,6 +92,9 @@ const F32 F_APPROXIMATELY_ZERO = 0.00001f; const F32 F_LN2 = 0.69314718056f; const F32 OO_LN2 = 1.4426950408889634073599246810019f; +const F32 F_ALMOST_ZERO = 0.0001f; +const F32 F_ALMOST_ONE = 1.0f - F_ALMOST_ZERO; + // BUG: Eliminate in favor of F_APPROXIMATELY_ZERO above? const F32 FP_MAG_THRESHOLD = 0.0000001f; diff --git a/indra/llmath/llvolumemgr.cpp b/indra/llmath/llvolumemgr.cpp index 23ed0183b8..c4f10467a9 100644 --- a/indra/llmath/llvolumemgr.cpp +++ b/indra/llmath/llvolumemgr.cpp @@ -115,7 +115,7 @@ LLVolume* LLVolumeMgr::refVolume(const LLVolumeParams &volume_params, const S32 { mDataMutex->unlock(); } - return volgroupp->getLODVolume(detail); + return volgroupp->refLOD(detail); } // virtual @@ -294,7 +294,7 @@ bool LLVolumeLODGroup::cleanupRefs() return res; } -LLVolume* LLVolumeLODGroup::getLODVolume(const S32 detail) +LLVolume* LLVolumeLODGroup::refLOD(const S32 detail) { llassert(detail >=0 && detail < NUM_LODS); mAccessCount[detail]++; diff --git a/indra/llmath/llvolumemgr.h b/indra/llmath/llvolumemgr.h index fac194165b..f4b44b3a12 100644 --- a/indra/llmath/llvolumemgr.h +++ b/indra/llmath/llvolumemgr.h @@ -59,7 +59,7 @@ public: static void getDetailProximity(const F32 tan_angle, F32 &to_lower, F32& to_higher); static F32 getVolumeScaleFromDetail(const S32 detail); - LLVolume* getLODVolume(const S32 detail); + LLVolume* refLOD(const S32 detail); BOOL derefLOD(LLVolume *volumep); S32 getNumRefs() const { return mRefs; } diff --git a/indra/llmath/v3dmath.h b/indra/llmath/v3dmath.h index 667c335f51..d5e5223571 100644 --- a/indra/llmath/v3dmath.h +++ b/indra/llmath/v3dmath.h @@ -95,6 +95,10 @@ class LLVector3d F64 magVecSquared() const; // Returns magnitude squared of LLVector3d inline F64 normVec(); // Normalizes and returns the magnitude of LLVector3d + F64 length() const; // Returns magnitude of LLVector3d + F64 lengthSquared() const; // Returns magnitude squared of LLVector3d + inline F64 normalize(); // Normalizes and returns the magnitude of LLVector3d + const LLVector3d& rotVec(const F64 angle, const LLVector3d &vec); // Rotates about vec by angle radians const LLVector3d& rotVec(const F64 angle, const F64 x, const F64 y, const F64 z); // Rotates about x,y,z by angle radians const LLVector3d& rotVec(const LLMatrix3 &mat); // Rotates by LLMatrix4 mat @@ -261,6 +265,28 @@ inline F64 LLVector3d::normVec(void) return (mag); } +inline F64 LLVector3d::normalize(void) +{ + F64 mag = fsqrtf(mdV[0]*mdV[0] + mdV[1]*mdV[1] + mdV[2]*mdV[2]); + F64 oomag; + + if (mag > FP_MAG_THRESHOLD) + { + oomag = 1.f/mag; + mdV[0] *= oomag; + mdV[1] *= oomag; + mdV[2] *= oomag; + } + else + { + mdV[0] = 0.f; + mdV[1] = 0.f; + mdV[2] = 0.f; + mag = 0; + } + return (mag); +} + // LLVector3d Magnitude and Normalization Functions inline F64 LLVector3d::magVec(void) const @@ -273,6 +299,16 @@ inline F64 LLVector3d::magVecSquared(void) const return mdV[0]*mdV[0] + mdV[1]*mdV[1] + mdV[2]*mdV[2]; } +inline F64 LLVector3d::length(void) const +{ + return fsqrtf(mdV[0]*mdV[0] + mdV[1]*mdV[1] + mdV[2]*mdV[2]); +} + +inline F64 LLVector3d::lengthSquared(void) const +{ + return mdV[0]*mdV[0] + mdV[1]*mdV[1] + mdV[2]*mdV[2]; +} + inline LLVector3d operator+(const LLVector3d &a, const LLVector3d &b) { LLVector3d c(a); @@ -416,8 +452,8 @@ inline F64 angle_between(const LLVector3d& a, const LLVector3d& b) { LLVector3d an = a; LLVector3d bn = b; - an.normVec(); - bn.normVec(); + an.normalize(); + bn.normalize(); F64 cosine = an * bn; F64 angle = (cosine >= 1.0f) ? 0.0f : (cosine <= -1.0f) ? F_PI : @@ -429,8 +465,8 @@ inline BOOL are_parallel(const LLVector3d &a, const LLVector3d &b, const F64 eps { LLVector3d an = a; LLVector3d bn = b; - an.normVec(); - bn.normVec(); + an.normalize(); + bn.normalize(); F64 dot = an * bn; if ( (1.0f - fabs(dot)) < epsilon) { @@ -443,7 +479,7 @@ inline BOOL are_parallel(const LLVector3d &a, const LLVector3d &b, const F64 eps inline LLVector3d projected_vec(const LLVector3d &a, const LLVector3d &b) { LLVector3d project_axis = b; - project_axis.normVec(); + project_axis.normalize(); return project_axis * (a * project_axis); } |