How to remove and restore a display region

I split the screen by creating another display region:

        
        dr1 = cam.node().getDisplayRegion(0)
        dr2 = base.win.makeDisplayRegion(0.1, 0.4, 0.2, 0.6)
        dr.setDimensions(0, 0.5, 0, 1)
        dr2.setDimensions(0.5, 1, 0, 1)

        # then restore it later
        base.win.removeDisplayRegion(dr2)
        dr1.setDimensions(0, 1, 0, 1)

The restoration code seems not working very well. The window after restoration has a wrong aspect ratio, it becomes double wide. What is the proper way to do a restoring here ?

That should do it (except for the strange reference to “dr” instead of “dr1” in the second line). There must be something else changing your aspect ratio. This is a property of base.camLens, and is normally adjusted automatically by Panda when your window is resized by the user.

David

Here is the sample code:

'''
by:unknown
revised-by: Fabius Astelix @ 2009-02
summary: Here how to have remote cameras in a scene: a camera is shooting a scene that is renderer in rectangular regions in the main scene.
'''
from pandac.PandaModules import Camera, DirectionalLight
from pandac.PandaModules import NodePath,TextNode
from pandac.PandaModules import Point3,Vec3,Vec4
from direct.actor.Actor import Actor
from direct.showbase.DirectObject import DirectObject
import direct.directbase.DirectStart

class World(DirectObject):
  def __init__(self):
    base.disableMouse()
    self.displayRegion1()
    self.accept("escape", self.restore)
    self.accept("s", self.split)

  def split(self):
    self.splitScreen(base.cam, self.displayRegion2())

  def displayRegion1(self):
    base.camera.setPos(0, -10, 5)
    self.actor= Actor('panda.egg', {'walk' : 'panda-walk.egg'})
    self.actor.setScale(0.25,0.25,0.25)
    self.actor.reparentTo(render)
    self.actor.loop("walk")
    base.camera.lookAt(self.actor.getPos())

    dlight = NodePath(DirectionalLight('dlight'))
    dlight.reparentTo(base.cam)
    render.setLight(dlight)
    return base.cam

  def displayRegion2(self):
    dr2 = base.win.makeDisplayRegion(0.1, 0.4, 0.2, 0.6)

    render2 = NodePath('render2')
    self.render2 = render2
    cam2 = render2.attachNewNode(Camera('cam2'))
    dr2.setCamera(cam2)

    env = loader.loadModel('environment.egg')
    env.reparentTo(render2)

    cam2.setPos(-22.5, -387.3, 58.1999)
    return cam2

  def splitScreen(self, cam, cam2):
    dr = cam.node().getDisplayRegion(0)
    self.dr1 = dr
    dr2 = cam2.node().getDisplayRegion(0)
    self.dr2 = dr2

    dr.setDimensions(0, 0.5, 0, 1)
    dr2.setDimensions(0.5, 1, 0, 1)

    cam.node().getLens().setAspectRatio(float(dr.getPixelWidth()) / float(dr.getPixelHeight()))
    cam2.node().getLens().setAspectRatio(float(dr2.getPixelWidth()) / float(dr2.getPixelHeight()))

  def restore(self):
      # then restore it later
      self.render2.removeNode()
      base.win.removeDisplayRegion(self.dr2)

      self.dr1.setDimensions(0, 1, 0, 1)


pea=World()
run()

Run the program, the panda looks fine.
Press ‘s’, the screen split. The panda still looks fine.
Press ‘escape’. Now the panda becomes a fat one.

Where is the problem ?
[/code]

It’s this line here:

    cam.node().getLens().setAspectRatio(float(dr.getPixelWidth()) / float(dr.getPixelHeight())) 

You’re fiddling with the aspect ratio of the camera to compensate for the new, skinny DisplayRegion. When you make the DisplayRegion wide again, you’ll have to fiddle it back.

David

Oops…

I am really stupid and blind. Thank you for pointing this silly mistake.