summaryrefslogtreecommitdiff
path: root/indra/llmath
diff options
context:
space:
mode:
authorAndrey Lihatskiy <alihatskiy@productengine.com>2025-04-10 06:01:50 +0300
committerAndrey Lihatskiy <alihatskiy@productengine.com>2025-04-10 06:01:50 +0300
commit5d7a5001b41df8989cd493433c3dc45459db8240 (patch)
tree80012c04f61c56af704e825cf7d2f4e8e3e8625d /indra/llmath
parent2813097aff00d856aa076ade4738a54fe48e25b6 (diff)
parent9e24b300d02e5627ea0d304d412cb683ec2de3a4 (diff)
Merge commit '9e24b30' into marchcat/maint-c/restore
# Conflicts: # indra/llmath/v2math.cpp # indra/llmath/v2math.h # indra/llmath/v3math.h # indra/llmath/v4math.h # indra/llui/llfolderviewitem.cpp # indra/llui/llfolderviewitem.h # indra/llui/llfolderviewmodel.h # indra/llui/llmodaldialog.cpp # indra/llui/lltexteditor.cpp # indra/llui/lltexteditor.h # indra/llwindow/llwindowwin32.cpp # indra/newview/llagent.cpp # indra/newview/llagentcamera.h # indra/newview/llavatarrenderinfoaccountant.cpp # indra/newview/llconversationmodel.h # indra/newview/llfloaterinventorysettings.cpp # indra/newview/llfloaternamedesc.cpp # indra/newview/llfloaternamedesc.h # indra/newview/llfloaterobjectweights.cpp # indra/newview/llfloaterobjectweights.h # indra/newview/llfolderviewmodelinventory.h # indra/newview/llinspecttexture.cpp # indra/newview/llinventorybridge.cpp # indra/newview/llinventorybridge.h # indra/newview/llinventoryfunctions.cpp # indra/newview/llinventorygallery.h # indra/newview/llinventorygallerymenu.cpp # indra/newview/llinventorymodel.cpp # indra/newview/llinventorypanel.cpp # indra/newview/llinventorypanel.h # indra/newview/llmaterialeditor.cpp # indra/newview/lloutfitgallery.cpp # indra/newview/lloutfitgallery.h # indra/newview/lloutfitslist.cpp # indra/newview/lloutfitslist.h # indra/newview/llpanelgroupcreate.cpp # indra/newview/llpanelgroupgeneral.cpp # indra/newview/llpanelobjectinventory.cpp # indra/newview/llpaneloutfitsinventory.h # indra/newview/llpanelprofile.cpp # indra/newview/llpanelwearing.cpp # indra/newview/llreflectionmap.cpp # indra/newview/llselectmgr.cpp # indra/newview/llsidepanelappearance.cpp # indra/newview/llsidepaneliteminfo.cpp # indra/newview/llteleporthistorystorage.cpp # indra/newview/lltexturectrl.cpp # indra/newview/lltexturectrl.h # indra/newview/lltexturefetch.cpp # indra/newview/lltexturefetch.h # indra/newview/llviewerassetupload.cpp # indra/newview/llviewercamera.cpp # indra/newview/llviewercamera.h # indra/newview/llviewermenufile.cpp # indra/newview/llviewerobject.h # indra/newview/llviewertexture.cpp # indra/newview/llviewerwindow.cpp # indra/newview/llvoavatar.cpp # indra/newview/llvoavatar.h # indra/newview/llvoavatarself.cpp # indra/newview/llvovolume.cpp # indra/newview/llvovolume.h # indra/newview/tests/llviewerassetstats_test.cpp
Diffstat (limited to 'indra/llmath')
-rw-r--r--indra/llmath/llcoordframe.cpp26
-rw-r--r--indra/llmath/llquaternion.cpp4
-rw-r--r--indra/llmath/v2math.cpp9
-rw-r--r--indra/llmath/v2math.h100
-rw-r--r--indra/llmath/v3math.h151
-rw-r--r--indra/llmath/v4math.h159
6 files changed, 146 insertions, 303 deletions
diff --git a/indra/llmath/llcoordframe.cpp b/indra/llmath/llcoordframe.cpp
index 4d6276b2cd..e0f4b2ff6b 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)
+{
+ F32 sx = source[VX], sy = source[VY], sz = source[VZ];
+ F32 tx = target[VX], ty = target[VY], tz = target[VZ];
+ F32 c = cosf(angle), s = sinf(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 aefb82b2f0..eb9eb0d427 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 4649e13376..63745b881c 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 a61c946304..6e3a2933bf 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
@@ -234,61 +222,42 @@ inline F32 LLVector2::lengthSquared(void) const
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 a3bfa68060..b7691d79b0 100644
--- a/indra/llmath/v3math.h
+++ b/indra/llmath/v3math.h
@@ -112,24 +112,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]; }
@@ -183,23 +183,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);
}
inline LLVector3::LLVector3(const glm::vec3& vec)
@@ -230,7 +224,7 @@ inline LLVector3::LLVector3(const LLVector3 &copy)
// 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]);
}
@@ -238,30 +232,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)
@@ -273,16 +259,12 @@ 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]);
}
inline void LLVector3::set(const glm::vec4& vec)
@@ -302,92 +284,63 @@ inline void LLVector3::set(const glm::vec3& vec)
// 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
@@ -411,7 +364,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)
@@ -499,10 +452,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;
}
@@ -522,7 +472,7 @@ inline LLVector3::operator glm::vec4() const
return glm::vec4(mV[VX], mV[VY], mV[VZ], 1.f);
}
-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];
@@ -530,7 +480,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];
@@ -538,7 +488,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];
@@ -552,10 +502,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)
@@ -592,11 +539,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)
@@ -637,7 +580,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)
@@ -647,7 +590,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 a4c9668fdd..f155d4db52 100644
--- a/indra/llmath/v4math.h
+++ b/indra/llmath/v4math.h
@@ -107,9 +107,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
@@ -118,8 +118,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(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
@@ -159,34 +161,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)
@@ -215,18 +205,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)
@@ -252,43 +236,31 @@ inline LLVector4::LLVector4(const glm::vec4& vec)
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)
@@ -301,10 +273,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)
@@ -322,7 +291,6 @@ inline void LLVector4::set(const F32 *vec)
mV[VZ] = vec[VZ];
mV[VW] = vec[VW];
}
-
inline void LLVector4::set(const glm::vec4& vec)
{
mV[VX] = vec.x;
@@ -342,68 +310,53 @@ inline void LLVector4::set(const glm::vec3& vec, F32 w)
// 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
@@ -422,7 +375,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)
@@ -495,11 +448,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)
@@ -517,16 +466,16 @@ inline LLVector4::operator glm::vec4() const
return glm::make_vec4(mV);
}
-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)
@@ -538,17 +487,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
{
@@ -557,34 +502,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]);