BulletPhysic: Strength / Impulse Contacts

I want to determine when one (ball) touches another object (goal), and I want to know the momentum of this contact.

I know three ways to detect contacts

gContactAddedCallback 

or

  int numManifolds = m_dynamicsWorld->getDispatcher()->getNumManifolds(); for (int i=0;i<numManifolds;i++) { btRigidBody* obA = static_cast<btRigidBody*>(contactManifold->getBody0()); btRigidBody* obB = static_cast<btRigidBody*>(contactManifold->getBody1()); // May be there is contact obA and obB btPersistentManifold* contactManifold = m_dynamicsWorld->getDispatcher()->getManifoldByIndexInternal(i); int numContacts = contactManifold->getNumContacts(); for (int j=0;j<numContacts;j++) { btManifoldPoint& pt = contactManifold->getContactPoint(j); if (pt.getDistance()<0.f) { // One contact point is inside of another object // But some contacts are ignored } } } 

or

Check ramp and angular. (It is unclear whether the contact was and which object changed speed, whether it was an object or damping, gravity, or some force field.


I want to have contact information to enable the momentum of contacts. I noticed that some kind of contact is allowed in 1 frame simulation, others take 2 frames, and the impulse is half as low. (I got the debugging code.) I would be ideal to get 1 contact message with a full boost.

None of the methods I have listed give me complete contact information. For some time he shoots when the ball flies near the target and does not even touch it.

What is the expected way to do this?

Such information could be used to play a percussive sound or start an animation if the contact energy is high.

+7
source share
1 answer

This code should indicate a possible direction.

 // some global constants needed enum collisiontypes { NOTHING = 0, // things that don't collide BALL_BODY = 1<<2, // is ball TARGET_BODY = 1<<3 // is target }; int ballBodyCollidesWith = TARGET_BODY | BALL_BODY; // balls collide with targets and other balls int targetBodyCollidesWith = BALL_BODY; // targets collide with balls // ... // bodies creation dynamicsWorld->addRigidBody(ballBody, BALL_BODY, ballBodyCollidesWith); dynamicsWorld->addRigidBody(targetBody, TARGET_BODY, targetBodyCollidesWith); //... // find out whether a ball collides with a target int numManifolds = m_dynamicsWorld->getDispatcher()->getNumManifolds(); for (int i=0;i<numManifolds;i++) { btRigidBody* obA = static_cast<btRigidBody*>(contactManifold->getBody0()); btRigidBody* obB = static_cast<btRigidBody*>(contactManifold->getBody1()); // May be there is contact obA and obB // ignore bodies that are not balls or targets if ( (!(obA->getCollisionFlags() | BALL_TYPE) && !(obB->getCollisionFlags() | BALL_TYPE)) // there is no BALL_TYPE colliding || (!(obA->getCollisionFlags() | TARGET_TYPE) && !(obB->getCollisionFlags() | TARGET_TYPE)) // there is no TARGET_TYPE colliding ) continue; // no more searching needed btPersistentManifold* contactManifold = m_dynamicsWorld->getDispatcher()->getManifoldByIndexInternal(i); int numContacts = contactManifold->getNumContacts(); for (int j=0;j<numContacts;j++) { btManifoldPoint& pt = contactManifold->getContactPoint(j); printf("%f\n", pt.getAppliedImpulse()); // log to see the variation range of getAppliedImpulse and to chose the appropriate impulseThreshold if (pt.getAppliedImpulse() > impulseThreshold) { // increase score or something break; // no more searching needed } } } 
+3
source

All Articles