btVector3.rotate()

Zenja
Posts: 14
Joined: Fri Jul 10, 2009 4:48 am

btVector3.rotate()

Post by Zenja »

Hi.

I seem to have stumbled onto an error with btVector3, the rotate() function in LinearMath/btVector3.h line 493. I've stumbled onto this while trying to apply a directional impulse at a particular point.

If I have a point (-2, -1, 0) which I want to rotate around an axis (eg. 0, 0, 1), there seems to be no effect (debugger shows that point doesn't change after calling rotate(). If I use an external vector library and rotate around the axis (0,0,1), I get valid results.

In effect, instead of doing the following (which doesn't work):

Code: Select all

btVector3 p1(-2, -1, 0);
p1.rotate(btVector3(0, 0, 1), z);
mRigidBody->applyImpulse(imp, p1);
I have to do the following (using external vector library):

Code: Select all

YVector3 p1(-2, -1, 0);
p1.Rotate(YVector3(0,0,1), z);
btVector3 p2(p1.x, p1.y, p1.z);
mRigidBody->applyImpulse(imp, p2);
I expect that when I rotate (-1, 0, 0) by PI (180 degrees) around the origin, the result should be (1, 0, 0). With the btVector3.rotate() function, I dont see any value change.
Le poussin
Posts: 1
Joined: Thu May 28, 2009 5:56 pm

Re: btVector3.rotate()

Post by Le poussin »

Vector3::rotate() does not modify the instance but returns the computed result.
The method should have been defined as const (fixed in r2204).

Thus, you have to do:

Code: Select all

btVector3 p1(-2, -1, 0);
p1 = p1.rotate(btVector3(0, 0, 1), z);
mRigidBody->applyImpulse(imp, p1);