help with bullet collision callback

nickak2003

11-06-2013 02:48:07

I've read about bullet contact callbacks, and want to try implementing one. Does anyone have some sample or started code?

dermont

11-06-2013 09:36:35

The bullet collision callback is limited in python-ogre. The gContactAddedCallback etc. needs to be implemented via some specific wrapper code.

Only the callback classes are implemented, e.g. ContactResultCallback for bullet>=2.76.


class OgreBtContactResultCallback(bullet.btCollisionWorld.ContactResultCallback):
def __init__(self, sceneManager):
bullet.btCollisionWorld.ContactResultCallback.__init__(self)

self.mLines = ogre.ManualObject("ContactResult")
sceneManager.getRootSceneNode().attachObject( self.mLines )
self.mLines.setDynamic(True)

self.sceneManager = sceneManager

def __del__(self):
self.sceneManager.getRootSceneNode().detachObject( self.mLines )
del self.mLines

def addSingleResult(self, cp, colObj0,partId0, index0, colObj1, partId1,index1):

self.sceneManager.getRootSceneNode().detachObject( self.mLines )
self.mLines.clear()
self.mLines.begin("BaseWhiteNoLighting", ogre.RenderOperation.OT_LINE_LIST )
c = ogre.ColourValue( 1.0,0.0,1.0 )
c.saturate()
self.mLines.position( cp.getPositionWorldOnA().x(),cp.getPositionWorldOnA().y(),cp.getPositionWorldOnA().z())
self.mLines.colour( c )
self.mLines.position( cp.getPositionWorldOnB().x(),cp.getPositionWorldOnB().y(),cp.getPositionWorldOnB().z() )
self.mLines.colour( c )
self.mLines.end()
self.sceneManager.getRootSceneNode().attachObject( self.mLines )

return 0.0 ## returns float required

....

self.contactResultCallback = OgreBtContactResultCallback(cam.getSceneManager())

....

self.dynamicsWorld.contactTest(self.rigidBody, self.contactResultCallback)