I'm trying to make an object pool for objects that add and remove frequently, such as arrows and machine gun bullets.
I tried setActivationState() and forceActivationState(), but neither of them worked, other rigidbody still collide with them when their state
has been set to DISABLE_SIMULATION.
Any suggestions?
How to disbale simulation for a rigidbody?
-
- Posts: 135
- Joined: Fri Nov 04, 2005 2:22 pm
Re: How to disbale simulation for a rigidbody?
you try like this?
rigidBody->setCollisionFlags(rigidBody->getCollisionFlags() | btCollisionObject::CF_NO_CONTACT_RESPONSE);
...
rigidBody->setCollisionFlags(rigidBody->getCollisionFlags() & ~btCollisionObject::CF_NO_CONTACT_RESPONSE);
here an example
https://www.youtube.com/watch?v=JhG-_PxwlsQ
...
https://www.youtube.com/watch?v=E-HPPsEUa4I
rigidBody->setCollisionFlags(rigidBody->getCollisionFlags() | btCollisionObject::CF_NO_CONTACT_RESPONSE);
...
rigidBody->setCollisionFlags(rigidBody->getCollisionFlags() & ~btCollisionObject::CF_NO_CONTACT_RESPONSE);
here an example
https://www.youtube.com/watch?v=JhG-_PxwlsQ
...
https://www.youtube.com/watch?v=E-HPPsEUa4I
-
- Posts: 10
- Joined: Fri Feb 19, 2016 2:04 am
Re: How to disbale simulation for a rigidbody?
Thank you, it works, though I still get collisions in getManifoldByIndexInternal(),Typhontaur wrote:you try like this?
rigidBody->setCollisionFlags(rigidBody->getCollisionFlags() | btCollisionObject::CF_NO_CONTACT_RESPONSE);
...
rigidBody->setCollisionFlags(rigidBody->getCollisionFlags() & ~btCollisionObject::CF_NO_CONTACT_RESPONSE);
here an example
https://www.youtube.com/watch?v=JhG-_PxwlsQ
...
https://www.youtube.com/watch?v=E-HPPsEUa4I
would that influence the performance by doing collision detection on disabled object? How to disable it from collision detection as well?
-
- Posts: 135
- Joined: Fri Nov 04, 2005 2:22 pm
Re: How to disbale simulation for a rigidbody?
I dont know much about getManifoldByIndexInternal(), I never used it...
In my engine, I use also :
for disable:
body->setActivationState(ISLAND_SLEEPING);
body->setCollisionFlags(body->getCollisionFlags() | btCollisionObject::CF_STATIC_OBJECT);
for enable:
body->setActivationState(ACTIVE_TAG);
body->setCollisionFlags(body->getCollisionFlags() & ~btCollisionObject::CF_STATIC_OBJECT);
I hope to help
In my engine, I use also :
for disable:
body->setActivationState(ISLAND_SLEEPING);
body->setCollisionFlags(body->getCollisionFlags() | btCollisionObject::CF_STATIC_OBJECT);
for enable:
body->setActivationState(ACTIVE_TAG);
body->setCollisionFlags(body->getCollisionFlags() & ~btCollisionObject::CF_STATIC_OBJECT);
I hope to help
-
- Posts: 10
- Joined: Fri Feb 19, 2016 2:04 am
Re: How to disbale simulation for a rigidbody?
Thank you.
Basically, I use getManifoldByIndexInternal() to implement custom collision callback.
From my test,your code indeed disable the physics simulation but did not disable the collision detection.
I can still get the information when two objects overlapping each other( one of them is set disabled).
My question is, does this have any influence upon the overall performance?
Basically, I use getManifoldByIndexInternal() to implement custom collision callback.
From my test,your code indeed disable the physics simulation but did not disable the collision detection.
I can still get the information when two objects overlapping each other( one of them is set disabled).
My question is, does this have any influence upon the overall performance?
-
- Posts: 10
- Joined: Fri Feb 19, 2016 2:04 am
Re: How to disbale simulation for a rigidbody?
OK, after hours of search and try, I got a solution.
Use collision filter group to filter out the disabled object.
Set the filter group at the begining
Then write a custom filter callback
register it,
When adding rigid body, set then in active group
When you want to disable a object,first stop simulate the rigid body, then change
the filter group to disabled group(it takes me a long time to find out how to change filter group without removing and re-adding object)
Then you won't get any simulation and collision callback on this object any more.
The drawback of this method is, aabb match still take place before filtering, to stop physics COMPLETELY on disabled object requires modification
on the broadphase. I'll appreciate it if anyone knows how to achieve this goal without change API
Use collision filter group to filter out the disabled object.
Set the filter group at the begining
Code: Select all
int groupActive=1;
int groupDisable=2;
Code: Select all
struct filterCallback : public btOverlapFilterCallback
{
virtual bool needBroadphaseCollision(btBroadphaseProxy*proxy0,btBroadphaseProxy*proxy1)const
{
bool collides=(proxy0->m_collisionFilterGroup&groupActive)&&(proxy1->m_collisionFilterGroup&groupActive);
return collides;
}
};
Code: Select all
btOverlapFilterCallback*filtercbk=new filterCallback();
dynamicsWorld->getPairCache()->setOverlapFilterCallback(filtercbk);
Code: Select all
dynamicsWorld->addRigidBody(body,groupActive,groupActive);
the filter group to disabled group(it takes me a long time to find out how to change filter group without removing and re-adding object)
Code: Select all
body->setActivationState(DISABLE_SIMULATION );
body->getBroadphaseProxy()->m_collisionFilterGroup=groupDisable;
The drawback of this method is, aabb match still take place before filtering, to stop physics COMPLETELY on disabled object requires modification
on the broadphase. I'll appreciate it if anyone knows how to achieve this goal without change API