kinematic issue again

Post Reply
topcomer
Posts: 32
Joined: Thu Sep 21, 2006 1:53 pm
Location: sweden but italian

kinematic issue again

Post by topcomer »

I'm using ConcavePhysicsDemo.ccp with the following modification inside shootTrimesh():

mass =0.f;
body->setCollisionFlags( body->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT );
body->setActivationState(DISABLE_DEACTIVATION);


and the follwing function called just after renderme() in clientMoveAndDisplay():

void ConcaveDemo::updateExtMesh()
{
int numManifolds = m_dynamicsWorld->getDispatcher()->getNumManifolds();
for( int j = 0; j < numManifolds; j++ )
{
// Get collision structures
btPersistentManifold* contactManifold = m_dynamicsWorld->getDispatcher()->getManifoldByIndexInternal(j);
btCollisionObject* obA = static_cast<btCollisionObject*>(contactManifold->getBody0());
btCollisionObject* obB = static_cast<btCollisionObject*>(contactManifold->getBody1());
contactManifold->refreshContactPoints(obA->getWorldTransform(),obB->getWorldTransform());

int numContacts = contactManifold->getNumContacts();
for( int k = 0; k < numContacts; k++ )
{
btManifoldPoint& pt = contactManifold->getContactPoint(k);

// Get contact points
btVector3 ptA = pt.getPositionWorldOnA();
btVector3 ptB = pt.getPositionWorldOnB();
btVector3 normal = pt.m_normalWorldOnB;
btVector3 vel;

if( obA->isKinematicObject() && obB->isStaticObject() )
std::cout << "B STATIC vs A KINEMATIC" << std::endl;
if( obB->isKinematicObject() && obA->isStaticObject() )
std::cout << "A STATIC vs B KINEMATIC" << std::endl;
if( obA->isKinematicObject() && (obB->isStaticOrKinematicObject() == false) )
std::cout << "B DYNAMIC vs A KINEMATIC" << std::endl;
if( obB->isKinematicObject() && (obA->isStaticOrKinematicObject() == false) )
std::cout << "A DYNAMIC vs B KINEMATIC" << std::endl;
}
}
}


The result is totally non-deterministic: when I shoot blocks (with the right button) against the bunny even though they always realistically collide, sometimes I get one of the messages, sometimes not, and also it happens to continue to get them when the collision is over. Has someone got a solution/explanation for this?

Thanks,
Alessio
User avatar
Erwin Coumans
Site Admin
Posts: 4232
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA
Contact:

Re: kinematic issue again

Post by Erwin Coumans »

topcomer wrote: The result is totally non-deterministic: when I shoot blocks (with the right button) against the bunny even though they always realistically collide, sometimes I get one of the messages, sometimes not, and also it happens to continue to get them when the collision is over. Has someone got a solution/explanation for this?
Your printf is outside the simulation loop. Multiple internal simulation steps might be taken, so a collision can occur and gets resolved. This will not get noticed outside the loop, unless you execute the printf right after the solver processes them.

This can be easily done, by deriving your own class from btSequentialImpulseConstraintSolver, and overriding the solveGroup method. First call the btSequentialImpulseConstraintSolver::solveGroup within your derived class, and then do your printf. We could simplify this process with a collisionPairProcessed callback, or ContactProcessed callback.

Contact points stay around for a while, until the distance becomes larger then a threshold. You can check the distance for each point, if you want to make sure.

Hope this helps,
Erwin
topcomer
Posts: 32
Joined: Thu Sep 21, 2006 1:53 pm
Location: sweden but italian

Re: kinematic issue again

Post by topcomer »

Ok I will use a callback then. I'm only afraid to process redundant contacts, that is something that is detected during the simulation loop but discarded by the solver.

Let's say for example that two blocks P and Q collide together but P also with the trimesh at the point A. To avoid penetration, both must be moved but P cannot bounce away from the trimesh due to the presence of Q and thus the contact point will now become B in the loop and perhaps also C and the end of the simulation. How can I get rid of or at least flag all these intermediate results?

Thanks,
Alessio

EDIT: with the following inside CustomMaterialCombinerCallback() I indeed get hundreds of collisions:

// Get collision structures
const btCollisionObject* obA = colObj0;
const btCollisionObject* obB = colObj1;

btManifoldPoint& pt = cp;

// Get contact points
btVector3 ptA = pt.getPositionWorldOnA();
btVector3 ptB = pt.getPositionWorldOnB();
btVector3 normal = pt.m_normalWorldOnB;
btVector3 vel;

if( obA->isKinematicObject() && obB->isStaticObject() )
std::cout << "B STATIC vs A KINEMATIC" << std::endl;
if( obB->isKinematicObject() && obA->isStaticObject() )
std::cout << "A STATIC vs B KINEMATIC" << std::endl;
if( obA->isKinematicObject() && (obB->isStaticOrKinematicObject() == false) )
std::cout << "B DYNAMIC vs A KINEMATIC" << std::endl;
if( obB->isKinematicObject() && (obA->isStaticOrKinematicObject() == false) )
std::cout << "A DYNAMIC vs B KINEMATIC" << std::endl;
/*if( (obA->isStaticOrKinematicObject() == false) && (obB->isStaticOrKinematicObject() == false) )
std::cout << "A DYNAMIC vs B DYNAMIC" << std::endl;*/
Post Reply