[SOLVED]BodyIterator

albino

19-12-2007 15:44:08

how do i use the bodyiterator

so i can add certain force to bodies in world which has
type of movable for example?
_________________________________
OK found the solution, after all it was tiny typo in the code (forgot to set teh iterator function as static void)
I'll write it in here in case somebody else needs the info.

in header file:
void runSimulation();
static void bodyIterator(OgreNewt::Body *me);

where runSimulation() is function i used to start the simulation to run, items drop down etc.
and bodyIterator is the function which will be called each time a body is found. (make sure its static void)

then in source file:
void World::runSimulation()
{
OgreNewt::BodyIterator::getSingleton().Init( physWorld );
OgreNewt::BodyIterator::getSingleton().go( World::bodyIterator );
}

void World::bodyIterator(OgreNewt::Body *me)
{
if(me->getType() == MOVABLE)
{
me->unFreeze();
me->setStandardForceCallback();
}
}

in runSimulation setup the iterator and in iterator function do whatever you want for the found body. In this case unfreeze it and add gravity if object is movable.

i hope this helps