Possible Math bug?
by Gonzo T. Clown · in Torque Game Engine · 03/14/2004 (6:25 pm) · 3 replies
I was browsing the math section of the engine when I noticed this....
QuatF& QuatF::set( const EulerF & e )
{
F32 cx, sx;
F32 cy, sy;
F32 cz, sz;
mSinCos( -e.x * F32(0.5), sx, cx );
mSinCos( -e.y * F32(0.5), sy, cy );
mSinCos( -e.z * F32(0.5), 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;
return *this;
}
Since "this" has been commented out in both places, how can anything but false or Zero be returned? If I'm making an idiot of myself, please tell me, I'm trying to learn more. But my understanding so far leads me to believe that this function will not work.
QuatF& QuatF::set( const EulerF & e )
{
F32 cx, sx;
F32 cy, sy;
F32 cz, sz;
mSinCos( -e.x * F32(0.5), sx, cx );
mSinCos( -e.y * F32(0.5), sy, cy );
mSinCos( -e.z * F32(0.5), 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;
return *this;
}
Since "this" has been commented out in both places, how can anything but false or Zero be returned? If I'm making an idiot of myself, please tell me, I'm trying to learn more. But my understanding so far leads me to believe that this function will not work.
About the author
Torque Owner John Vanderbeck
VanderGames
Let me see if I can type up something that makes it clear.. i'm very bad at teaching :(
class foo { foo* getFoo(); } foo* foo:getFoo(); { return this; } void main() { foo* pFoo; pFoo = new foo(); foo* pSameFoo; pSameFoo = pFoo->getFoo(); // pFoo and pSameFoo are now the same object }That code serves no REAL purpose other than to demonstrate. I hope its right. I'm very tired, but even if its syntacly (oh god thats not a word) incorrect, it should give you the idea.