automatic deactivation (sleeping) questions

ola
Posts: 169
Joined: Sun Jan 14, 2007 7:56 pm
Location: Norway

automatic deactivation (sleeping) questions

Post by ola »

Hello all,

I seem to have some problems getting the rigid bodies in my game to automatically go to sleep/deactivate when they are lying still somewhere. I'm using bullet with double precision on Linux. I set up the physics world like this:

Code: Select all

 btCollisionDispatcher* dispatcher  = new btCollisionDispatcher();
 
 btVector3 world_min(btScalar(-1e30),btScalar(-1e30),btScalar(-1e30));
 btVector3 world_max(btScalar( 1e30),btScalar( 1e30),btScalar( 1e30));

 btBroadphaseInterface* pair_cache     = new btAxisSweep3(world_min,world_max);
 btConstraintSolver* constraint_solver = new btSequentialImpulseConstraintSolver();
 
physics_world_ = new btDiscreteDynamicsWorld(dispatcher,pair_cache,constraint_solver);

 //-----------------
 // Add the terrain 
 //-----------------
 
 btCollisionShape* terrain_collision_shape = new WbBulletTerrain(terrain_);
 btTransform terrain_transform;
 terrain_transform.setIdentity();
 terrain_transform.setOrigin(btVector3(0,0,0));
 btVector3 terrain_inertia(0,0,0);

 btDefaultMotionState* terrain_motion_state = new btDefaultMotionState(terrain_transform);
 btRigidBody* terrain_body = new btRigidBody(0.0, 
                                             terrain_motion_state, 
                                             terrain_collision_shape, 
                                             terrain_inertia,
                                             0.0,  // Linear damping
                                             0.0,  // Angular damping
                                             0.8,  // Friction
                                             1.0); // Restitution
 physics_world_->addRigidBody(terrain_body);
The WbBulletTerrain class is a mesh class derived from the btConcaveShape and it provides collision triangles from the terrain database, very similar to the btTriangleMeshShape.

Is there something that has to be done in order to have the rigidbodies automatically sleep, like they do in the CcdPhysicsDemo? I can't seem to find anything in that demo that does anything to influence this (except for the kinematic ground version that disables deactivation).

Also, I'm wondering about what the concept of simulation islands is all about. Is this something that has to be enabled, or does it work automatically by itself?

What does the world size that is set in btAxisSweep3(world_min,world_max); actually influence? I have set it so huge as the game world in our game covers the entire earth globe (like in Google Earth), but maybe this can cause something to break.

Best regards,
Ola
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: automatic deactivation (sleeping) questions

Post by Erwin Coumans »

ola wrote: Is there something that has to be done in order to have the rigidbodies automatically sleep, like they do in the CcdPhysicsDemo? I can't seem to find anything in that demo that does anything to influence this (except for the kinematic ground version that disables deactivation).

Also, I'm wondering about what the concept of simulation islands is all about. Is this something that has to be enabled, or does it work automatically by itself?

What does the world size that is set in btAxisSweep3(world_min,world_max); actually influence? I have set it so huge as the game world in our game covers the entire earth globe (like in Google Earth), but maybe this can cause something to break.
Sleeping should automatically work by default. The system will deactivate islands of objects that don't move. Islands are based on bounding box (aabb) overlap in the broadphase. If you use btAxis3Sweep, and provide too large world size, the AABB become extremely huge, and everything will be merged into one island.

You can better use the new bt32BitAxis3Sweep broadphase in Bullet 2.58. This would allow for larger worlds, and more objects. The future btMultiSap broadphase can help too. You can also consider to enable double precision build.

It is recommended to keep the world size (worldAabbMin/worldAabbMax) smaller, in meters. This improves performance and makes the AABB better fitting.

Thanks,
Erwin