Orientation problem (swapped axes ?) [solved]

Gunwizard

06-08-2007 08:24:03

Hello OgreBullet developers,

We are using the Bullet engine and the OgreBullet wrapper for a multiplayer game called "Verdun-Online" (http://www.verdun-online.com/index.php)

However, i have quite a strange problem atm. In short, the synchronisation of Bullet's rigid bodies and Ogre's scene nodes is messed up. I slightly modified the wrapper classes so far and i probably made a silly mistake there, but i can't see where the problem is.
The orientation of rigid bodies, though correctly set to identity at the start, simply doesn't fit the display of debug objects/meshes. I tried to use the inverse transform for the display of debug shapes, which somehow aligns them to the aabbs again, but that doesn't seem to be the real problem.
Also the bodies are positioned correctly, but rotate in the wrong direction, when torque is applied or when they collide. As far as i could figure out, the axes are swapped from (x,y,z) to (-z,y,-x), actually making the coordinate system left-handed (sic!)

This might be related to the fact that we use the Z-axis for the up direction instead of Y (Ogre's standard), but i can't see where this causes trouble :? . I used SceneNode::setFixedYawAxis(true, Ogre::Vector3::UNIT_Z); but i don't think this should have any influence since nodes are not yawed/pitched/rolled by Bullet/OgreBullet. Sorry for not posting much code here, but it's just not that different from the original wrapper.

Does someone have similar problems ? Any hints and ideas are appreciated. Thanks for your help in advance :)

Best regards
Lukas Toenne

Gunwizard

09-08-2007 07:36:52

[Update]: I think i found the error :D

The BtOgreConverter class constructs an Ogre::Quaternion with the argument order (x, y, z, w):

static Ogre::Quaternion to(const btQuaternion &Q)
{
return Ogre::Quaternion(Q.x(), Q.y(), Q.z(), Q[3]);
};


But the Ogre::Quaternion constructor wants them in the order (w, x, y, z) actually:

static Ogre::Quaternion to(const btQuaternion &Q)
{
return Ogre::Quaternion(Q.w(), Q.x(), Q.y(), Q.z());
};


Please check this !
I assume this is also the reason why the OgreBulletCollisions::ObjectState sets the transform directly with Quaternion elements instead of using the converter - i used it, so the axes were messed up :wink: . Some other problems persist (debug objects inverted or so), so expect further updates. I hope to be able to contribute to this project as our game engine advances.

Gunwizard

14-08-2007 13:04:21

Update on the debug objects:

I think the transformation of the line coordinates in CollisionShape::drawConvexWireFrame is wrong. Currently it is

// apply transformation
if (hasVecTransform)
curVec -= pos;
if (hasQuatTransform)
curVec = quat * curVec;


but i think it should be

// apply transformation
if (hasQuatTransform)
curVec = quat * curVec;
if (hasVecTransform)
curVec += pos;


That seems to give me the correct alignment of debug objects and rigid bodies.

Chaster

15-10-2007 21:56:22

I think there is still some sort of problem with the conversion from Ogre Quaternions to Bullet Quaternions. I'm not sure what the problem is, but I'm getting pretty weird behavior (friction force being applied backwards!) which I suspect is related to this ..

UPDATE: Yeah, looks like OgreBTConverter::to() doesn't work quite right, but I'm not sure exactly WHY... At least I've localized it, but man what a pain in the neck..

UPDATE2: Scratch that. The problem is with my code, not OgreBullet (or bullet for that matter). A very tricky problem with updates (mixing kinematics and rigid bodies...)

Chaster