mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-03-03 12:30:31 +00:00
Merges in Monkey's fixes PR with a resolution for a conflict
This commit is contained in:
commit
bedc79aacb
22 changed files with 131 additions and 74 deletions
|
|
@ -163,7 +163,7 @@ EulerF MatrixF::toEuler() const
|
|||
const F32 * mat = m;
|
||||
|
||||
EulerF r;
|
||||
r.x = mAsin(mat[MatrixF::idx(2,1)]);
|
||||
r.x = mAsin(mClampF(mat[MatrixF::idx(2,1)], -1.0, 1.0));
|
||||
|
||||
if(mCos(r.x) != 0.f)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -233,11 +233,13 @@ class Point3D
|
|||
bool isZero() const;
|
||||
F64 len() const;
|
||||
F64 lenSquared() const;
|
||||
F64 magnitudeSafe() const;
|
||||
|
||||
//-------------------------------------- Mathematical mutators
|
||||
public:
|
||||
void neg();
|
||||
void normalize();
|
||||
void normalizeSafe();
|
||||
void normalize(F64 val);
|
||||
void convolve(const Point3D&);
|
||||
void convolveInverse(const Point3D&);
|
||||
|
|
@ -728,11 +730,13 @@ inline Point3F& Point3F::operator*=(const Point3F &_vec)
|
|||
|
||||
inline Point3F Point3F::operator/(const Point3F &_vec) const
|
||||
{
|
||||
AssertFatal(_vec.x != 0.0f && _vec.y != 0.0f && _vec.z != 0.0f, "Error, div by zero attempted");
|
||||
return Point3F(x / _vec.x, y / _vec.y, z / _vec.z);
|
||||
}
|
||||
|
||||
inline Point3F& Point3F::operator/=(const Point3F &_vec)
|
||||
{
|
||||
AssertFatal(_vec.x != 0.0f && _vec.y != 0.0f && _vec.z != 0.0f, "Error, div by zero attempted");
|
||||
x /= _vec.x;
|
||||
y /= _vec.y;
|
||||
z /= _vec.z;
|
||||
|
|
@ -855,7 +859,8 @@ inline F64 Point3D::lenSquared() const
|
|||
|
||||
inline F64 Point3D::len() const
|
||||
{
|
||||
return mSqrtD(x*x + y*y + z*z);
|
||||
F64 temp = x*x + y*y + z*z;
|
||||
return (temp > 0.0) ? mSqrtD(temp) : 0.0;
|
||||
}
|
||||
|
||||
inline void Point3D::normalize()
|
||||
|
|
@ -863,6 +868,28 @@ inline void Point3D::normalize()
|
|||
m_point3D_normalize(*this);
|
||||
}
|
||||
|
||||
inline F64 Point3D::magnitudeSafe() const
|
||||
{
|
||||
if( isZero() )
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return len();
|
||||
}
|
||||
}
|
||||
|
||||
inline void Point3D::normalizeSafe()
|
||||
{
|
||||
F64 vmag = magnitudeSafe();
|
||||
|
||||
if( vmag > POINT_EPSILON )
|
||||
{
|
||||
*this *= F64(1.0 / vmag);
|
||||
}
|
||||
}
|
||||
|
||||
inline void Point3D::normalize(F64 val)
|
||||
{
|
||||
m_point3D_normalize_f(*this, val);
|
||||
|
|
|
|||
|
|
@ -32,33 +32,48 @@ const QuatF QuatF::Identity(0.0f,0.0f,0.0f,1.0f);
|
|||
|
||||
QuatF& QuatF::set( const EulerF & e )
|
||||
{
|
||||
F32 cx, sx;
|
||||
F32 cy, sy;
|
||||
F32 cz, sz;
|
||||
mSinCos( e.x * 0.5f, sx, cx );
|
||||
mSinCos( e.y * 0.5f, sy, cy );
|
||||
mSinCos( e.z * 0.5f, sz, cz );
|
||||
/*
|
||||
F32 cx, sx;
|
||||
F32 cy, sy;
|
||||
F32 cz, sz;
|
||||
mSinCos( -e.x * 0.5f, sx, cx );
|
||||
mSinCos( -e.y * 0.5f, sy, cy );
|
||||
mSinCos( -e.z * 0.5f, sz, cz );
|
||||
|
||||
// Qyaw(z) = [ (0, 0, sin z/2), cos z/2 ]
|
||||
// Qpitch(x) = [ (sin x/2, 0, 0), cos x/2 ]
|
||||
// Qroll(y) = [ (0, sin y/2, 0), cos y/2 ]
|
||||
// this = Qresult = Qyaw*Qpitch*Qroll ZXY
|
||||
//
|
||||
// The code that folows is a simplification of:
|
||||
// roll*=pitch;
|
||||
// roll*=yaw;
|
||||
// *this = roll;
|
||||
F32 cycz, sysz, sycz, cysz;
|
||||
cycz = cy*cz;
|
||||
sysz = sy*sz;
|
||||
sycz = sy*cz;
|
||||
cysz = cy*sz;
|
||||
w = cycz*cx - sysz*sx;
|
||||
x = cycz*sx + sysz*cx;
|
||||
y = sycz*cx + cysz*sx;
|
||||
z = cysz*cx - sycz*sx;
|
||||
// Qyaw(z) = [ (0, 0, sin z/2), cos z/2 ]
|
||||
// Qpitch(x) = [ (sin x/2, 0, 0), cos x/2 ]
|
||||
// Qroll(y) = [ (0, sin y/2, 0), cos y/2 ]
|
||||
// this = Qresult = Qyaw*Qpitch*Qroll ZXY
|
||||
//
|
||||
// The code that folows is a simplification of:
|
||||
// roll*=pitch;
|
||||
// roll*=yaw;
|
||||
// *this = roll;
|
||||
F32 cycz, sysz, sycz, cysz;
|
||||
cycz = cy*cz;
|
||||
sysz = sy*sz;
|
||||
sycz = sy*cz;
|
||||
cysz = cy*sz;
|
||||
w = cycz*cx + sysz*sx;
|
||||
x = cycz*sx + sysz*cx;
|
||||
y = sycz*cx - cysz*sx;
|
||||
z = cysz*cx - sycz*sx;
|
||||
*/
|
||||
// Assuming the angles are in radians.
|
||||
F32 c1 = mCos(e.y * 0.5f);
|
||||
F32 s1 = mSin(e.y * 0.5f);
|
||||
F32 c2 = mCos(e.z * 0.5f);
|
||||
F32 s2 = mSin(e.z * 0.5f);
|
||||
F32 c3 = mCos(e.x * 0.5f);
|
||||
F32 s3 = mSin(e.x * 0.5f);
|
||||
F32 c1c2 = c1*c2;
|
||||
F32 s1s2 = s1*s2;
|
||||
w =c1c2*c3 - s1s2*s3;
|
||||
x =c1c2*s3 + s1s2*c3;
|
||||
y =s1*c2*c3 + c1*s2*s3;
|
||||
z =c1*s2*c3 - s1*c2*s3;
|
||||
|
||||
return *this;
|
||||
return *this;
|
||||
}
|
||||
|
||||
QuatF& QuatF::operator *=( const QuatF & b )
|
||||
|
|
@ -289,7 +304,7 @@ QuatF & QuatF::interpolate( const QuatF & q1, const QuatF & q2, F32 t )
|
|||
return *this;
|
||||
}
|
||||
|
||||
Point3F & QuatF::mulP(const Point3F& p, Point3F* r)
|
||||
Point3F & QuatF::mulP(const Point3F& p, Point3F* r) const
|
||||
{
|
||||
QuatF qq;
|
||||
QuatF qi = *this;
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ public:
|
|||
QuatF& interpolate( const QuatF & q1, const QuatF & q2, F32 t );
|
||||
F32 angleBetween( const QuatF & q );
|
||||
|
||||
Point3F& mulP(const Point3F& a, Point3F* b); // r = p * this
|
||||
Point3F& mulP(const Point3F& a, Point3F* r) const; // r = p * this
|
||||
QuatF& mul(const QuatF& a, const QuatF& b); // This = a * b
|
||||
|
||||
// Vectors passed in must be normalized
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue