yawn... bug in matrix4.h (rotateVect) ;)

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
jox
Bug Slayer
Posts: 726
Joined: Thu Apr 22, 2004 6:55 pm
Location: Germany

yawn... bug in matrix4.h (rotateVect) ;)

Post by jox »

I just discovered a bug in matrix4::rotateVect() and found that Electron already did report about it at the beginning of September 2004...

http://irrlicht.sourceforge.net/phpBB2/ ... hp?p=21314

He put it in Advanced help though. I'm now doing what calimero proposed at the end of that thread:
calimero wrote: 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.
Niko, I guess you missed that one...

:)

Irrlicht 0.8:

In matrix4.h The old function:

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]);
	}
...should be replaced by:

Code: Select all

	inline void matrix4::rotateVect( vector3df& vect ) const
	{
		vector3df tmp = vect;
		vect.X = tmp.X*M[0] + tmp.Y*M[4] + tmp.Z*M[8];
		vect.Y = tmp.X*M[1] + tmp.Y*M[5] + tmp.Z*M[9];
		vect.Z = tmp.X*M[2] + tmp.Y*M[6] + tmp.Z*M[10];
	}
jox
It is like it is. And because it is like it is, things are like they are.
niko
Site Admin
Posts: 1759
Joined: Fri Aug 22, 2003 4:44 am
Location: Vienna, Austria
Contact:

Post by niko »

Ah, yes, missed it sorry.
Sounds quite right, I think. The inverseRotateVect() method should be changed in the same way I think, and I hope this would not cause any code to broken :)
jox
Bug Slayer
Posts: 726
Joined: Thu Apr 22, 2004 6:55 pm
Location: Germany

Post by jox »

Mhm, the current inverseRotateVect() method looks ok to me like it is. What it does is rotate the vector in the opposite direction than rotateVect() does and thats what it's supposed to do I think.
If rotateVect() and inverseRotateVect() are applied in a row to the same vector then the vector has not changed (except the floating point errors :) ).
It is like it is. And because it is like it is, things are like they are.
Guest

Post by Guest »

Yeah, but I don't think the current rotate works quite the way it should.
If you try to set rotation using roll, pitch and heading, you'll see some strange behaviour: keep all angles at 0 except one angle and you've got no problems, but try applying two angles and you're in trouble.

You can compensate for it by loading your own matrix with the direction vectors you need and then getting the rotation from that.
Bad thing about that is that it wastes some cycles, should not be necessary and most people want to stay away from matrix math in the first place.
jox
Bug Slayer
Posts: 726
Joined: Thu Apr 22, 2004 6:55 pm
Location: Germany

Post by jox »

Guest wrote:Yeah, but I don't think the current rotate works quite the way it should.
what do you mean by "current rotate"? Didn't you read the first post? Of course the current rotate doesn't work well, otherwise I wouldn't have opened this thread.. or did I get you wrong here?
Guest wrote: If you try to set rotation using roll, pitch and heading, you'll see some strange behaviour: keep all angles at 0 except one angle and you've got no problems, but try applying two angles and you're in trouble.
How do you "set rotation using roll, pitch and heading"? In other words: what function(s) of matrix4 do you use for that? setRotationGegrees()?

With my corrected rotateVect() I got no trouble at all. Also with setting multiple angles. Maybe you have problems with the "evelness" of euler angles and the importance of the order that the angles are applied.

:?: :)

jox
It is like it is. And because it is like it is, things are like they are.
Guest

Post by Guest »

No, I got the Euler angles right, but I got your rotate/inverserotate comment wrong - I presumed that that was with the original code.
And with the current (0.8) rotate you do get the behaviour I described.

So basically the current rotate is invalid but the current inverserotate is correct?

If rotateVect is wrong, does the same then apply to the transform... methods?
Fingers
Posts: 38
Joined: Thu Feb 10, 2005 10:17 am
Location: South Africa

Post by Fingers »

Just a Question,

Could this possibly be why I'm experiencing strage behaviour in my rotation functions ??

Here is the thread for my problem
http://irrlicht.sourceforge.net/phpBB2/ ... php?t=5626

Thx.
Post Reply