Page 1 of 1

matrix4::rotateVect is transposed?

Posted: Wed Sep 01, 2004 12:02 pm
by Electron
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

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]);
	}
I wrote a emulating the Newton function, and mine behaves as I would expect it to

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]);
}  
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.

Posted: Fri Sep 03, 2004 12:52 am
by arras
Well I don't know if it realy helps but when I needed to rotate movement vector to get new position of node in 3d based on node rotation, rotateVect() was not working as I would expect. Instead I am using transformVect() which does the job.

Posted: Fri Sep 03, 2004 12:05 pm
by calimero
Yes I'm a little puzzled by the difference between transformVect and rotateVect.
If I remember correctly when I was in school (9 years ago !!!)
the only difference between the 2 methods has to be in the final terms (which make the translation) ie : M[12], M[13], M[14]

as a quick overview I expect transformVect = rotateVect + translateVect
but it doesn't seem to be that in the engine. the rotate methods seems to use a kind of transposed matrix.

Finally I'm not sure of what is the good representation but the inconstency between the 2 methods is very strange (pretty sure there is a bug).

Posted: Fri Sep 03, 2004 8:07 pm
by Electron
exactly. transformVect should = ratateVect + translateVect
I beleive that if my function (if made into a matrix4 function) would make that true. My function is nothingm ore than the original rotate function transposed. Did niko forget what memory ordering he was using as he wrote that function?

Posted: Sat Sep 04, 2004 6:29 am
by calimero
perhaps it is time to put this topic in the bug forum ?
It may have strong impact, it's strange nobody spot this one before.

Posted: Fri Mar 04, 2005 8:53 pm
by jox

Posted: Sat Mar 05, 2005 12:14 am
by Electron
thanks jox. I should have done that a long time ago :oops:

Posted: Mon Mar 07, 2005 12:44 pm
by calimero
Hello jox and electron,

It's a long time since I went on this forum, have lot of things to do that keep me away of the irrlicht stuff. I already created a topic in the forum bug long ago but with no result :-(

nice to see It's taken into account now.

Now I have to understand how irrlicht and Nx have evolved to see which way I will follow

Posted: Fri Mar 11, 2005 2:43 pm
by Thulsa Doom
Hi Electron!

Irrlicht uses a left hand side coordinate system, while usually one would exspect a right hand side coordinate system. Both systems can be transformed into each other by transposed matrices.

Greets T.D.