Simulating force from single point

brianh
Posts: 1
Joined: Fri Mar 28, 2008 5:44 pm

Simulating force from single point

Post by brianh »

Is there a built-in way for simulating a small sphere in space that has an repelling effect on the objects around it? If not, then how does this method sound:

Each frame, find all dynamic objects within a certain radius of the sphere. Then for each object, apply a tangental force.

Thanks,

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

Re: Simulating force from single point

Post by Erwin Coumans »

brianh wrote: Each frame, find all dynamic objects within a certain radius of the sphere. Then for each object, apply a tangental force.
There is no out-of-the-box demo that shows how to do this, but it should be fairly easy.

1) create a btSphereShape and btRigidBody (see localCreateRigidBody in the demos)
2) disable collision response
3) add custom callback, and apply the desired impulse for each object colliding within this callback

You can see the use of the collision callback in Bullet/Demos/ConcaveDemo/ConcaveCollisionDemo.cpp, look for 'CustomMaterialCombinerCallback'.

Enabling the collision callback and disabling collision response can be done using collision flags:

Code: Select all

  //enable custom material callback
        rigidBody->setCollisionFlags(staticBody->getCollisionFlags()  | btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK | btCollisionObject::CF_NO_CONTACT_RESPONSE);
Hope this helps,
Erwin