matrix4::rotateVect is transposed?

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
Electron
Posts: 874
Joined: Sun Mar 14, 2004 12:05 am
Location: Massachusetts USA

matrix4::rotateVect is transposed?

Post 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.
You do a lot of programming? Really? I try to get some in, but the debugging keeps me pretty busy.

Crucible of Stars
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post 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.
calimero
Posts: 45
Joined: Sun Aug 08, 2004 4:31 pm
Location: Nice, France

Post 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).
Electron
Posts: 874
Joined: Sun Mar 14, 2004 12:05 am
Location: Massachusetts USA

Post 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?
You do a lot of programming? Really? I try to get some in, but the debugging keeps me pretty busy.

Crucible of Stars
calimero
Posts: 45
Joined: Sun Aug 08, 2004 4:31 pm
Location: Nice, France

Post 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.
jox
Bug Slayer
Posts: 726
Joined: Thu Apr 22, 2004 6:55 pm
Location: Germany

Post by jox »

It is like it is. And because it is like it is, things are like they are.
Electron
Posts: 874
Joined: Sun Mar 14, 2004 12:05 am
Location: Massachusetts USA

Post by Electron »

thanks jox. I should have done that a long time ago :oops:
You do a lot of programming? Really? I try to get some in, but the debugging keeps me pretty busy.

Crucible of Stars
calimero
Posts: 45
Joined: Sun Aug 08, 2004 4:31 pm
Location: Nice, France

Post 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
Thulsa Doom
Posts: 63
Joined: Thu Aug 05, 2004 9:40 am
Location: Germany

Post 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.
Post Reply