Irrlicht and ODE! Problems, questions and misunderstandings

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
WickedImp
Posts: 8
Joined: Tue Mar 16, 2004 10:49 am
Location: C=DE/ST=NRW/L=Blankenrode

Irrlicht and ODE! Problems, questions and misunderstandings

Post by WickedImp »

Hi community,

started my first project using Irrlicht and OpenDE. Personally I like the concept of using node trees to relatively set position and rotation of child nodes. For now I wrote a custom node to implement ODE bodies and geoms and it used IAnimatedMeshSceneNode to display the mesh and its shadow (its called cNodeBody). As long as all cNodeBody nodes have the same parent the ode simulation is working correct (relative coordinates of my objects are same as the absolute). In my example I added a car chassis and placed some wheels above it. The wheels fall down and roll away. Here are my functions which set the position and rotation, and the one called on every frame to update the irrlicht node pos/rot from the ode body:

Code: Select all

void cNodeBody::setPosition()
{
    dReal *posOde = (dReal*)dGeomGetPosition( m_geom );
    
    vector3df posIrr( (f32)posOde[0], (f32)posOde[1], (f32)posOde[2] );
    ISceneNode::setPosition( posIrr );

    dQuaternion result;
    dGeomGetQuaternion( m_geom, result );

    vector3df rot;
    quaternion quat( (f32)result[1], (f32)result[2], (f32)result[3], (f32)result[0] );
    quat.toEuler( rot );
    vector3df degrees( rot.X*180/PI, rot.Y*180/PI, rot.Z*180/PI );
    ISceneNode::setRotation( degrees );
}

void cNodeBody::setPosition( const vector3df &newpos )
{
    ISceneNode::setPosition( newpos );

    dBody::setPosition( newpos.X, newpos.Y, newpos.Z );
}

void cNodeBody::setRotation( const vector3df &newrot )
{
    ISceneNode::setRotation( newrot );

    dMatrix4 r;
    dRFromEulerAngles( r, newrot.X*PI/180, newrot.Y*PI/180, newrot.Z*PI/180 );
    dBody::setRotation( r );
}
Now I want to make this work if the wheels are child nodes of the chassis. I rewrote setPosition(vector3df) and setRotation(vector3df) to first set relative position/rotation then get the absolute tranformation matrix and get the translation or rotation from it and use this values to set the absolute position/rotation of the ode body:

Code: Select all

void cNodeBody::setPosition( const vector3df &newpos )
{
    ISceneNode::setPosition( newpos );
    
    matrix4 m = ISceneNode::getAbsoluteTransformation().getTransposed();
    vector3df abspos = m.getTranslation();
    
    dBody::setPosition( abspos.X, abspos.Y, abspos.Z );
}

void cNodeBody::setRotation( const vector3df &newrot )
{
    ISceneNode::setRotation( newrot );

    matrix4 m = ISceneNode::getAbsoluteTransformation().getTransposed();
    vector3df absrot = m.getRotationDegrees();

    dMatrix4 r;
    dRFromEulerAngles( r, absrot.X*PI/180, absrot.Y*PI/180, absrot.Z*PI/180 );
    dBody::setRotation( r );
}
To test it I did not change setPosition() and I did not make the wheels childs of the chassis. From what I understand it should not change the behaviour of the simulation at all. Wheels should still fall down onto the chassis.
Boom - does not work at all! Simulation explodes! I commented out the collide and quickstep stuff to disable the simulation. After first frame chassis and wheels are all set to zero position by a call to setPosition() - means something is wrong with the why I use the absolute tranformation matrix to set the position and rotation. They seem to stay at (0,0,0) on ODEs side.

What's wrong? Somebody able to help? Complete source code available here: http://www.thirdgate.de/share/trippingrc.zip
Brainsaw
Posts: 1183
Joined: Wed Jan 07, 2004 12:57 pm
Location: Bavaria

Post by Brainsaw »

For my Irrlicht-ODE wrapper (see signature) I didn't find a solution for that (maybe I'm just too lazy ... ask my former teachers ;) ) I simply implemented a break in the tree structure of the scene. If a body is child of another body some code is used that makes the ODE world (in my wrapper the root node for all physical objects) the parent of this body. This breaks up some of the things for Irrlicht (maybe it costs some performance, and you have to take care of all nodes if you want to hide them), but it works. Since I'm using ODE for all movement it's (for me) OK that the subtree is broken, as it changes Irrlicht's view of the scene to ODE's view (all position and rotation values are global).
Dustbin::Games on the web: https://www.dustbin-online.de/

Dustbin::Games on facebook: https://www.facebook.com/dustbingames/
Dustbin::Games on twitter: https://twitter.com/dustbingames
WickedImp
Posts: 8
Joined: Tue Mar 16, 2004 10:49 am
Location: C=DE/ST=NRW/L=Blankenrode

Post by WickedImp »

Thx for the info Brainsaw,

looked at the IrrODE-Wrapper already, but decided not to use it. Want to learn Irrlicht and ODE from the beginning.

But what really irritates me is that it seems that there is nothing inside the absolute transformation matrix... otherwise the bodies should be shown where I placed them, even if I not use the tree structure of Irr.

I will do some tests with this if I get some more time. But maybe someone can explain this to me?!?!
Post Reply