[ODE] New to List
Don Burns
don at andesengineering.com
Tue May 4 06:18:50 MST 2004
On Tue, 4 May 2004, Lonnie Cumberland wrote:
> Hello All,
>
> Actually, my project is using the Open Scene Graph for Linux and I need
> to add in some Physics. Came across ODE and it looked like a potential
> match for this.
>
Hi Lonnie,
I'll answer from the OSG side of the house. My approach to learning ODE,
then applying it to Open Scene Graph went something like this.
1. Copy an example and strip out the graphics. test_boxstack.cpp is a
good one, for example. The graphics calls all start with the 'ds' (draw
stuff) prefix. Once you have this working satisfactorily add OSG
graphics.
2. Create a scene graph with shapes that are equivalent to the ode shapes.
Use osg::ShapeDrawables (box, cylinder, sphere, etc..). For each shape,
parent it with a osg::MatrixTransform, with an UpdateCallback that stores
a reference to the ode dBodyID which the shape represents.
3. In the UpdateCallback functor, query the dBody() parameters and apply
them to an osg::Matrix like this:
osg::MatrixTransform *tx = dynamic_cast<osg::MatrixTransform *>(node);
if( tx != 0L )
{
const dReal *d = dBodyGetPosition(_ODEbody);
const dReal *r = dBodyGetRotation(_ODEbody);
osg::Matrix mat ( r[0], r[4], r[8], 0,
r[1], r[5], r[9], 0,
r[2], r[6], r[10], 0,
d[0], d[1], d[2], 1.0 );
tx->setMatrix( mat );
}
4. For collisions with the ground plane, you can use the
osgUtil::InterSectVisitor, to get the intersect with the ground.
osgUtil::IntersectVisitor returns a point of intersection and a normal,
from which you can derive a plane equation. What I do is cache a
"currentGroundPlane", and replace it if it has changed on frame by frame
basis, removing the old one (dGeomDestroy()) and creating a new one
( dCreatePlane()).
5. Have fun with it! OpenSceneGraph and ODE are a great match.
Cheers,
-don
More information about the ODE
mailing list