Hi all,
I have set up an off-screen rendering of an environment and I project that environment using 12 cameras (associated with 12 off-screen buffers to get a panoramic effect) onto a round shape in the base window.
I have set up a movement task which allows me to move the cluster of 12 cameras around the environment.
I have then set up the pusher collision handler along with a traverser to create the ‘push’ effect against the walls of the environment as well as against geometrical objects. I have also changed the environment egg file adding the appropriate tags. The thing doing the collisions should be the camera cluster.
I have 3 problems:
I cannot seem to make a collision sphere around the camera cluster I have created and am forced to make a collision sphere around a ‘smiley’ and reparent the cluster to the smiley…
I have set
self.cTrav.showCollisions()
but I do not see any collisions even though they do happen. I cannot even see the collision spheres around the geometrical objects in the environment (even though if I load an object into the environment like a teapot I can see the sphere)…
Lastly, the push effect that I do get stutters and is not smooth whenever a collision happens.
Would anyone have any ideas what could be going wrong?
Below are snipets from the code in case it helps.
Thank you for any help!!
Pawel
This is how I make the 12 off-screen buffers with 12 cameras creating a panoramic view:
self.myscene = NodePath("My Scene")
self.environment=loader.loadModel("models/env2")
self.environment.reparentTo(self.myscene)
self.lens2=PerspectiveLens()
self.lensfovx=30
self.lensfovy=70
self.mybuffer=[]
self.mycamera=[]
self.mytexture=[]
for i in range(0,12):
self.mybuffer.append(base.win.makeTextureBuffer("My Buffer " + str(i), 1024, 1024))
self.mytexture.append(self.mybuffer[i].getTexture())
self.mybuffer[i].setSort(-100)
self.mycamera.append(base.makeCamera(self.mybuffer[i],lens=self.lens2))
self.mycamera[i].node().setScene(self.myscene)
if i>0:
self.mycamera[i].reparentTo(self.mycamera[0])
self.mycamera[i].setHpr(i*self.lensfovx, 0, 0)
self.mycamera[i].setPos(0,0,0)
I make a round shape using 12 slices and set the Texture of each slice from each of the 12 buffers:
self.screen=[]
for i in range(0,12):
self.screen.append(loader.loadModel("models/slice12"))
self.screen[i].reparentTo(self.render)
self.screen[i].setScale(3, 3, 3)
self.screen[i].setPos(0, 20, 0)
self.screen[i].setHpr(-30*i, 0, 0)
self.screen[i].setTexture(self.mytexture[i])
I load the smiley, set up a collision sphere around the smiley and reparent mycamera[0] (to which all other cameras are reparented to) to the smiley. The smiley is the reparented to back to myscene which is the node that the environment is reparented to - I have to do this because when I try to create a collision sphere around mycamera[0] it does not work…:
self.smiley = loader.loadModel("models/smiley")
self.smiley.reparentTo(self.myscene)
self.mycamera[0].reparentTo(self.smiley)
self.smiley.setPos(0,0,0)
self.smileyPath = self.smiley.attachNewNode(CollisionNode('cnode_smiley'))
self.smileyPath.node().addSolid(CollisionSphere(0,0,-1,2))
self.smileyPath.node().setIntoCollideMask(BitMask32.allOff())
self.smileyPath.node().setFromCollideMask(BitMask32.bit(0))
I set up a Pusher Collision Handler, and a traverser, and then set up a couple of tasks to initiate the traverser:
self.pusher = CollisionHandlerPusher()
self.cTrav = CollisionTraverser()
self.pusher.addCollider(self.smileyPath, self.smiley)
self.cTrav.addCollider(self.smileyPath, self.pusher)
self.cTrav.showCollisions(self.myscene)
self.start()
def start(self):
taskMgr.add( self.pusherTask, 'pusherTask')
taskMgr.add( self.moveTask, 'moveTask')
def pusherTask(self, task):
self.cTrav.traverse(self.myscene)
return task.cont
def moveTask(self, task):
dt = globalClock.getDt()
for key, action in MOVEFUNCTIONS.items():
if keyPoller[ key ]:
self.smiley.setPos( self.smiley, action*dt)
for key, action in ROTATEFUNCTIONS.items():
if keyPoller[ key ]:
self.smiley.setHpr( self.smiley, action*dt )
return task.cont
The movement task that is also initiated above first receives:
POLLKEYS = list(string.ascii_lowercase+string.digits)
POLLKEYS.extend(
[ 'arrow_up', 'arrow_down', 'arrow_left', 'arrow_right' ] )
MOVEFUNCTIONS = { 'arrow_up' : Vec3(0,-10,0),
'arrow_down' : Vec3(0, 10,0) }
ROTATEFUNCTIONS = { 'arrow_left' : Vec3( 90,0,0),
'arrow_right': Vec3(-90,0,0) }
class KeyPollerClass( DirectObject ):
def __init__( self ):
self.data = dict()
for key in POLLKEYS:
self.accept( key, self.event, [key, True] )
self.accept( key+"-up", self.event, [key, False] )
self.data[ key ] = False
def event( self, key, active ):
self.data[key] = active
def __getitem__( self, key ):
return self.data[key]
keyPoller = KeyPollerClass()
[/code]