Some times contact normal is unpredictable. Especially on edges. May be it depends on what object is A and what object is B in collision pair and when they switch in a pair then normal switch as well.
What is the best way to override contact normal algorithm?
I can check object's UserPointer and if I have a certain pair of objects then I set certain, predictable normal.
e.g. normal could be always directed from center of sphere or always be normal to plate even on plates edges.
Thank You
Custom contact normal algorithm
-
- Posts: 82
- Joined: Sun Apr 04, 2010 10:08 pm
Re: Custom contact normal algorithm
I plan to override
btCollisionAlgorithm* btCollisionDispatcher::findAlgorithm(btCollisionObject* body0,btCollisionObject* body1,btPersistentManifold* sharedManifold = 0);
I will do my own btCollisionAlgorithm and it will wrap original btCollisionAlgorithm but will modify normals
What do you think?
btCollisionAlgorithm* btCollisionDispatcher::findAlgorithm(btCollisionObject* body0,btCollisionObject* body1,btPersistentManifold* sharedManifold = 0);
I will do my own btCollisionAlgorithm and it will wrap original btCollisionAlgorithm but will modify normals
What do you think?
-
- Posts: 82
- Joined: Sun Apr 04, 2010 10:08 pm
Re: Custom contact normal algorithm
file btCollisionWorld.cpp
findAlgorithm - allocates new btCollisionAlgorithm
But process method frees it.
If I override findAlgorithm and it will allocate 2 btCollisionAlgorithms (original one and wrapper that will correct contact normal) then process will release only last wrapper algorithm.
I have to teach my wrapper to free original btCollisionAlgorithm
and algorithm return contact points by calling addContactPoint method in btManifoldResult
----
It would be much simpler and cleaner to put callback after or just modify the line
in btCollisionWorld.cpp
I do not wish to modify BulletPhysics
But it would be the easiest place,
1. I can detect here if colliding objects are objects I am interested in
2. I can call processCollision with my own contactPointResult2 object that will override normals and then call contactPointResult
Code: Select all
virtual bool process(const btBroadphaseProxy* proxy)
{
btCollisionObject* collisionObject = (btCollisionObject*)proxy->m_clientObject;
if (collisionObject == m_collisionObject)
return true;
//only perform raycast if filterMask matches
if(m_resultCallback.needsCollision(collisionObject->getBroadphaseHandle()))
{
btCollisionAlgorithm* algorithm = m_world->getDispatcher()->findAlgorithm(m_collisionObject,collisionObject);
if (algorithm)
{
btBridgedManifoldResult contactPointResult(m_collisionObject,collisionObject, m_resultCallback);
//discrete collision detection query
algorithm->processCollision(m_collisionObject,collisionObject, m_world->getDispatchInfo(),&contactPointResult);
algorithm->~btCollisionAlgorithm();
m_world->getDispatcher()->freeCollisionAlgorithm(algorithm);
}
}
return true;
}
findAlgorithm - allocates new btCollisionAlgorithm
But process method frees it.
If I override findAlgorithm and it will allocate 2 btCollisionAlgorithms (original one and wrapper that will correct contact normal) then process will release only last wrapper algorithm.
I have to teach my wrapper to free original btCollisionAlgorithm
and algorithm return contact points by calling addContactPoint method in btManifoldResult
----
It would be much simpler and cleaner to put callback after or just modify the line
Code: Select all
algorithm->processCollision(m_collisionObject,collisionObject, m_world->getDispatchInfo(),&contactPointResult);
I do not wish to modify BulletPhysics
But it would be the easiest place,
1. I can detect here if colliding objects are objects I am interested in
2. I can call processCollision with my own contactPointResult2 object that will override normals and then call contactPointResult
-
- Posts: 82
- Joined: Sun Apr 04, 2010 10:08 pm
Re: Custom contact normal algorithm
Am I allowed to modify normal in gContactAddedCallback ???
I use it to detect sounds )) But I just understood that I can adjust normals here. Right???
I use it to detect sounds )) But I just understood that I can adjust normals here. Right???
-
- Posts: 82
- Joined: Sun Apr 04, 2010 10:08 pm
Re: Custom contact normal algorithm
gContactAddedCallback works to override normal