Collision Response: object, poi... voi?

Post Reply
stevenLD
Posts: 10
Joined: Fri Sep 14, 2007 1:27 am

Collision Response: object, poi... voi?

Post by stevenLD »

I'm not quite sure how many hours is enough to spend searching the forums, CHM, and source, so if I just need to go back and search some more, let me know. Otherwise, my question:

When two objects collide, it creates overlapPairs and that goodness, but I was wondering where, if anywhere, I can get the velocity of impact. I was hoping to do effects (damage, graphical, etc) based on the velocity of impact between two rigidBody objects (say, a sparrow and a tank). Any info you can provide would be splendid. :)

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

Re: Collision Response: object, poi... voi?

Post by Erwin Coumans »

stevenLD wrote:
When two objects collide, it creates overlapPairs and that goodness, but I was wondering where, if anywhere, I can get the velocity of impact. I was hoping to do effects (damage, graphical, etc) based on the velocity of impact between two rigidBody objects (say, a sparrow and a tank). Any info you can provide would be splendid. :)

Thanks.
You will need to iterate over the contact points, and search for a member called m_appliedImpulse. This gives an indication about the magniture of the impact.

See bullet\Demos\CollisionInterfaceDemo\CollisionInterfaceDemo.cpp how to iteratve over manifolds/contact points.

There is an issue when you have multiple substeps, you would loose some impacts (they get overwritten). I will provide a callback to avoid this problem soon.

Hope this helps,
Erwin
Proctoid
Posts: 18
Joined: Fri Apr 21, 2006 3:04 pm
Location: uk

Re: Collision Response: object, poi... voi?

Post by Proctoid »

i play with bullet just for fun, but if accuracy of velocity or speed etc is not so important you could do something simple like i do...

during your enviroment creation, set the callback for when manifold points are added:
gContactAddedCallback = new_persistent_manifold_collision_point_added;

here is the one i use to simply set some flags for the colliding objects when manifold points are added:

bool new_persistent_manifold_collision_point_added( btManifoldPoint& cp, const btCollisionObject* colObj0, int partId0, int index0, const btCollisionObject* colObj1, int partId1, int index1 )
{
IPhysics *pobj0 = static_cast<IPhysics*>( colObj0->getUserPointer() );
IPhysics *pobj1 = static_cast<IPhysics*>( colObj1->getUserPointer() );
//
pobj0->m_do_collision_sound = true;
pobj1->m_do_collision_sound = true;
//
if ( pobj0->GetRigidBody()->getInvMass() != 0 )
{
pobj1->m_collided_with_something_non_terrain = true;
}
//
if ( pobj1->GetRigidBody()->getInvMass() != 0 )
{
pobj0->m_collided_with_something_non_terrain = true;
}

return false; // return value unused so far (bullet v2.15)
}

then in your main app loop:
for every object in your game, copy the current linear velocity and whatever else you may need and clear previous flags
call physics step simulation
then for every object in your game examine the flags the step simulation would have set upon collisions and do whatever.
AlexSilverman
Posts: 141
Joined: Mon Jul 02, 2007 5:12 pm

Re: Collision Response: object, poi... voi?

Post by AlexSilverman »

I am doing what Proctoid explained, and it works perfectly. One question about that method though. Does he need to copy the velocities before the simulation step. Can he just look at them inside the callback, or have the velocities been changed due to the contact at that point?

-Alex
Proctoid
Posts: 18
Joined: Fri Apr 21, 2006 3:04 pm
Location: uk

Re: Collision Response: object, poi... voi?

Post by Proctoid »

i dunno if the velocities would have changed before the callback is called - not something i've needed to investigate yet...
i just save variables before calling step simulation and compare them after because i don't want to fill callbacks with lots of extra code!
Post Reply