diff options
Diffstat (limited to 'indra/llmath/v3math.cpp')
-rw-r--r-- | indra/llmath/v3math.cpp | 141 |
1 files changed, 70 insertions, 71 deletions
diff --git a/indra/llmath/v3math.cpp b/indra/llmath/v3math.cpp index a867b9f578..bd96417190 100644 --- a/indra/llmath/v3math.cpp +++ b/indra/llmath/v3math.cpp @@ -28,7 +28,6 @@ #include "v3math.h" -//#include "vmath.h" #include "v2math.h" #include "v4math.h" #include "m4math.h" @@ -53,27 +52,27 @@ const LLVector3 LLVector3::all_one(1.f,1.f,1.f); // Clamps each values to range (min,max). -// Returns TRUE if data changed. -BOOL LLVector3::clamp(F32 min, F32 max) +// Returns true if data changed. +bool LLVector3::clamp(F32 min, F32 max) { - BOOL ret = FALSE; + bool ret{ false }; - if (mV[0] < min) { mV[0] = min; ret = TRUE; } - if (mV[1] < min) { mV[1] = min; ret = TRUE; } - if (mV[2] < min) { mV[2] = min; ret = TRUE; } + if (mV[VX] < min) { mV[VX] = min; ret = true; } + if (mV[VY] < min) { mV[VY] = min; ret = true; } + if (mV[VZ] < min) { mV[VZ] = min; ret = true; } - if (mV[0] > max) { mV[0] = max; ret = TRUE; } - if (mV[1] > max) { mV[1] = max; ret = TRUE; } - if (mV[2] > max) { mV[2] = max; ret = TRUE; } + if (mV[VX] > max) { mV[VX] = max; ret = true; } + if (mV[VY] > max) { mV[VY] = max; ret = true; } + if (mV[VZ] > max) { mV[VZ] = max; ret = true; } return ret; } // Clamps length to an upper limit. -// Returns TRUE if the data changed -BOOL LLVector3::clampLength( F32 length_limit ) +// Returns true if the data changed +bool LLVector3::clampLength( F32 length_limit ) { - BOOL changed = FALSE; + bool changed{ false }; F32 len = length(); if (llfinite(len)) @@ -85,10 +84,10 @@ BOOL LLVector3::clampLength( F32 length_limit ) { length_limit = 0.f; } - mV[0] *= length_limit; - mV[1] *= length_limit; - mV[2] *= length_limit; - changed = TRUE; + mV[VX] *= length_limit; + mV[VY] *= length_limit; + mV[VZ] *= length_limit; + changed = true; } } else @@ -108,7 +107,7 @@ BOOL LLVector3::clampLength( F32 length_limit ) { // no it can't be salvaged --> clear it clear(); - changed = TRUE; + changed = true; break; } } @@ -116,49 +115,49 @@ BOOL LLVector3::clampLength( F32 length_limit ) { // yes it can be salvaged --> // bring the components down before we normalize - mV[0] /= max_abs_component; - mV[1] /= max_abs_component; - mV[2] /= max_abs_component; + mV[VX] /= max_abs_component; + mV[VY] /= max_abs_component; + mV[VZ] /= max_abs_component; normalize(); if (length_limit < 0.f) { length_limit = 0.f; } - mV[0] *= length_limit; - mV[1] *= length_limit; - mV[2] *= length_limit; + mV[VX] *= length_limit; + mV[VY] *= length_limit; + mV[VZ] *= length_limit; } } return changed; } -BOOL LLVector3::clamp(const LLVector3 &min_vec, const LLVector3 &max_vec) +bool LLVector3::clamp(const LLVector3& min_vec, const LLVector3& max_vec) { - BOOL ret = FALSE; + bool ret{ false }; - if (mV[0] < min_vec[0]) { mV[0] = min_vec[0]; ret = TRUE; } - if (mV[1] < min_vec[1]) { mV[1] = min_vec[1]; ret = TRUE; } - if (mV[2] < min_vec[2]) { mV[2] = min_vec[2]; ret = TRUE; } + if (mV[VX] < min_vec[0]) { mV[VX] = min_vec[0]; ret = true; } + if (mV[VY] < min_vec[1]) { mV[VY] = min_vec[1]; ret = true; } + if (mV[VZ] < min_vec[2]) { mV[VZ] = min_vec[2]; ret = true; } - if (mV[0] > max_vec[0]) { mV[0] = max_vec[0]; ret = TRUE; } - if (mV[1] > max_vec[1]) { mV[1] = max_vec[1]; ret = TRUE; } - if (mV[2] > max_vec[2]) { mV[2] = max_vec[2]; ret = TRUE; } + if (mV[VX] > max_vec[0]) { mV[VX] = max_vec[0]; ret = true; } + if (mV[VY] > max_vec[1]) { mV[VY] = max_vec[1]; ret = true; } + if (mV[VZ] > max_vec[2]) { mV[VZ] = max_vec[2]; ret = true; } return ret; } // Sets all values to absolute value of their original values -// Returns TRUE if data changed -BOOL LLVector3::abs() +// Returns true if data changed +bool LLVector3::abs() { - BOOL ret = FALSE; + bool ret{ false }; - if (mV[0] < 0.f) { mV[0] = -mV[0]; ret = TRUE; } - if (mV[1] < 0.f) { mV[1] = -mV[1]; ret = TRUE; } - if (mV[2] < 0.f) { mV[2] = -mV[2]; ret = TRUE; } + if (mV[VX] < 0.f) { mV[VX] = -mV[VX]; ret = true; } + if (mV[VY] < 0.f) { mV[VY] = -mV[VY]; ret = true; } + if (mV[VZ] < 0.f) { mV[VZ] = -mV[VZ]; ret = true; } return ret; } @@ -194,13 +193,13 @@ void LLVector3::snap(S32 sig_digits) mV[VZ] = snap_to_sig_figs(mV[VZ], sig_digits); } -const LLVector3& LLVector3::rotVec(const LLMatrix3 &mat) +const LLVector3& LLVector3::rotVec(const LLMatrix3& mat) { *this = *this * mat; return *this; } -const LLVector3& LLVector3::rotVec(const LLQuaternion &q) +const LLVector3& LLVector3::rotVec(const LLQuaternion& q) { *this = *this * q; return *this; @@ -228,7 +227,7 @@ const LLVector3& LLVector3::transVec(const LLMatrix4& mat) } -const LLVector3& LLVector3::rotVec(F32 angle, const LLVector3 &vec) +const LLVector3& LLVector3::rotVec(F32 angle, const LLVector3& vec) { if ( !vec.isExactlyZero() && angle ) { @@ -263,35 +262,35 @@ LLVector3 LLVector3::scaledVec(const LLVector3& vec) const return ret; } -const LLVector3& LLVector3::set(const LLVector3d &vec) +const LLVector3& LLVector3::set(const LLVector3d& vec) { - mV[0] = (F32)vec.mdV[0]; - mV[1] = (F32)vec.mdV[1]; - mV[2] = (F32)vec.mdV[2]; + mV[VX] = (F32)vec.mdV[VX]; + mV[VY] = (F32)vec.mdV[VY]; + mV[VZ] = (F32)vec.mdV[VZ]; return (*this); } -const LLVector3& LLVector3::set(const LLVector4 &vec) +const LLVector3& LLVector3::set(const LLVector4& vec) { - mV[0] = vec.mV[0]; - mV[1] = vec.mV[1]; - mV[2] = vec.mV[2]; + mV[VX] = vec.mV[VX]; + mV[VY] = vec.mV[VY]; + mV[VZ] = vec.mV[VZ]; return (*this); } -const LLVector3& LLVector3::setVec(const LLVector3d &vec) +const LLVector3& LLVector3::setVec(const LLVector3d& vec) { - mV[0] = (F32)vec.mdV[0]; - mV[1] = (F32)vec.mdV[1]; - mV[2] = (F32)vec.mdV[2]; + mV[VX] = (F32)vec.mdV[0]; + mV[VY] = (F32)vec.mdV[1]; + mV[VZ] = (F32)vec.mdV[2]; return (*this); } -const LLVector3& LLVector3::setVec(const LLVector4 &vec) +const LLVector3& LLVector3::setVec(const LLVector4& vec) { - mV[0] = vec.mV[0]; - mV[1] = vec.mV[1]; - mV[2] = vec.mV[2]; + mV[VX] = vec.mV[VX]; + mV[VY] = vec.mV[VY]; + mV[VZ] = vec.mV[VZ]; return (*this); } @@ -302,14 +301,14 @@ LLVector3::LLVector3(const LLVector2 &vec) mV[VZ] = 0; } -LLVector3::LLVector3(const LLVector3d &vec) +LLVector3::LLVector3(const LLVector3d& vec) { mV[VX] = (F32)vec.mdV[VX]; mV[VY] = (F32)vec.mdV[VY]; mV[VZ] = (F32)vec.mdV[VZ]; } -LLVector3::LLVector3(const LLVector4 &vec) +LLVector3::LLVector3(const LLVector4& vec) { mV[VX] = (F32)vec.mV[VX]; mV[VY] = (F32)vec.mV[VY]; @@ -330,20 +329,20 @@ LLVector3::LLVector3(const LLSD& sd) LLSD LLVector3::getValue() const { LLSD ret; - ret[0] = mV[0]; - ret[1] = mV[1]; - ret[2] = mV[2]; + ret[0] = mV[VX]; + ret[1] = mV[VY]; + ret[2] = mV[VZ]; return ret; } void LLVector3::setValue(const LLSD& sd) { - mV[0] = (F32) sd[0].asReal(); - mV[1] = (F32) sd[1].asReal(); - mV[2] = (F32) sd[2].asReal(); + mV[VX] = (F32) sd[0].asReal(); + mV[VY] = (F32) sd[1].asReal(); + mV[VZ] = (F32) sd[2].asReal(); } -const LLVector3& operator*=(LLVector3 &a, const LLQuaternion &rot) +const LLVector3& operator*=(LLVector3& a, const LLQuaternion& rot) { const F32 rw = - rot.mQ[VX] * a.mV[VX] - rot.mQ[VY] * a.mV[VY] - rot.mQ[VZ] * a.mV[VZ]; const F32 rx = rot.mQ[VW] * a.mV[VX] + rot.mQ[VY] * a.mV[VZ] - rot.mQ[VZ] * a.mV[VY]; @@ -358,11 +357,11 @@ const LLVector3& operator*=(LLVector3 &a, const LLQuaternion &rot) } // static -BOOL LLVector3::parseVector3(const std::string& buf, LLVector3* value) +bool LLVector3::parseVector3(const std::string& buf, LLVector3* value) { - if( buf.empty() || value == NULL) + if( buf.empty() || value == nullptr) { - return FALSE; + return false; } LLVector3 v; @@ -370,10 +369,10 @@ BOOL LLVector3::parseVector3(const std::string& buf, LLVector3* value) if( 3 == count ) { value->setVec( v ); - return TRUE; + return true; } - return FALSE; + return false; } // Displacement from query point to nearest neighbor point on bounding box. |