Help with DisplayRegion Cameras

I’ve been trying to use this code which I found on the forum:

[i]""" This function splits the main display region into two separate
left-and-right regions, which represent the left and right eye of
the camera. “”"

First, disable the default DisplayRegion, which covers the whole

screen.

dr = base.camNode.getDisplayRegion(0)
dr.setActive(0)

Now, make a new pair of side-by-side DisplayRegions.

window = dr.getWindow()
dr1 = window.makeDisplayRegion(0, 0.5, 0, 1)
dr1.setSort(dr.getSort())
dr2 = window.makeDisplayRegion(0.5, 1, 0, 1)
dr2.setSort(dr.getSort())

# Set these both up to use the same camera.
dr1.setCamera(base.cam)
dr2.setCamera(base.cam)

# And make them into left and right stereo pairs.

dr1.setStereoChannel(Lens.SCLeft)

dr2.setStereoChannel(Lens.SCRight)[/i]

…and trying to create two cameras using this (from the forum):

[i]def init(self):
self.camera1=self.createCamera((0.5,1.0,0,1))
self.camera1.reparentTo(self.model1)
self.camera1.lookAt(self.model1)
self.camera2=self.createCamera((0.5,1.0,0,1))
self.camera2.reparentTo(self.model2)
self.camera2.lookAt(self.model2)
base.camNode.setActive(False) #disable default cam

def createCamera(self,dispRegion):
camera=base.makeCamera(base.win,displayRegion=dispRegion)
camera.node().getLens().setAspectRatio(3.0/4.0)
camera.node().getLens().setFov(45) #optional.
camera.setPos(0,-8,3) #set its position.
return camera[/i]

However, nothing I try is working.
How can I create two different cameras to use with the first code?
Thanks.

The first script is for a stereo camera, which is not what you want.

What excactly from the second script is not working?

Sorry to have confused you.
Both scripts are working.
I was just trying to use the second script, to try to get two different cameras into the first script. The first script (which I want to use) uses the same camera in both displayRegions. I want to have a different camera for each.
Can you help me create seperate cameras for each window? Thanks

I have accomolished what I wanted. I got my help from this code I foun on the forums.

Code:

    def addBackground(self): 
        self.minicon.addText("_Add background") 
        #The background root and camera. 
        self.background = NodePath("Background") 
        self.setupBackgroundCamera() 

        #Load the skybox. 
        self.skybox = loader.loadModel("Skybox") 
        self.skybox.reparentTo(self.background) 
        if self.BGOFF: self.skybox.hide() 
        
        #Load the axis. 
        #self.axisCenter = loader.loadModel("AxisCenter") 
        #self.axisCenter.reparentTo(self.background) 
        #self.axisCenter.hide() 

    def setupBackgroundCamera(self): 
        self.bg_cam = Camera("BgCam") 
        self.bg_cam.setScene(self.background) 
        self.bg_camera = self.background.attachNewNode(self.bg_cam) 
        self.bg_camera.setName("BgCamera") 
        self.bg_camera.setP(-90) 
        
        self.bg_lens = PerspectiveLens() 
        self.bg_lens.setAspectRatio(base.getAspectRatio()) 
        self.bg_lens.setFov(self.BGFOV) 
        self.bg_cam.setLens(self.bg_lens) 
        
        self.bg_dr = base.win.makeDisplayRegion(0, 1, 0, 1) 
        self.bg_dr.setSort(-1000) 
        self.bg_dr.setClearDepthActive(1) 
        self.bg_dr.setCamera(self.bg_camera)

I almost forgot.
I wanted to ask…
After the camera has been set (setCamera), how do I remove it, or disable it?

You can setCamera(NodePath()) to remove the camera. This will stop the DisplayRegion from rendering at all. You can also just disable the DisplayRegion via dr.setActive(0), which amounts to the same thing.

David

Thanks David.