matrix4::rotateVect is transposed?
Posted: Wed Sep 01, 2004 12:02 pm
matrix4::rotateVect was not behaving as I would expect it to and when I looked at the rotateVector function in the dvector class that comes with the Newton physics examples(www.physicsengine.com) I saw that the two functions seemed transposed with regard to eachother,
The irrlicht function looks like this
I wrote a emulating the Newton function, and mine behaves as I would expect it to
It looks to me like the original function is performing dot product of row against row instead of row against column (or column against row, depending on how you visualize your matrices on paper.)
My matirx math is not good, so it's possible I made a mistake somewhere and the irrlicht function is actually correct, but it diodn't work for me and my new one did.
The irrlicht function looks like this
Code: Select all
inline void matrix4::rotateVect( vector3df& vect ) const
{
vector3df tmp = vect;
vect.X = -(tmp.X*M[0] + tmp.Y*M[1] + tmp.Z*M[2]);
vect.Y = -(tmp.X*M[4] + tmp.Y*M[5] + tmp.Z*M[6]);
vect.Z = -(tmp.X*M[8] + tmp.Y*M[9] + tmp.Z*M[10]);
}
Code: Select all
//This function is modeled after Newton function in their tutorials
vector3df rotateVector(matrix4& mat, vector3df& vec)
{
return vector3df(vec.X*mat.M[0] + vec.Y*mat.M[4] +vec.Z*mat.M[8],
vec.X*mat.M[1] + vec.Y*mat.M[5] + vec.Z * mat.M[9],
vec.X*mat.M[2] + vec.Y*mat.M[6] + vec.Z * mat.M[10]);
}
My matirx math is not good, so it's possible I made a mistake somewhere and the irrlicht function is actually correct, but it diodn't work for me and my new one did.