Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What effect does "wake" have in b2Body::ApplyLinearImpulse?

Tags:

box2d

I am using Box2d v2.3 The following box2d method takes a bool "wake" :

inline void b2Body::ApplyLinearImpulse(const b2Vec2& impulse, const b2Vec2& point, bool wake)

What does it do? Regardless of whether I set it to YES or NO, it doesn't seem to noticeable impact my physics.

Earlier versions of Box2d did not accept the bool - they only took impulse and point.

EDIT: Likewise so does the following method:

inline void b2Body::ApplyForce(const b2Vec2& force, const b2Vec2& point, bool wake)
like image 887
Rahul Iyer Avatar asked Jan 01 '14 09:01

Rahul Iyer


1 Answers

Taken from the official Box2D manual:

What does sleep mean? Well it is expensive to simulate bodies, so the less we have to simulate the better. When a body comes to rest we would like to stop simulating it.

When Box2D determines that a body (or group of bodies) has come to rest, the body enters a sleep state which has very little CPU overhead. If a body is awake and collides with a sleeping body, then the sleeping body wakes up. Bodies will also wake up if a joint or contact attached to them is destroyed. You can also wake a body manually.

So the sleepmode is a way to improve performance. It makes sense to wake up a body, when you apply a force to it, so in case it is not already awake anyway, it will wake up and be simulated, because that's what you probably want.

In case it is already awake, it doesn't matter. It won't be set to sleep with wake=false and waking it up again, doesn't change anything. To be safe, you should always use wake=true. In the worst case it hurts the performance a little bit, but only for a little while. Then Box2D will set it back to sleep anyway.

like image 148
noone Avatar answered Sep 26 '22 17:09

noone