That's what I do until now:
Now I have a problem:rigidBody.handle(float dt){
handleSleeping(dt)
if (sleeps) { return; }
else{
integrateVelocities(dt)
}
}
rigidBody.integrateForces(float dt){
if(sleeps) return;
...
}
rigidBody.handleSleeping(float dt){
if (energy < treshold){
sleepTime += dt;
if (sleepTime > timeNeeded){
sleep();
}
}
else{
wakeUp()
}
}
rigidBody.sleep(){
sleeps = true;
vel = 0, 0;
avel = 0;
}
rigidBody.wakeUp(){
sleeps = false;
sleepTime = 0;
}
And in the collision handler:
if(( b1.isStatic() || b1.isSleeping() ) && ( b2.isStatic() || b2.isSleeping())){
do not collide;
}
What to do in the applyForce and applyImpulse functions ... I can't wake a body up if a force is applied, because it could be gravity or another force that was taking effect before the body went to sleep... But if a new force comes in effect, the body must be waked up.
I think I am missing something here, could anyone please give me a hint or link a paper, where this is discussed? I couldn't find anything on this topic, but I think this is too important, that there could be nothing about it.
Thanks