collision detection for the camera

hi,

I am very new at panda and I am having some problems with collision.
I am trying to create a game where the user will be able to move around with the mouse in a fairly large town. I want to do collision detection between the camera and the scene. I cannot use the default solids to do this because my scene is very complicate. For the moment I don´t care about performance.

import direct.directbase.DirectStart
from pandac.PandaModules import *
from direct.interval.IntervalGlobal import *

base.cTrav = CollisionTraverser()
pusher = CollisionHandlerPusher()


#load a model  (in normal case here will be the town)
town= loader.loadModel('models/teapot.egg')
town.reparentTo(render)
town.setPos(0,150,0.5)
town.setScale(10,10,10)

#use the camera as a from object to detect collisions with all the geometry of the scene
fromObject = base.camera.attachNewNode(CollisionNode('colNode'))
fromObject.node().addSolid(CollisionSphere(0, 0, 0, 1))
fromObject.node().setIntoCollideMask(BitMask32.allOff())
fromObject.node().setFromCollideMask(GeomNode.getDefaultCollideMask())


#add collision node to the traverser and the pusher
base.cTrav.addCollider(fromObject,pusher)
pusher.addCollider(fromObject, base.camera, base.drive.node())
base.cTrav.showCollisions(render)

run()

I can see that collisions are been made from base.cTrav.showCollisions(render) but the camera is still passing through the scene.

Am I doing something wrong here? Is there any other way to do this except ODE and OdeTriMeshGeom?

thanks

You never turned on drive mode, so your camera is still in trackball mode, which doesn’t respond to base.drive.node(). Did you mean to call:

base.useDrive()

?

David

thanks David. You were right. As I said before I am new at Panda and I am confused with the functionality of camera(trackball, mouse e.t.c).

I have another question now. The application is really slow so I must improve my collision detection. Before I will try tagging my models I want first to load my scene(the same scene but with much lower number of polygons) as a collision solid but I didn´t figure how.

the ideal case would be something like this:

...

smiley = loader.loadModel('myScene.egg')
smiley.reparentTo(render)

cNode = CollisionNode('scene')
cNode.addSolid(CollisionSolid('mySceneOptimized.egg'))
cNode.setIntoCollideMask(BitMask32.bit(1))
cNode.setFromCollideMask(BitMask32.allOff())
smileyC = smiley.attachNewNode(cNode)

any help would be much appreciated.
thanks

Edit the egg file to add the “barrier” tag. See the Panda3D manual for more about this.

David