Collisions with ODE


#1

Hi guys,

I recently started my first project with panda3d and already got to a point where i dont know how to solve my problem the best way.

I created an odespace where i let my objects collide. I also turned autocollide on, so that I dont have to deal with the collisions manually. The problem with that is, that i have some objects that should not autocollide but only send the collide-event, so I can deal with that manually. So how do I solve that the best way? Should I just create a new odespace where i let the objects collide but dont turn autocollide on? Or can i manually exclude some objects from the automatic collisions?

I am a bit lost there, so i would be happy about any advise.

Greetz

Blaz


#2

I think you are looking to implement what is called a “trigger” in coppertop’s ODE Middleware.

This middleware, which I highly recommend, does not use the autocollide feature; it uses OdeUtil.collide() and then manually iterates through the collisions and creates contact joints (for non-triggers) and issues callback functions for the others. It’s well documented, so you can look through it for instruction. (It’s the only complete Panda/ODE example I could find online)

Alternatively, you could use Panda’s collision detection in addition to ODE for just detecting and initiating the callbacks. Suppose you want some objects to be containers, so you can remember when something goes inside of them. You could initialize a CollisionHandlerEvent as:

        # Initialize the handler.
        base.cEvent = CollisionHandlerEvent()
        base.cEvent.addInPattern("%fn-into-%(container)it")
        base.cEvent.addOutPattern("%fn-outof-%(container)it")
        # initialize listeners
        base.accept('object-into-acontainer', self._enterContainer)
        base.accept('object-outof-acontainer', self._exitContainer)

Then, for each such container, define a collision box and tag it as a container.

        lcorner, ucorner =self.model.getTightBounds()
        self.fullBoxCN = CollisionNode('object')
        cGeom = CollisionBox(lcorner, ucorner)
        cGeom.setTangible(1)
        self.fullBoxNP = self.attachNewNode(self.fullBoxCN)
        self.fullBoxCN.addSolid(cGeom)
        self.fullBoxNP.setTag('container','acontainer')
        base.cTrav.addCollider(self.fullBoxNP, base.cEvent)

Hope this helps!

Dustin