Inactive objects still collides

Post Reply
lvella
Posts: 16
Joined: Thu Oct 30, 2008 4:28 pm

Inactive objects still collides

Post by lvella »

When I filled my sparse scene with many dynamic rigid bodies on startup, the game starts very slow, like one frame per 2 seconds, and after some time, I get good speed again. The simulation world is indeed very big, but most of the objects should remain deactivated until the player get to it and interact. I believed the problem was because all the rigid bodies were active at startup, and after some time they are automatically deactivated.

To try to improve the initial speed, I deactivated all those rigid bodies with:

Code: Select all

m_pRigidBody->setActivationState(WANTS_DEACTIVATION);
Now they remain stationary until the player character gets close to them. But for my surprise, they are still generating contact points, and the first few seconds speed are not better. Using gprof I could determine that most of this time is spent on

Code: Select all

btConvexHullShape::localGetSupportingVertexWithoutMargin
After some time, precisely when the good speed is attained, they stop generating contact points.

So it seems dynamics activation is dissociated from collision activation. Is there a way to completely deactivate a rigid body, so it won't move nor generate contact points until auto or manually reactivated?

In the future, I may add the bodies to the world dynamically, based on info from the scene culling algorithm, but the best solution is still unknown.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA
Contact:

Re: Inactive objects still collides

Post by Erwin Coumans »

You should use

Code: Select all

object->setActivationState(ISLAND_SLEEPING);
Does that help?
Erwin
lvella
Posts: 16
Joined: Thu Oct 30, 2008 4:28 pm

Re: Inactive objects still collides

Post by lvella »

Changing from WANTS_DEACTIVATION to ISLAND_SLEEPING made no difference, but inserting the

Code: Select all

object->setActivationState(ISLAND_SLEEPING);
before inserting the rigid body into the world made the magic.
If the rigid body is inserted into the world deactivated, no contact point is generated until after its activation.
lvella
Posts: 16
Joined: Thu Oct 30, 2008 4:28 pm

Re: Inactive objects still collides

Post by lvella »

Ok, my bad. Forget about the last post. There is nothing to do with when the rigid body is deactivated or inserted in the world.

The problem is indeed not related to whether I use ISLAND_SLEEPING or WANTS_DEACTIVATION, both works now. To solve the problem, I had to deactivate at startup the both new dynamic bodies and the static scenery.

To skip collision detection, both bodies needs to be deactivated, and the scenery where the dynamic objects stood upon where active.

That said, do you think this change will do any bad? Static-static collision is handled by broadphase, but static-inactive is not.

btCollisionDispatcher.cpp:184, needsCollision()

Code: Select all

-	if ((!body0->isActive()) && (!body1->isActive()))
+	if ((!body0->isActive() || body0->isStaticObject()) && (!body1->isActive() || body1->isStaticObject()))
		needsCollision = false;
pico
Posts: 229
Joined: Sun Sep 30, 2007 7:58 am

Re: Inactive objects still collides

Post by pico »

Hi,

people may want to get collisions for non active bodies and static bodies. An example would be to query if there are bodies within a 'trigger' volume. The trigger volume is static and the bodies are sleeping. With your modification there would be no more bodies reported after they fall asleep.

Anyway, your behaviour is fine aswell if you dont want such queries. So just override the virtual needsCollision routine to fit your needs.

Beside that, i'm not sure but i think bullet caches the contact points and recognizes if a body didn't moved. So no new collisions should be calculated, but the contacts would still be reported in the manifolds.
mohican
Posts: 17
Joined: Mon Aug 25, 2008 5:12 pm

Re: Inactive objects still collides

Post by mohican »

lvella wrote: The problem is indeed not related to whether I use ISLAND_SLEEPING or WANTS_DEACTIVATION, both works now. To solve the problem, I had to deactivate at startup the both new dynamic bodies and the static scenery.

To skip collision detection, both bodies needs to be deactivated, and the scenery where the dynamic objects stood upon where active.
Thanks so much for this tip Ivella!
I could not figure out how to load a world without the objects starting to move all over the place...
You saved my life!
:wink:
Post Reply