Undo camera motion, rotation

Hi everyone,

I have a setup that works like this: there are 2 states in an FSM, one has multiple display regions, the other does not. I load an actor to one state and move the camera around, and then I move onto the next state. When I move from one state to another, I need any and all camera motions and rotations undone, so that the camera is the exact way it was before I moved it around.

The code:

class Holo_FSM(FSM,ShowBase):
    
   def __init__(self):
        ShowBase.__init__(self)
        FSM.__init__(self, 'Holo_FSM')    
        
   def enterMe(self):
       #just normal viewing:
       base.cam.setPos(0,0,0)
       base.cam.setHpr(0,0,0)
       base.camera.setPos(0,0,0)
       base.camera.setHpr(0,0,0)          
       self.model=Actor('panda')
       self.model.reparentTo(render)
       self.join_pieces= DirectButton(text = ("You", "click!", "rolling over", "disabled"),pos=(0,0,0.4),scale=.05,command=self.changer,extraArgs=[0])#
       self.model.setPos(0,100,0)


   def exitMe(self):
       self.model.removeNode()
       self.join_pieces.destroy()


   def enterYou(self):
       #here, create display regions:
        base.cam.setPos(0,0,0)
        base.cam.setHpr(0,0,0)
        base.camera.setPos(0,0,0)
        base.camera.setHpr(0,0,0)       
        self.close= DirectButton(text = ("Me", "click!", "rolling over", "disabled"),pos=(0,0,0.3),scale=.05,command=self.changer,extraArgs=[1])#
        base.cam.node().getDisplayRegion(0).setActive(0)
        self.dp_1=base.win.makeDisplayRegion(0, 0.3, 0, 1)#screen_one
        self.dp_2=base.win.makeDisplayRegion(0.3,1,0,1)#screen_two
        self.camNode = Camera('cam')
        self.camNP = NodePath(self.camNode)
        self.c2node= Camera('cam2')
        self.c2np=NodePath(self.c2node)
        self.dp_1.setCamera(self.camNP)
        self.dp_2.setCamera(self.c2np)
        self.dp_1.setClearColor(Vec4(0.3, 0.5,0.4, 1))
        self.dp_1.setClearColorActive(True)
        self.dp_2.setClearColor(Vec4(0.3, 0.4,0.4, 1))
        self.dp_2.setClearColorActive(True)
        aspect = float(self.dp_1.getPixelWidth()) / float(self.dp_1.getPixelHeight())
        assp2=float(self.dp_2.getPixelWidth()) / float(self.dp_2.getPixelHeight())
        self.camNP.node().getLens().setAspectRatio(aspect)
        self.c2np.node().getLens().setAspectRatio(assp2)
        self.c2np.reparentTo(base.camera)
        self.render2 = NodePath('render2')
        self.camNP.reparentTo(self.render2)
        self.c2np.setPos(0,0,0)
        self.c2np.setHpr(0,0,0)
        #actor:
        self.model=Actor('panda')
        self.model.reparentTo(render)    
        self.model.setPos(0,100,0)


   def exitYou(self):
       #destroy display regions:
       self.close.destroy()     
       base.win.removeDisplayRegion(self.dp_1)
       base.win.removeDisplayRegion(self.dp_2)
       self.camNP.removeNode()
       self.c2np.removeNode()
       #restore display region:
       base.cam.node().getDisplayRegion(0).setActive(1)
       self.model.removeNode()  


   def changer(self,mode):
       if(mode==0):
           ramp.request('You')
       else:
           ramp.request('Me')


ramp=Holo_FSM()
ramp.request('Me')
ramp.run()

The above does not reset the camera; I’ve tried calling this at the beginning of each state:

       base.cam.setPos(0,0,0)
       base.cam.setHpr(0,0,0)
       base.camera.setPos(0,0,0)
       base.camera.setHpr(0,0,0)   

#affecting the parent could have just affected the child

And on creating the display region with the camera parented to base.camera, I ‘reset’ it too:

        self.c2np.setPos(0,0,0)
        self.c2np.setHpr(0,0,0)

I know it’s a simple question, but how would I go about resetting the camera to default with each state-transition?

Thanks.

I also tried this:

       base.cam.clearTransform()
       base.camera.clearTransform()   

and this:

       base.cam.clearMat()
       base.camera.clearMat()

But the camera still had whatever changes done to it after the mouse was moved in one state. Am I missing something?

You didn’t call base.disableMouse(), so Panda has control over the camera. If you want to reset the default camera controller, use base.trackball.node().setMat(Mat4.identMat()) or something.

Well, I still do need panda to have control over the camera, I just wanted to reset the camera with each state transition. Thanks so much rdb! This totally worked:

                     base.trackball.node().setMat(Mat4.identMat())

I probably would have never even thought about doing that. I really appreciate your help! I wish there were a better way to show my gratitude than just mere words though… :frowning: