mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-15 16:44:36 +00:00
Fixed angle conversion issues
Fixed a variable name and method that should be const. Also fixed several angle conversion functions that didn't convert the angle correct.
This commit is contained in:
parent
c7e0d83587
commit
ad267f0505
3 changed files with 43 additions and 28 deletions
|
|
@ -163,7 +163,7 @@ EulerF MatrixF::toEuler() const
|
||||||
const F32 * mat = m;
|
const F32 * mat = m;
|
||||||
|
|
||||||
EulerF r;
|
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)
|
if(mCos(r.x) != 0.f)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -32,33 +32,48 @@ const QuatF QuatF::Identity(0.0f,0.0f,0.0f,1.0f);
|
||||||
|
|
||||||
QuatF& QuatF::set( const EulerF & e )
|
QuatF& QuatF::set( const EulerF & e )
|
||||||
{
|
{
|
||||||
F32 cx, sx;
|
/*
|
||||||
F32 cy, sy;
|
F32 cx, sx;
|
||||||
F32 cz, sz;
|
F32 cy, sy;
|
||||||
mSinCos( e.x * 0.5f, sx, cx );
|
F32 cz, sz;
|
||||||
mSinCos( e.y * 0.5f, sy, cy );
|
mSinCos( -e.x * 0.5f, sx, cx );
|
||||||
mSinCos( e.z * 0.5f, sz, cz );
|
mSinCos( -e.y * 0.5f, sy, cy );
|
||||||
|
mSinCos( -e.z * 0.5f, sz, cz );
|
||||||
|
|
||||||
// Qyaw(z) = [ (0, 0, sin z/2), cos z/2 ]
|
// Qyaw(z) = [ (0, 0, sin z/2), cos z/2 ]
|
||||||
// Qpitch(x) = [ (sin x/2, 0, 0), cos x/2 ]
|
// Qpitch(x) = [ (sin x/2, 0, 0), cos x/2 ]
|
||||||
// Qroll(y) = [ (0, sin y/2, 0), cos y/2 ]
|
// Qroll(y) = [ (0, sin y/2, 0), cos y/2 ]
|
||||||
// this = Qresult = Qyaw*Qpitch*Qroll ZXY
|
// this = Qresult = Qyaw*Qpitch*Qroll ZXY
|
||||||
//
|
//
|
||||||
// The code that folows is a simplification of:
|
// The code that folows is a simplification of:
|
||||||
// roll*=pitch;
|
// roll*=pitch;
|
||||||
// roll*=yaw;
|
// roll*=yaw;
|
||||||
// *this = roll;
|
// *this = roll;
|
||||||
F32 cycz, sysz, sycz, cysz;
|
F32 cycz, sysz, sycz, cysz;
|
||||||
cycz = cy*cz;
|
cycz = cy*cz;
|
||||||
sysz = sy*sz;
|
sysz = sy*sz;
|
||||||
sycz = sy*cz;
|
sycz = sy*cz;
|
||||||
cysz = cy*sz;
|
cysz = cy*sz;
|
||||||
w = cycz*cx - sysz*sx;
|
w = cycz*cx + sysz*sx;
|
||||||
x = cycz*sx + sysz*cx;
|
x = cycz*sx + sysz*cx;
|
||||||
y = sycz*cx + cysz*sx;
|
y = sycz*cx - cysz*sx;
|
||||||
z = cysz*cx - sycz*sx;
|
z = cysz*cx - sycz*sx;
|
||||||
|
*/
|
||||||
|
// Assuming the angles are in radians.
|
||||||
|
F32 c1 = mCos(e.y/2.0f);
|
||||||
|
F32 s1 = mSin(e.y/2.0f);
|
||||||
|
F32 c2 = mCos(e.z/2.0f);
|
||||||
|
F32 s2 = mSin(e.z/2.0f);
|
||||||
|
F32 c3 = mCos(e.x/2.0f);
|
||||||
|
F32 s3 = mSin(e.x/2.0f);
|
||||||
|
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 )
|
QuatF& QuatF::operator *=( const QuatF & b )
|
||||||
|
|
@ -289,7 +304,7 @@ QuatF & QuatF::interpolate( const QuatF & q1, const QuatF & q2, F32 t )
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Point3F & QuatF::mulP(const Point3F& p, Point3F* r)
|
Point3F & QuatF::mulP(const Point3F& p, Point3F* r) const
|
||||||
{
|
{
|
||||||
QuatF qq;
|
QuatF qq;
|
||||||
QuatF qi = *this;
|
QuatF qi = *this;
|
||||||
|
|
|
||||||
|
|
@ -81,7 +81,7 @@ public:
|
||||||
QuatF& interpolate( const QuatF & q1, const QuatF & q2, F32 t );
|
QuatF& interpolate( const QuatF & q1, const QuatF & q2, F32 t );
|
||||||
F32 angleBetween( const QuatF & q );
|
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
|
QuatF& mul(const QuatF& a, const QuatF& b); // This = a * b
|
||||||
|
|
||||||
// Vectors passed in must be normalized
|
// Vectors passed in must be normalized
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue