Skip to content

Commit

Permalink
#1611 Regression in anti-flipping mechanism for mouselook camera
Browse files Browse the repository at this point in the history
  • Loading branch information
LLGuru committed Jun 14, 2024
1 parent 563b6b8 commit b5399c9
Show file tree
Hide file tree
Showing 10 changed files with 262 additions and 432 deletions.
39 changes: 27 additions & 12 deletions indra/llmath/llcoordframe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,28 +329,43 @@ 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 c = cos(angle);
double s = sin(angle);

LLVector3 new_source
(
source[VX] * c + target[VX] * s,
source[VY] * c + target[VY] * s,
source[VZ] * c + target[VZ] * s
);

LLVector3 new_target
(
target[VX] * c - source[VX] * s,
target[VY] * c - source[VY] * s,
target[VZ] * c - source[VZ] * s
);

source = new_source;
target = new_target;
}

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
Expand Down
4 changes: 2 additions & 2 deletions indra/llmath/llquaternion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
9 changes: 8 additions & 1 deletion indra/llmath/v2math.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 romb_square = a[VX] * b[VY] - b[VX] * a[VY];
return romb_square < 0 ? -angle : angle;
}

BOOL are_parallel(const LLVector2 &a, const LLVector2 &b, F32 epsilon)
{
LLVector2 an = a;
LLVector2 bn = b;
Expand Down
102 changes: 32 additions & 70 deletions indra/llmath/v2math.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -187,108 +180,84 @@ 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);
}


// LLVector2 Magnitude and Normalization Functions

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
{
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)
Expand All @@ -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];
}


Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Loading

0 comments on commit b5399c9

Please sign in to comment.