detecting initial collision of objects

nickak2003

11-06-2013 10:27:36

Right now my collision detection code runs each frame and if two objects are colliding, I cant find a good way to only act on the initial collision. Are there initial collision callbacks? Are there object started moving callbacks?

dermont

11-06-2013 18:05:31

Right now my collision detection code runs each frame and if two objects are colliding, I cant find a good way to only act on the initial collision. Are there initial collision callbacks? Are there object started moving callbacks?
You would probably be better off asking bullet specific questions on the bullet form or check the bullet wiki.
http://www.bulletphysics.org/mediawiki- ... d_Triggers

This most definitely isn't the way to do this and is probably very slow but it shows how you can extend callbacks via python. I used something similar for RaySceneQueryListeners and Ogre.


class OgreBtContactResultCallback(bullet.btCollisionWorld.ContactResultCallback):
def __init__(self, _func, world):
bullet.btCollisionWorld.ContactResultCallback.__init__(self)
self._func = _func
self.dynamicsWorld = world
self.rigidBody = None

def update(self):
if self.rigidBody:
## will call addSingleResult if contact exists
self.dynamicsWorld.contactTest(self.rigidBody, self)

def addSingleResult(self, cp, colObj0,partId0, index0, colObj1, partId1,index1):
self._func(cp, colObj0,partId0, index0, colObj1, partId1,index1, self.rigidBody)
return 0.0 ## returns float required



class BulletListener( sf.FrameListener ):
def __init__(self, rw, cam, world,rb ):
sf.FrameListener.__init__(self, rw, cam)
self.dynamicsWorld = world
self.rigidBody = rb
## create our contact result callback
self.contactResultCallback = OgreBtContactResultCallback(self.ContactResultCallback, world)
self.contactResultCallback.rigidBody = rb

def ContactResultCallback(self, cp, colObj0,partId0, index0, colObj1, partId1,index1, rb):
print cp.getPositionWorldOnA().x(),cp.getPositionWorldOnA().y(),cp.getPositionWorldOnA().z()
print cp.getPositionWorldOnB().x(),cp.getPositionWorldOnB().y(),cp.getPositionWorldOnB().z()
self.contactResultCallback.rigidBody = None
rb.setCollisionFlags( bullet. btCollisionObject.CollisionFlags.CF_STATIC_OBJECT )

def frameStarted(self, frameEvent):
.....
self.contactResultCallback.update()
.....