
Working on some plant creatures. The vines are built using box2d and springs. They are really flexible but seem to collapse upon eachother, it turns into a mess. I would like to built up the structure of the vines with box2d segments but I can’t figure out a way to build simple lines that change dimensions, go figure. I know that chipmunk can do this but want to figure out a way to do this with box2d.
April 4th, 2009 at 9:26 am
Hi Todd,
i worked with JBox2D an has a similar problem. The only solution for me was to delete and create a new Shape in a Body on each Frame. The only Problem was that my instruction to delete and create was triggert in a moment when the World.Step() phase was in action an so I got crazy exceptions in irregular intervalls.
In my application I have 2 threads: on OpenGL Thread who triggers the World.step() method to update the simulation at the same intervall of the rendering and a second with my own code.
So i made a hack: I extend the org.jbox2d.dynamics.World class from the sources of JBox2D with a method to get the m_lock variable.
public Boolean getLock(){
return m_lock;
}
If you look in line 458 (step() method) you see that this is a flag to lock a lot of functions while the solver is working.
With this extension I’m able to check in my code if the Physik-Engine is in a crucial phase and wait:
My code:
while(m_world.getLock()){
//nothing:
}
//go ahead
//now i set a custom lock-flag to stop the call of the World.step() Method because my OpenGL Thread triggers this
_lock= true;
//now i can create and delete some shape or Body in the Physic-engine
_lock= false;//release the flag. Now the Physic-engine gets updated.
…..
if(_lock==False){ m_world.step(_timeStep,_settings.iterationCount);
}
Cheers