Sleeping system

Please don't post Bullet support questions here, use the above forums instead.
Steinmetz
Posts: 26
Joined: Sat Dec 15, 2007 12:03 am

Sleeping system

Post by Steinmetz »

After implementing a simple broadphase (Sweep and Prune at one axis), the next performance leak is the collision response. The most helpful thing seems to be implementing a sleeping system, so that still bodies go asleep after short time and are not integrated anymore.
That's what I do until now:
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;
}
Now I have a problem:
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