moving /setting camera pos at start. [SOLVED]

I am having trouble setting the position of my camera either before render or after. It just stays at the origin. The following code I wrote so I can rotate the camera around and press ‘c’ to get its coordinates. I have tried to use those coordinates to set the camera to no avail.

FYI: Panda3d noob and Python noob.

Does the world rotate with a fixed camera, or does the camera actually rotate?

import direct.directbase.DirectStart
from direct.gui.OnscreenText import OnscreenText
from direct.showbase.DirectObject import DirectObject
class World(DirectObject):
    def __init__(self):
        self.environ = loader.loadModel("streetscene/street-scene")
        self.SetupCam()
        self.environ.reparentTo(render)
        self.environ.setScale(0.25,0.25,0.25)
#        self.environ.setPos(22,-6,14)
        self.accept('c',self.ShowCamPos)
        self.accept('c-up',self.HideCamPos)
        
        
        
    def SetupCam(self):
        base.camera.setX(22)
        base.camera.setY(-6)
        base.camera.setZ(14)
        
    def ShowCamPos(self):
#        position = environ.getPos()
        x=base.camera.getX()
        y=base.camera.getY()
        z=base.camera.getZ()
        self.title = OnscreenText(text = str(x)+":"+str(y)+":"+str(z),style=1,fg=(1,1,0,1),pos=(0,0), scale = 0.07)
    def HideCamPos(self):
        self.title.destroy()
    
w = World()
run()

Panda3D has by default a system for camera movement active. Either mouse drive or trackball. The camera will be reset to it’s original position each frame if this default camera movement system is not disabled. To disable:

base.disableMouse( )

No worries, almost every newbie (including me) as asked this question so far.

enn0x

yes… I found that nugget of info in the post about First person shooter someone was making.

Also found out I need to set the camera H and P. Which stands for heading and pitch?

here is the fixed code for prosperity:

import direct.directbase.DirectStart
from direct.gui.OnscreenText import OnscreenText
from direct.showbase.DirectObject import DirectObject
class World(DirectObject):
    def __init__(self):
        self.environ = loader.loadModel("streetscene/street-scene")
        
        self.environ.reparentTo(render)
        self.environ.setScale(0.25,0.25,0.25)
#        self.environ.setPos(22,-6,14)
        self.accept('c',self.ShowCamPos)
        self.accept('c-up',self.HideCamPos)
        base.disableMouse()
        self.SetupCam()
        
        
        
    def SetupCam(self):
        base.camera.setX(4.55)
        base.camera.setY(-0.33)
        base.camera.setZ(2.10)
        base.camera.setH(85.91)
        base.camera.setP(-7.42)
        
    def ShowCamPos(self):
#        position = environ.getPos()
        x=base.camera.getX()
        y=base.camera.getY()
        z=base.camera.getZ()
        h=base.camera.getH()
        p=base.camera.getP()
        self.title = OnscreenText(text = str(x)+" : "+str(y)+" : "+str(z)+"\n"+str(h)+" : "+str(p),style=1,fg=(1,1,0,1),pos=(0,0), scale = 0.07)
    def HideCamPos(self):
        self.title.destroy()
    
w = World()
run()

Note that you can do the positioning/rotating in less calls, if you want:

base.camera.setPos(4.55,-0.33,2.10)
base.camera.setHpr(85.91,-7.42,0)

Or, even in one call, if you want:

base.camera.setPosHpr(4.55,-0.33,2.10,85.91,-7.42,0)