From 3d84a147f0ae781a71f74d9d7ad0b07f9b1ccb43 Mon Sep 17 00:00:00 2001 From: Alexander Gavriliuk Date: Fri, 14 Jun 2024 08:06:31 +0200 Subject: #1611 Regression in anti-flipping mechanism for mouselook camera --- indra/llmath/llcoordframe.cpp | 26 +++---- indra/llmath/llquaternion.cpp | 4 +- indra/llmath/v2math.cpp | 9 ++- indra/llmath/v2math.h | 102 +++++++++----------------- indra/llmath/v3math.h | 151 ++++++++++++--------------------------- indra/llmath/v4math.h | 161 ++++++++++++------------------------------ 6 files changed, 147 insertions(+), 306 deletions(-) (limited to 'indra/llmath') diff --git a/indra/llmath/llcoordframe.cpp b/indra/llmath/llcoordframe.cpp index 4d6276b2cd..7e1f350ab5 100644 --- a/indra/llmath/llcoordframe.cpp +++ b/indra/llmath/llcoordframe.cpp @@ -329,28 +329,30 @@ void LLCoordFrame::rotate(const LLMatrix3 &rotation_matrix) } +// Rotate 2 normalized orthogonal vectors in direction from `source` to `target` +static void rotate2(LLVector3& source, LLVector3& target, F32 angle) +{ + double sx = source[VX], sy = source[VY], sz = source[VZ]; + double tx = target[VX], ty = target[VY], tz = target[VZ]; + double c = cos(angle), s = sin(angle); + + source.set(sx * c + tx * s, sy * c + ty * s, sz * c + tz * s); + target.set(tx * c - sx * s, ty * c - sy * s, tz * c - sz * s); +} + void LLCoordFrame::roll(F32 angle) { - LLQuaternion q(angle, mXAxis); - LLMatrix3 rotation_matrix(q); - rotate(rotation_matrix); - CHECK_FINITE_OBJ(); + rotate2(mYAxis, mZAxis, angle); } void LLCoordFrame::pitch(F32 angle) { - LLQuaternion q(angle, mYAxis); - LLMatrix3 rotation_matrix(q); - rotate(rotation_matrix); - CHECK_FINITE_OBJ(); + rotate2(mZAxis, mXAxis, angle); } void LLCoordFrame::yaw(F32 angle) { - LLQuaternion q(angle, mZAxis); - LLMatrix3 rotation_matrix(q); - rotate(rotation_matrix); - CHECK_FINITE_OBJ(); + rotate2(mXAxis, mYAxis, angle); } // get*() routines diff --git a/indra/llmath/llquaternion.cpp b/indra/llmath/llquaternion.cpp index ce0a88c26f..07e54daf87 100644 --- a/indra/llmath/llquaternion.cpp +++ b/indra/llmath/llquaternion.cpp @@ -58,7 +58,7 @@ LLQuaternion::LLQuaternion(const LLMatrix3 &mat) LLQuaternion::LLQuaternion(F32 angle, const LLVector4 &vec) { - F32 mag = sqrtf(vec.mV[VX] * vec.mV[VX] + vec.mV[VY] * vec.mV[VY] + vec.mV[VZ] * vec.mV[VZ]); + F32 mag = vec.length(); if (mag > FP_MAG_THRESHOLD) { angle *= 0.5; @@ -77,7 +77,7 @@ LLQuaternion::LLQuaternion(F32 angle, const LLVector4 &vec) LLQuaternion::LLQuaternion(F32 angle, const LLVector3 &vec) { - F32 mag = sqrtf(vec.mV[VX] * vec.mV[VX] + vec.mV[VY] * vec.mV[VY] + vec.mV[VZ] * vec.mV[VZ]); + F32 mag = vec.length(); if (mag > FP_MAG_THRESHOLD) { angle *= 0.5; diff --git a/indra/llmath/v2math.cpp b/indra/llmath/v2math.cpp index ecbfe7378c..78d349f2f0 100644 --- a/indra/llmath/v2math.cpp +++ b/indra/llmath/v2math.cpp @@ -67,7 +67,14 @@ F32 angle_between(const LLVector2& a, const LLVector2& b) return angle; } -BOOL are_parallel(const LLVector2 &a, const LLVector2 &b, float epsilon) +F32 signed_angle_between(const LLVector2& a, const LLVector2& b) +{ + F32 angle = angle_between(a, b); + F32 rhombus_square = a[VX] * b[VY] - b[VX] * a[VY]; + return rhombus_square < 0 ? -angle : angle; +} + +BOOL are_parallel(const LLVector2 &a, const LLVector2 &b, F32 epsilon) { LLVector2 an = a; LLVector2 bn = b; diff --git a/indra/llmath/v2math.h b/indra/llmath/v2math.h index 5c756a7f84..978d14ece8 100644 --- a/indra/llmath/v2math.h +++ b/indra/llmath/v2math.h @@ -107,13 +107,14 @@ class LLVector2 friend LLVector2 operator-(const LLVector2 &a); // Return vector -a - friend std::ostream& operator<<(std::ostream& s, const LLVector2 &a); // Stream a + friend std::ostream& operator<<(std::ostream& s, const LLVector2 &a); // Stream a }; // Non-member functions F32 angle_between(const LLVector2 &a, const LLVector2 &b); // Returns angle (radians) between a and b +F32 signed_angle_between(const LLVector2& a, const LLVector2& b); // Returns signed angle (radians) between a and b BOOL are_parallel(const LLVector2 &a, const LLVector2 &b, F32 epsilon=F_APPROXIMATELY_ZERO); // Returns TRUE if a and b are very close to parallel F32 dist_vec(const LLVector2 &a, const LLVector2 &b); // Returns distance between a and b F32 dist_vec_squared(const LLVector2 &a, const LLVector2 &b);// Returns distance squared between a and b @@ -124,26 +125,22 @@ LLVector2 lerp(const LLVector2 &a, const LLVector2 &b, F32 u); // Returns a vect inline LLVector2::LLVector2(void) { - mV[VX] = 0.f; - mV[VY] = 0.f; + clear(); } inline LLVector2::LLVector2(F32 x, F32 y) { - mV[VX] = x; - mV[VY] = y; + set(x, y); } inline LLVector2::LLVector2(const F32 *vec) { - mV[VX] = vec[VX]; - mV[VY] = vec[VY]; + set(vec); } inline LLVector2::LLVector2(const LLVector3 &vec) { - mV[VX] = vec.mV[VX]; - mV[VY] = vec.mV[VY]; + set(vec.mV); } inline LLVector2::LLVector2(const LLSD &sd) @@ -155,28 +152,24 @@ inline LLVector2::LLVector2(const LLSD &sd) inline void LLVector2::clear(void) { - mV[VX] = 0.f; - mV[VY] = 0.f; + mV[VX] = mV[VY] = 0.f; } inline void LLVector2::setZero(void) { - mV[VX] = 0.f; - mV[VY] = 0.f; + clear(); } // deprecated inline void LLVector2::clearVec(void) { - mV[VX] = 0.f; - mV[VY] = 0.f; + clear(); } // deprecated inline void LLVector2::zeroVec(void) { - mV[VX] = 0.f; - mV[VY] = 0.f; + clear(); } inline void LLVector2::set(F32 x, F32 y) @@ -187,36 +180,31 @@ inline void LLVector2::set(F32 x, F32 y) inline void LLVector2::set(const LLVector2 &vec) { - mV[VX] = vec.mV[VX]; - mV[VY] = vec.mV[VY]; + set(vec.mV); } inline void LLVector2::set(const F32 *vec) { - mV[VX] = vec[VX]; - mV[VY] = vec[VY]; + set(vec[VX], vec[VY]); } // deprecated inline void LLVector2::setVec(F32 x, F32 y) { - mV[VX] = x; - mV[VY] = y; + set(x, y); } // deprecated inline void LLVector2::setVec(const LLVector2 &vec) { - mV[VX] = vec.mV[VX]; - mV[VY] = vec.mV[VY]; + set(vec); } // deprecated inline void LLVector2::setVec(const F32 *vec) { - mV[VX] = vec[VX]; - mV[VY] = vec[VY]; + set(vec); } @@ -224,7 +212,7 @@ inline void LLVector2::setVec(const F32 *vec) inline F32 LLVector2::length(void) const { - return (F32) sqrt(mV[0]*mV[0] + mV[1]*mV[1]); + return (F32) sqrt(lengthSquared()); } inline F32 LLVector2::lengthSquared(void) const @@ -232,63 +220,44 @@ inline F32 LLVector2::lengthSquared(void) const return mV[0]*mV[0] + mV[1]*mV[1]; } -inline F32 LLVector2::normalize(void) +inline F32 LLVector2::normalize(void) { - F32 mag = (F32) sqrt(mV[0]*mV[0] + mV[1]*mV[1]); - F32 oomag; + F32 mag = length(); if (mag > FP_MAG_THRESHOLD) { - oomag = 1.f/mag; - mV[0] *= oomag; - mV[1] *= oomag; + *this /= mag; } else { - mV[0] = 0.f; - mV[1] = 0.f; + clear(); mag = 0; } - return (mag); + return mag; } // checker inline bool LLVector2::isFinite() const { - return (llfinite(mV[VX]) && llfinite(mV[VY])); + return llfinite(mV[VX]) && llfinite(mV[VY]); } // deprecated -inline F32 LLVector2::magVec(void) const +inline F32 LLVector2::magVec(void) const { - return (F32) sqrt(mV[0]*mV[0] + mV[1]*mV[1]); + return length(); } // deprecated -inline F32 LLVector2::magVecSquared(void) const +inline F32 LLVector2::magVecSquared(void) const { - return mV[0]*mV[0] + mV[1]*mV[1]; + return lengthSquared(); } // deprecated -inline F32 LLVector2::normVec(void) +inline F32 LLVector2::normVec(void) { - F32 mag = (F32) sqrt(mV[0]*mV[0] + mV[1]*mV[1]); - F32 oomag; - - if (mag > FP_MAG_THRESHOLD) - { - oomag = 1.f/mag; - mV[0] *= oomag; - mV[1] *= oomag; - } - else - { - mV[0] = 0.f; - mV[1] = 0.f; - mag = 0; - } - return (mag); + return normalize(); } inline const LLVector2& LLVector2::scaleVec(const LLVector2& vec) @@ -301,11 +270,7 @@ inline const LLVector2& LLVector2::scaleVec(const LLVector2& vec) inline BOOL LLVector2::isNull() { - if ( F_APPROXIMATELY_ZERO > mV[VX]*mV[VX] + mV[VY]*mV[VY] ) - { - return TRUE; - } - return FALSE; + return F_APPROXIMATELY_ZERO > mV[VX]*mV[VX] + mV[VY]*mV[VY]; } @@ -337,9 +302,9 @@ inline LLVector2 operator-(const LLVector2 &a, const LLVector2 &b) return c -= b; } -inline F32 operator*(const LLVector2 &a, const LLVector2 &b) +inline F32 operator*(const LLVector2 &a, const LLVector2 &b) { - return (a.mV[0]*b.mV[0] + a.mV[1]*b.mV[1]); + return a.mV[0]*b.mV[0] + a.mV[1]*b.mV[1]; } inline LLVector2 operator%(const LLVector2 &a, const LLVector2 &b) @@ -405,10 +370,7 @@ inline const LLVector2& operator*=(LLVector2 &a, F32 k) inline const LLVector2& operator/=(LLVector2 &a, F32 k) { - F32 t = 1.f / k; - a.mV[0] *= t; - a.mV[1] *= t; - return a; + return a *= 1.f / k; } inline LLVector2 operator-(const LLVector2 &a) diff --git a/indra/llmath/v3math.h b/indra/llmath/v3math.h index 0f4a4a07ae..513e01d3e1 100644 --- a/indra/llmath/v3math.h +++ b/indra/llmath/v3math.h @@ -100,24 +100,24 @@ class LLVector3 const LLVector3& setVec(const LLVector4 &vec); // deprecated const LLVector3& setVec(const LLVector3d &vec); // deprecated - F32 length() const; // Returns magnitude of LLVector3 - F32 lengthSquared() const; // Returns magnitude squared of LLVector3 - F32 magVec() const; // deprecated - F32 magVecSquared() const; // deprecated + F32 length() const; // Returns magnitude of LLVector3 + F32 lengthSquared() const; // Returns magnitude squared of LLVector3 + F32 magVec() const; // deprecated + F32 magVecSquared() const; // deprecated - inline F32 normalize(); // Normalizes and returns the magnitude of LLVector3 - inline F32 normVec(); // deprecated + inline F32 normalize(); // Normalizes and returns the magnitude of LLVector3 + inline F32 normVec(); // deprecated - inline BOOL inRange( F32 min, F32 max ) const; // Returns true if all values of the vector are between min and max + inline BOOL inRange(F32 min, F32 max) const; // Returns true if all values of the vector are between min and max - const LLVector3& rotVec(F32 angle, const LLVector3 &vec); // Rotates about vec by angle radians - const LLVector3& rotVec(F32 angle, F32 x, F32 y, F32 z); // Rotates about x,y,z by angle radians - const LLVector3& rotVec(const LLMatrix3 &mat); // Rotates by LLMatrix4 mat - const LLVector3& rotVec(const LLQuaternion &q); // Rotates by LLQuaternion q - const LLVector3& transVec(const LLMatrix4& mat); // Transforms by LLMatrix4 mat (mat * v) + const LLVector3& rotVec(F32 angle, const LLVector3 &vec); // Rotates about vec by angle radians + const LLVector3& rotVec(F32 angle, F32 x, F32 y, F32 z); // Rotates about x,y,z by angle radians + const LLVector3& rotVec(const LLMatrix3 &mat); // Rotates by LLMatrix4 mat + const LLVector3& rotVec(const LLQuaternion &q); // Rotates by LLQuaternion q + const LLVector3& transVec(const LLMatrix4& mat); // Transforms by LLMatrix4 mat (mat * v) - const LLVector3& scaleVec(const LLVector3& vec); // scales per component by vec - LLVector3 scaledVec(const LLVector3& vec) const; // get a copy of this vector scaled by vec + const LLVector3& scaleVec(const LLVector3& vec); // scales per component by vec + LLVector3 scaledVec(const LLVector3& vec) const; // get a copy of this vector scaled by vec BOOL isNull() const; // Returns TRUE if vector has a _very_small_ length BOOL isExactlyZero() const { return !mV[VX] && !mV[VY] && !mV[VZ]; } @@ -171,23 +171,17 @@ bool box_valid_and_non_zero(const LLVector3* box); inline LLVector3::LLVector3(void) { - mV[0] = 0.f; - mV[1] = 0.f; - mV[2] = 0.f; + clear(); } inline LLVector3::LLVector3(const F32 x, const F32 y, const F32 z) { - mV[VX] = x; - mV[VY] = y; - mV[VZ] = z; + set(x, y, z); } inline LLVector3::LLVector3(const F32 *vec) { - mV[VX] = vec[VX]; - mV[VY] = vec[VY]; - mV[VZ] = vec[VZ]; + set(vec); } /* @@ -204,7 +198,7 @@ inline LLVector3::LLVector3(const LLVector3 ©) // checker inline BOOL LLVector3::isFinite() const { - return (llfinite(mV[VX]) && llfinite(mV[VY]) && llfinite(mV[VZ])); + return llfinite(mV[VX]) && llfinite(mV[VY]) && llfinite(mV[VZ]); } @@ -212,30 +206,22 @@ inline BOOL LLVector3::isFinite() const inline void LLVector3::clear(void) { - mV[0] = 0.f; - mV[1] = 0.f; - mV[2] = 0.f; + set(0.f, 0.f, 0.f); } inline void LLVector3::setZero(void) { - mV[0] = 0.f; - mV[1] = 0.f; - mV[2] = 0.f; + clear(); } inline void LLVector3::clearVec(void) { - mV[0] = 0.f; - mV[1] = 0.f; - mV[2] = 0.f; + clear(); } inline void LLVector3::zeroVec(void) { - mV[0] = 0.f; - mV[1] = 0.f; - mV[2] = 0.f; + clear(); } inline void LLVector3::set(F32 x, F32 y, F32 z) @@ -247,107 +233,74 @@ inline void LLVector3::set(F32 x, F32 y, F32 z) inline void LLVector3::set(const LLVector3 &vec) { - mV[0] = vec.mV[0]; - mV[1] = vec.mV[1]; - mV[2] = vec.mV[2]; + set(vec.mV[0], vec.mV[1], vec.mV[2]); } inline void LLVector3::set(const F32 *vec) { - mV[0] = vec[0]; - mV[1] = vec[1]; - mV[2] = vec[2]; + set(vec[0], vec[1], vec[2]); } // deprecated inline void LLVector3::setVec(F32 x, F32 y, F32 z) { - mV[VX] = x; - mV[VY] = y; - mV[VZ] = z; + set(x, y, z); } // deprecated inline void LLVector3::setVec(const LLVector3 &vec) { - mV[0] = vec.mV[0]; - mV[1] = vec.mV[1]; - mV[2] = vec.mV[2]; + set(vec); } // deprecated inline void LLVector3::setVec(const F32 *vec) { - mV[0] = vec[0]; - mV[1] = vec[1]; - mV[2] = vec[2]; + set(vec); } inline F32 LLVector3::normalize(void) { F32 mag = (F32) sqrt(mV[0]*mV[0] + mV[1]*mV[1] + mV[2]*mV[2]); - F32 oomag; if (mag > FP_MAG_THRESHOLD) { - oomag = 1.f/mag; - mV[0] *= oomag; - mV[1] *= oomag; - mV[2] *= oomag; + *this /= mag; } else { - mV[0] = 0.f; - mV[1] = 0.f; - mV[2] = 0.f; + clear(); mag = 0; } - return (mag); + return mag; } // deprecated inline F32 LLVector3::normVec(void) { - F32 mag = (F32) sqrt(mV[0]*mV[0] + mV[1]*mV[1] + mV[2]*mV[2]); - F32 oomag; - - if (mag > FP_MAG_THRESHOLD) - { - oomag = 1.f/mag; - mV[0] *= oomag; - mV[1] *= oomag; - mV[2] *= oomag; - } - else - { - mV[0] = 0.f; - mV[1] = 0.f; - mV[2] = 0.f; - mag = 0; - } - return (mag); + return normalize(); } // LLVector3 Magnitude and Normalization Functions -inline F32 LLVector3::length(void) const +inline F32 LLVector3::length(void) const { - return (F32) sqrt(mV[0]*mV[0] + mV[1]*mV[1] + mV[2]*mV[2]); + return (F32) sqrt(lengthSquared()); } -inline F32 LLVector3::lengthSquared(void) const +inline F32 LLVector3::lengthSquared(void) const { return mV[0]*mV[0] + mV[1]*mV[1] + mV[2]*mV[2]; } -inline F32 LLVector3::magVec(void) const +inline F32 LLVector3::magVec(void) const { - return (F32) sqrt(mV[0]*mV[0] + mV[1]*mV[1] + mV[2]*mV[2]); + return length(); } -inline F32 LLVector3::magVecSquared(void) const +inline F32 LLVector3::magVecSquared(void) const { - return mV[0]*mV[0] + mV[1]*mV[1] + mV[2]*mV[2]; + return lengthSquared(); } inline BOOL LLVector3::inRange( F32 min, F32 max ) const @@ -371,7 +324,7 @@ inline LLVector3 operator-(const LLVector3 &a, const LLVector3 &b) inline F32 operator*(const LLVector3 &a, const LLVector3 &b) { - return (a.mV[0]*b.mV[0] + a.mV[1]*b.mV[1] + a.mV[2]*b.mV[2]); + return a.mV[0]*b.mV[0] + a.mV[1]*b.mV[1] + a.mV[2]*b.mV[2]; } inline LLVector3 operator%(const LLVector3 &a, const LLVector3 &b) @@ -459,10 +412,7 @@ inline const LLVector3& operator*=(LLVector3 &a, const LLVector3 &b) inline const LLVector3& operator/=(LLVector3 &a, F32 k) { - F32 t = 1.f / k; - a.mV[0] *= t; - a.mV[1] *= t; - a.mV[2] *= t; + a *= 1.f / k; return a; } @@ -471,7 +421,7 @@ inline LLVector3 operator-(const LLVector3 &a) return LLVector3( -a.mV[0], -a.mV[1], -a.mV[2] ); } -inline F32 dist_vec(const LLVector3 &a, const LLVector3 &b) +inline F32 dist_vec(const LLVector3 &a, const LLVector3 &b) { F32 x = a.mV[0] - b.mV[0]; F32 y = a.mV[1] - b.mV[1]; @@ -479,7 +429,7 @@ inline F32 dist_vec(const LLVector3 &a, const LLVector3 &b) return (F32) sqrt( x*x + y*y + z*z ); } -inline F32 dist_vec_squared(const LLVector3 &a, const LLVector3 &b) +inline F32 dist_vec_squared(const LLVector3 &a, const LLVector3 &b) { F32 x = a.mV[0] - b.mV[0]; F32 y = a.mV[1] - b.mV[1]; @@ -487,7 +437,7 @@ inline F32 dist_vec_squared(const LLVector3 &a, const LLVector3 &b) return x*x + y*y + z*z; } -inline F32 dist_vec_squared2D(const LLVector3 &a, const LLVector3 &b) +inline F32 dist_vec_squared2D(const LLVector3 &a, const LLVector3 &b) { F32 x = a.mV[0] - b.mV[0]; F32 y = a.mV[1] - b.mV[1]; @@ -501,10 +451,7 @@ inline LLVector3 projected_vec(const LLVector3 &a, const LLVector3 &b) { return ((a * b) / bb) * b; } - else - { - return b.zero; - } + return b.zero; } inline LLVector3 inverse_projected_vec(const LLVector3& a, const LLVector3& b) @@ -541,11 +488,7 @@ inline LLVector3 lerp(const LLVector3 &a, const LLVector3 &b, F32 u) inline BOOL LLVector3::isNull() const { - if ( F_APPROXIMATELY_ZERO > mV[VX]*mV[VX] + mV[VY]*mV[VY] + mV[VZ]*mV[VZ] ) - { - return TRUE; - } - return FALSE; + return F_APPROXIMATELY_ZERO > mV[VX]*mV[VX] + mV[VY]*mV[VY] + mV[VZ]*mV[VZ]; } inline void update_min_max(LLVector3& min, LLVector3& max, const LLVector3& pos) @@ -586,7 +529,7 @@ inline F32 angle_between(const LLVector3& a, const LLVector3& b) ab = 0.0f; // get rid of negative zero } LLVector3 c = a % b; // crossproduct - return atan2f(sqrtf(c * c), ab); // return the angle + return atan2f(c.length(), ab); // return the angle } inline BOOL are_parallel(const LLVector3 &a, const LLVector3 &b, F32 epsilon) @@ -596,7 +539,7 @@ inline BOOL are_parallel(const LLVector3 &a, const LLVector3 &b, F32 epsilon) an.normalize(); bn.normalize(); F32 dot = an * bn; - if ( (1.0f - fabs(dot)) < epsilon) + if (1.0f - fabs(dot) < epsilon) { return TRUE; } diff --git a/indra/llmath/v4math.h b/indra/llmath/v4math.h index 7f0020af6b..b9460820a1 100644 --- a/indra/llmath/v4math.h +++ b/indra/llmath/v4math.h @@ -96,9 +96,9 @@ class LLVector4 F32 lengthSquared() const; // Returns magnitude squared of LLVector4 F32 normalize(); // Normalizes and returns the magnitude of LLVector4 - F32 magVec() const; // deprecated - F32 magVecSquared() const; // deprecated - F32 normVec(); // deprecated + F32 magVec() const; // deprecated + F32 magVecSquared() const; // deprecated + F32 normVec(); // deprecated // Sets all values to absolute value of their original values // Returns TRUE if data changed @@ -107,10 +107,10 @@ class LLVector4 BOOL isExactlyClear() const { return (mV[VW] == 1.0f) && !mV[VX] && !mV[VY] && !mV[VZ]; } BOOL isExactlyZero() const { return !mV[VW] && !mV[VX] && !mV[VY] && !mV[VZ]; } - const LLVector4& rotVec(F32 angle, const LLVector4 &vec); // Rotates about vec by angle radians - const LLVector4& rotVec(F32 angle, F32 x, F32 y, F32 z); // Rotates about x,y,z by angle radians - const LLVector4& rotVec(const LLMatrix4 &mat); // Rotates by MAT4 mat - const LLVector4& rotVec(const LLQuaternion &q); // Rotates by QUAT q + const LLVector4& rotVec(F32 angle, const LLVector4 &vec); // Rotates about vec by angle radians + const LLVector4& rotVec(F32 angle, F32 x, F32 y, F32 z); // Rotates about x,y,z by angle radians + const LLVector4& rotVec(const LLMatrix4 &mat); // Rotates by MAT4 mat + const LLVector4& rotVec(const LLQuaternion &q); // Rotates by QUAT q const LLVector4& scaleVec(const LLVector4& vec); // Scales component-wise by vec @@ -150,34 +150,22 @@ LLVector4 lerp(const LLVector4 &a, const LLVector4 &b, F32 u); // Returns a vect inline LLVector4::LLVector4(void) { - mV[VX] = 0.f; - mV[VY] = 0.f; - mV[VZ] = 0.f; - mV[VW] = 1.f; + clear(); } inline LLVector4::LLVector4(F32 x, F32 y, F32 z) { - mV[VX] = x; - mV[VY] = y; - mV[VZ] = z; - mV[VW] = 1.f; + set(x, y, z, 1.f); } inline LLVector4::LLVector4(F32 x, F32 y, F32 z, F32 w) { - mV[VX] = x; - mV[VY] = y; - mV[VZ] = z; - mV[VW] = w; + set(x, y, z, w); } inline LLVector4::LLVector4(const F32 *vec) { - mV[VX] = vec[VX]; - mV[VY] = vec[VY]; - mV[VZ] = vec[VZ]; - mV[VW] = vec[VW]; + set(vec); } inline LLVector4::LLVector4(const F64 *vec) @@ -206,18 +194,12 @@ inline LLVector4::LLVector4(const LLVector2 &vec, F32 z, F32 w) inline LLVector4::LLVector4(const LLVector3 &vec) { - mV[VX] = vec.mV[VX]; - mV[VY] = vec.mV[VY]; - mV[VZ] = vec.mV[VZ]; - mV[VW] = 1.f; + set(vec, 1.f); } inline LLVector4::LLVector4(const LLVector3 &vec, F32 w) { - mV[VX] = vec.mV[VX]; - mV[VY] = vec.mV[VY]; - mV[VZ] = vec.mV[VZ]; - mV[VW] = w; + set(vec, w); } inline LLVector4::LLVector4(const LLSD &sd) @@ -228,43 +210,31 @@ inline LLVector4::LLVector4(const LLSD &sd) inline BOOL LLVector4::isFinite() const { - return (llfinite(mV[VX]) && llfinite(mV[VY]) && llfinite(mV[VZ]) && llfinite(mV[VW])); + return llfinite(mV[VX]) && llfinite(mV[VY]) && llfinite(mV[VZ]) && llfinite(mV[VW]); } // Clear and Assignment Functions inline void LLVector4::clear(void) { - mV[VX] = 0.f; - mV[VY] = 0.f; - mV[VZ] = 0.f; - mV[VW] = 1.f; + set(0.f, 0.f, 0.f, 1.f); } // deprecated inline void LLVector4::clearVec(void) { - mV[VX] = 0.f; - mV[VY] = 0.f; - mV[VZ] = 0.f; - mV[VW] = 1.f; + clear(); } // deprecated inline void LLVector4::zeroVec(void) { - mV[VX] = 0.f; - mV[VY] = 0.f; - mV[VZ] = 0.f; - mV[VW] = 0.f; + set(0.f, 0.f, 0.f, 0.f); } inline void LLVector4::set(F32 x, F32 y, F32 z) { - mV[VX] = x; - mV[VY] = y; - mV[VZ] = z; - mV[VW] = 1.f; + set(x, y, z, 1.f); } inline void LLVector4::set(F32 x, F32 y, F32 z, F32 w) @@ -277,10 +247,7 @@ inline void LLVector4::set(F32 x, F32 y, F32 z, F32 w) inline void LLVector4::set(const LLVector4 &vec) { - mV[VX] = vec.mV[VX]; - mV[VY] = vec.mV[VY]; - mV[VZ] = vec.mV[VZ]; - mV[VW] = vec.mV[VW]; + set(vec.mV); } inline void LLVector4::set(const LLVector3 &vec, F32 w) @@ -299,72 +266,56 @@ inline void LLVector4::set(const F32 *vec) mV[VW] = vec[VW]; } - // deprecated inline void LLVector4::setVec(F32 x, F32 y, F32 z) { - mV[VX] = x; - mV[VY] = y; - mV[VZ] = z; - mV[VW] = 1.f; + set(x, y, z); } // deprecated inline void LLVector4::setVec(F32 x, F32 y, F32 z, F32 w) { - mV[VX] = x; - mV[VY] = y; - mV[VZ] = z; - mV[VW] = w; + set(x, y, z, w); } // deprecated inline void LLVector4::setVec(const LLVector4 &vec) { - mV[VX] = vec.mV[VX]; - mV[VY] = vec.mV[VY]; - mV[VZ] = vec.mV[VZ]; - mV[VW] = vec.mV[VW]; + set(vec); } // deprecated inline void LLVector4::setVec(const LLVector3 &vec, F32 w) { - mV[VX] = vec.mV[VX]; - mV[VY] = vec.mV[VY]; - mV[VZ] = vec.mV[VZ]; - mV[VW] = w; + set(vec, w); } // deprecated inline void LLVector4::setVec(const F32 *vec) { - mV[VX] = vec[VX]; - mV[VY] = vec[VY]; - mV[VZ] = vec[VZ]; - mV[VW] = vec[VW]; + set(vec); } // LLVector4 Magnitude and Normalization Functions -inline F32 LLVector4::length(void) const +inline F32 LLVector4::length(void) const { - return (F32) sqrt(mV[VX]*mV[VX] + mV[VY]*mV[VY] + mV[VZ]*mV[VZ]); + return (F32) sqrt(lengthSquared()); } -inline F32 LLVector4::lengthSquared(void) const +inline F32 LLVector4::lengthSquared(void) const { return mV[VX]*mV[VX] + mV[VY]*mV[VY] + mV[VZ]*mV[VZ]; } -inline F32 LLVector4::magVec(void) const +inline F32 LLVector4::magVec(void) const { - return (F32) sqrt(mV[VX]*mV[VX] + mV[VY]*mV[VY] + mV[VZ]*mV[VZ]); + return length(); } -inline F32 LLVector4::magVecSquared(void) const +inline F32 LLVector4::magVecSquared(void) const { - return mV[VX]*mV[VX] + mV[VY]*mV[VY] + mV[VZ]*mV[VZ]; + return lengthSquared(); } // LLVector4 Operators @@ -383,7 +334,7 @@ inline LLVector4 operator-(const LLVector4 &a, const LLVector4 &b) inline F32 operator*(const LLVector4 &a, const LLVector4 &b) { - return (a.mV[VX]*b.mV[VX] + a.mV[VY]*b.mV[VY] + a.mV[VZ]*b.mV[VZ]); + return a.mV[VX]*b.mV[VX] + a.mV[VY]*b.mV[VY] + a.mV[VZ]*b.mV[VZ]; } inline LLVector4 operator%(const LLVector4 &a, const LLVector4 &b) @@ -456,11 +407,7 @@ inline const LLVector4& operator*=(LLVector4 &a, F32 k) inline const LLVector4& operator/=(LLVector4 &a, F32 k) { - F32 t = 1.f / k; - a.mV[VX] *= t; - a.mV[VY] *= t; - a.mV[VZ] *= t; - return a; + return a *= 1.f / k; } inline LLVector4 operator-(const LLVector4 &a) @@ -468,16 +415,16 @@ inline LLVector4 operator-(const LLVector4 &a) return LLVector4( -a.mV[VX], -a.mV[VY], -a.mV[VZ] ); } -inline F32 dist_vec(const LLVector4 &a, const LLVector4 &b) +inline F32 dist_vec(const LLVector4 &a, const LLVector4 &b) { LLVector4 vec = a - b; - return (vec.length()); + return vec.length(); } -inline F32 dist_vec_squared(const LLVector4 &a, const LLVector4 &b) +inline F32 dist_vec_squared(const LLVector4 &a, const LLVector4 &b) { LLVector4 vec = a - b; - return (vec.lengthSquared()); + return vec.lengthSquared(); } inline LLVector4 lerp(const LLVector4 &a, const LLVector4 &b, F32 u) @@ -489,17 +436,13 @@ inline LLVector4 lerp(const LLVector4 &a, const LLVector4 &b, F32 u) a.mV[VW] + (b.mV[VW] - a.mV[VW]) * u); } -inline F32 LLVector4::normalize(void) +inline F32 LLVector4::normalize(void) { F32 mag = (F32) sqrt(mV[VX]*mV[VX] + mV[VY]*mV[VY] + mV[VZ]*mV[VZ]); - F32 oomag; if (mag > FP_MAG_THRESHOLD) { - oomag = 1.f/mag; - mV[VX] *= oomag; - mV[VY] *= oomag; - mV[VZ] *= oomag; + *this /= mag; } else { @@ -508,34 +451,18 @@ inline F32 LLVector4::normalize(void) mV[2] = 0.f; mag = 0; } - return (mag); + return mag; } // deprecated -inline F32 LLVector4::normVec(void) +inline F32 LLVector4::normVec(void) { - F32 mag = (F32) sqrt(mV[VX]*mV[VX] + mV[VY]*mV[VY] + mV[VZ]*mV[VZ]); - F32 oomag; - - if (mag > FP_MAG_THRESHOLD) - { - oomag = 1.f/mag; - mV[VX] *= oomag; - mV[VY] *= oomag; - mV[VZ] *= oomag; - } - else - { - mV[0] = 0.f; - mV[1] = 0.f; - mV[2] = 0.f; - mag = 0; - } - return (mag); + return normalize(); } // Because apparently some parts of the viewer use this for color info. -inline const LLVector4 srgbVector4(const LLVector4 &a) { +inline const LLVector4 srgbVector4(const LLVector4 &a) +{ LLVector4 srgbColor; srgbColor.mV[0] = linearTosRGB(a.mV[0]); -- cgit v1.2.3 From 19347f7094c9448e02a021ae2d571b5fe8bfcc2e Mon Sep 17 00:00:00 2001 From: Ansariel Date: Tue, 15 Oct 2024 22:35:38 +0200 Subject: Fix merge issues: * Restore changes from 21947778baaca205615a71a97ac8f563c998fdd3 to llwindow/llwindowwin32.cpp * Restore changes from 3758618949684641fc94b5c9478d9002706213cc to newview/llinspecttexture.cpp * Fix apparent merge error in LLInventoryPanel::itemChanged * Restore changes from 1eeecfa1a8bf43a8980217ce34e3b5f4458483e0 in newview/llpaneloutfitsinventory.h * Restore changes from b9633c17e373bfe55b29228996e8473eb041466d in newview/llpaneloutfitsinventory.h & newview/llpanelwearing.cpp * Restore changes from f660f1f0fda4d2363d351fa550b4f8818b46c2c3 in newview/llviewertexture.cpp * Restore changes from b9633c17e373bfe55b29228996e8473eb041466d & 98f7d73d46fdc045759023eda6409e8c791f5cb2 in newview/lloutfitgallery.cpp and newview/lloutfitslist.cpp * Replace changes from 23729442aab7130f3368d433e8a5a9dd45ff6b98 with current implementation in develop branch * Fix more broken changes in LLViewerTexture::saveRawImage * Restore the changes in LLMath both from develop and maint-c * Fix all kind of other merge errors # Conflicts: # indra/llmath/v2math.h # indra/llmath/v3math.h # indra/llui/llfolderviewitem.cpp # indra/llwindow/llwindowwin32.cpp # indra/newview/llfloaterobjectweights.h # indra/newview/lloutfitgallery.cpp # indra/newview/lloutfitslist.cpp # indra/newview/llsidepaneliteminfo.cpp # indra/newview/llvoavatar.cpp --- indra/llmath/llmath.h | 2 +- indra/llmath/v2math.h | 2 +- indra/llmath/v3math.h | 4 ++-- indra/llmath/v4math.h | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) (limited to 'indra/llmath') diff --git a/indra/llmath/llmath.h b/indra/llmath/llmath.h index fa315291a3..f5e9cdc7e4 100644 --- a/indra/llmath/llmath.h +++ b/indra/llmath/llmath.h @@ -75,7 +75,7 @@ constexpr F32 DEG_TO_RAD = 0.017453292519943295769236907684886f; constexpr F32 RAD_TO_DEG = 57.295779513082320876798154814105f; constexpr F32 F_APPROXIMATELY_ZERO = 0.00001f; constexpr F32 F_LN10 = 2.3025850929940456840179914546844f; -constexpr F32 OO_LN10 = 0.43429448190325182765112891891661; +constexpr F32 OO_LN10 = 0.43429448190325182765112891891661f; constexpr F32 F_LN2 = 0.69314718056f; constexpr F32 OO_LN2 = 1.4426950408889634073599246810019f; diff --git a/indra/llmath/v2math.h b/indra/llmath/v2math.h index 6e3a2933bf..8e366485e7 100644 --- a/indra/llmath/v2math.h +++ b/indra/llmath/v2math.h @@ -212,7 +212,7 @@ inline void LLVector2::setVec(const F32 *vec) inline F32 LLVector2::length(void) const { - return (F32) sqrt(lengthSquared()); + return sqrt(lengthSquared()); } inline F32 LLVector2::lengthSquared(void) const diff --git a/indra/llmath/v3math.h b/indra/llmath/v3math.h index b7691d79b0..d6f2a26c54 100644 --- a/indra/llmath/v3math.h +++ b/indra/llmath/v3math.h @@ -325,10 +325,10 @@ inline F32 LLVector3::normVec(void) inline F32 LLVector3::length(void) const { - return (F32) sqrt(lengthSquared()); + return sqrt(lengthSquared()); } -inline F32 LLVector3::lengthSquared(void) const +inline F32 LLVector3::lengthSquared() const { return mV[0]*mV[0] + mV[1]*mV[1] + mV[2]*mV[2]; } diff --git a/indra/llmath/v4math.h b/indra/llmath/v4math.h index f155d4db52..e72d5cfa6b 100644 --- a/indra/llmath/v4math.h +++ b/indra/llmath/v4math.h @@ -341,7 +341,7 @@ inline void LLVector4::setVec(const F32 *vec) inline F32 LLVector4::length(void) const { - return (F32) sqrt(lengthSquared()); + return sqrt(lengthSquared()); } inline F32 LLVector4::lengthSquared(void) const @@ -489,7 +489,7 @@ inline LLVector4 lerp(const LLVector4 &a, const LLVector4 &b, F32 u) inline F32 LLVector4::normalize(void) { - F32 mag = (F32) sqrt(mV[VX]*mV[VX] + mV[VY]*mV[VY] + mV[VZ]*mV[VZ]); + F32 mag = sqrt(mV[VX]*mV[VX] + mV[VY]*mV[VY] + mV[VZ]*mV[VZ]); if (mag > FP_MAG_THRESHOLD) { -- cgit v1.2.3 From 74a71e30e76862d59a240a1592c4094ff82f3bf6 Mon Sep 17 00:00:00 2001 From: Ansariel Hiller Date: Fri, 18 Apr 2025 22:15:47 +0200 Subject: Restore llmath fixes that got lost during merge (#3948) --- indra/llmath/v2math.h | 6 +++--- indra/llmath/v3math.h | 10 +++++----- indra/llmath/v4math.h | 2 -- 3 files changed, 8 insertions(+), 10 deletions(-) (limited to 'indra/llmath') diff --git a/indra/llmath/v2math.h b/indra/llmath/v2math.h index d9fb70e191..6b9d37535b 100644 --- a/indra/llmath/v2math.h +++ b/indra/llmath/v2math.h @@ -243,19 +243,19 @@ inline bool LLVector2::isFinite() const } // deprecated -inline F32 LLVector2::magVec(void) const +inline F32 LLVector2::magVec() const { return length(); } // deprecated -inline F32 LLVector2::magVecSquared(void) const +inline F32 LLVector2::magVecSquared() const { return lengthSquared(); } // deprecated -inline F32 LLVector2::normVec(void) +inline F32 LLVector2::normVec() { return normalize(); } diff --git a/indra/llmath/v3math.h b/indra/llmath/v3math.h index baf38e4a3a..098ca5218c 100644 --- a/indra/llmath/v3math.h +++ b/indra/llmath/v3math.h @@ -264,7 +264,7 @@ inline void LLVector3::set(const LLVector3& vec) inline void LLVector3::set(const F32* vec) { - set(vec[0], vec[1], vec[2]); + set(vec[VX], vec[VY], vec[VZ]); } inline void LLVector3::set(const glm::vec4& vec) @@ -343,7 +343,7 @@ inline F32 LLVector3::magVecSquared() const return lengthSquared(); } -inline bool LLVector3::inRange( F32 min, F32 max ) const +inline bool LLVector3::inRange(F32 min, F32 max) const { return mV[VX] >= min && mV[VX] <= max && mV[VY] >= min && mV[VY] <= max && @@ -369,7 +369,7 @@ inline F32 operator*(const LLVector3& a, const LLVector3& b) inline LLVector3 operator%(const LLVector3& a, const LLVector3& b) { - return LLVector3( a.mV[VY]*b.mV[VZ] - b.mV[VY]*a.mV[VZ], a.mV[VZ]*b.mV[VX] - b.mV[VZ]*a.mV[VX], a.mV[VX]*b.mV[VY] - b.mV[VX]*a.mV[VY] ); + return LLVector3(a.mV[VY]*b.mV[VZ] - b.mV[VY]*a.mV[VZ], a.mV[VZ]*b.mV[VX] - b.mV[VZ]*a.mV[VX], a.mV[VX]*b.mV[VY] - b.mV[VX]*a.mV[VY]); } inline LLVector3 operator/(const LLVector3& a, F32 k) @@ -429,7 +429,7 @@ inline const LLVector3& operator-=(LLVector3& a, const LLVector3& b) inline const LLVector3& operator%=(LLVector3& a, const LLVector3& b) { - LLVector3 ret( a.mV[VY]*b.mV[VZ] - b.mV[VY]*a.mV[VZ], a.mV[VZ]*b.mV[VX] - b.mV[VZ]*a.mV[VX], a.mV[VX]*b.mV[VY] - b.mV[VX]*a.mV[VY]); + LLVector3 ret(a.mV[VY]*b.mV[VZ] - b.mV[VY]*a.mV[VZ], a.mV[VZ]*b.mV[VX] - b.mV[VZ]*a.mV[VX], a.mV[VX]*b.mV[VY] - b.mV[VX]*a.mV[VY]); a = ret; return a; } @@ -477,7 +477,7 @@ inline F32 dist_vec(const LLVector3& a, const LLVector3& b) F32 x = a.mV[VX] - b.mV[VX]; F32 y = a.mV[VY] - b.mV[VY]; F32 z = a.mV[VZ] - b.mV[VZ]; - return sqrt( x*x + y*y + z*z ); + return sqrt(x*x + y*y + z*z); } inline F32 dist_vec_squared(const LLVector3& a, const LLVector3& b) diff --git a/indra/llmath/v4math.h b/indra/llmath/v4math.h index d49639bd35..1cbd0d9a78 100644 --- a/indra/llmath/v4math.h +++ b/indra/llmath/v4math.h @@ -118,8 +118,6 @@ public: bool isExactlyClear() const { return (mV[VW] == 1.0f) && !mV[VX] && !mV[VY] && !mV[VZ]; } bool isExactlyZero() const { return !mV[VW] && !mV[VX] && !mV[VY] && !mV[VZ]; } - const LLVector4& rotVec(F32 angle, const LLVector4 &vec); // Rotates about vec by angle radians - const LLVector4& rotVec(F32 angle, F32 x, F32 y, F32 z); // Rotates about x,y,z by angle radians const LLVector4& rotVec(const LLMatrix4 &mat); // Rotates by MAT4 mat const LLVector4& rotVec(const LLQuaternion &q); // Rotates by QUAT q -- cgit v1.2.3 From 9235312990b07314758ff1fc4825958d7ee74896 Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Fri, 27 Jun 2025 17:50:58 +0300 Subject: #4298 Crash at generateVertexRemapMulti --- indra/llmath/llvolume.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'indra/llmath') diff --git a/indra/llmath/llvolume.cpp b/indra/llmath/llvolume.cpp index 1e7dfd18f2..7c60253618 100644 --- a/indra/llmath/llvolume.cpp +++ b/indra/llmath/llvolume.cpp @@ -5711,7 +5711,15 @@ bool LLVolumeFace::cacheOptimize(bool gen_tangents) S32 vert_count = 0; if (!data.p.empty()) { - vert_count = static_cast(meshopt_generateVertexRemapMulti(&remap[0], nullptr, data.p.size(), data.p.size(), mos, stream_count)); + try + { + vert_count = static_cast(meshopt_generateVertexRemapMulti(&remap[0], nullptr, data.p.size(), data.p.size(), mos, stream_count)); + } + catch (std::bad_alloc&) + { + LLError::LLUserWarningMsg::showOutOfMemory(); + LL_ERRS("LLCoros") << "Failed to allocate memory for VertexRemap: " << (S32)data.p.size() << LL_ENDL; + } } if (vert_count < 65535 && vert_count != 0) -- cgit v1.2.3