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 );
}
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 );
}
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