###Edit
This was suppose to be a reply under the requests topic. But i nooobed out on it
Hi. As this is my first post And I’m not a very well versed panda user I don’t know that this request is strictly necessary. However here we go.
I have been working with panda to render two images of the same scene. I tried to use the camera that is created in showBase for one of the display regions. However I was not able to change the aspect ratio of this display region as this is controlled in the windowEvent function and it takes it’s aspect ratio From the whole window and not aspect ratio of window multiplied with aspect ratio of display region. In the end I ended up not using the camera. That is It’s still there but it has no geometry to render. witch I don’t like much but maby I’m just being pedantic.
But to my request: I’d like for the diplayregion object to have a getaspectratio function or a getX and getY length function. Also for the getAspectRatio function in showBase to return the aspect ratio of the window and the aspectratio of eider the display region asosiated with a camera sent in with the function or the base.cam camera. I culd probably make this my self. However I feel it wouldn’t be much point unless others can get to use it to and have the code be independent upon what panda version is in use.
Here is a sample of the code I have made. The video function is not run as you wold have to have that file in the same directory as you are running this code:
from direct.directbase.DirectStart import *
from pandac.PandaModules import *
from direct.showbase.DirectObject import DirectObject
from camOb import *
import sys
class InspectorGadget(DirectObject):
def __init__(self):
taskMgr.add(self.movement,"moveTask")
self.eventSetup()
self.camP1 = camOb(0.005, 0.3, 0.505, 0.995)
self.camP2 = camOb(0.005, 0.3, 0.005, 0.495)
#self.setupMovie()
self.setupEnv()
self.cam1 = self.makeNewDrAndCam('cam1')
self.cam2 = self.makeNewDrAndCam('cam2')
self.splitScreen()
def windowAspectEventHandler(self):
"""
This method is evocked by the eventhnadler when the size of the window changes.
It curently makes sertain that the relative dimensions of the model in
the two 3D renderings are corect and is the same when the aspect ratio changes.
"""
self.cam1.node().getLens().setAspectRatio(self.camP1.getAsp(base.win))
self.cam2.node().getLens().setAspectRatio(self.camP2.getAsp(base.win))
def eventSetup(self):
self.keyMap = {"left":0, "right":0, "forward":0, "cam-left":0, "cam-right":0}
self.accept('aspectRatioChanged', self.windowAspectEventHandler)
self.accept("escape", sys.exit)
self.accept("arrow_left", self.setKey, ["left",1])
self.accept("arrow_right", self.setKey, ["right",1])
self.accept("arrow_up", self.setKey, ["forward",1])
self.accept("a", self.setKey, ["cam-left",1])
self.accept("s", self.setKey, ["cam-right",1])
self.accept("arrow_left-up", self.setKey, ["left",0])
self.accept("arrow_right-up", self.setKey, ["right",0])
self.accept("arrow_up-up", self.setKey, ["forward",0])
self.accept("a-up", self.setKey, ["cam-left",0])
self.accept("s-up", self.setKey, ["cam-right",0])
def setupEnv(self):
"""
This function initialises the environment and the 3D modeles.
"""
self.render2 = NodePath('render2')
self.env = loader.loadModel("models/teapot.egg")
self.env.reparentTo(self.render2)
ambientLight = AmbientLight("ambientLight")
ambientLight.setColor(Vec4(.3, .3, .3, 1))
directionalLight = DirectionalLight("directionalLight")
directionalLight.setDirection(Vec3(-5, -5, -5))
directionalLight.setColor(Vec4(1, 1, 1, 1))
directionalLight.setSpecularColor(Vec4(1, 1, 1, 1))
self.render2.setLight(self.render2.attachNewNode(ambientLight))
self.render2.setLight(self.render2.attachNewNode(directionalLight))
def setupMovie(self):
"""
This function setsup the video and starts palying it.
"""
tex = MovieTexture("name")
assert tex.read("PandaSneezesMjpeg.avi"), "Failed to load video!"
base.disableMouse()
cm = CardMaker("Panda sneese card");
cm.setFrame(-0.39, 0.99, -0.2, 0.99)
cm.setUvRange(tex)
card = NodePath(cm.generate())
card.reparentTo(render2d)
card.setTexture(tex)
card.setTexScale(TextureStage.getDefault(), tex.getTexScale())
tex.play()
def makeNewDrAndCam(self, camName):
dr = base.win.makeDisplayRegion()
dr.setClearColor(VBase4(0, 0, 0, 1))
dr.setClearColorActive(True)
dr.setClearDepthActive(True)
cam1 = self.render2.attachNewNode(Camera(camName))
dr.setCamera(cam1)
cam1.setPos(0, -20, 1)
return cam1
def splitScreen(self):
dr1 = self.cam1.node().getDisplayRegion(0)
dr2 = self.cam2.node().getDisplayRegion(0)
dr1.setDimensions(self.camP1.x1, self.camP1.x2, self.camP1.y1, self.camP1.y2)
dr2.setDimensions(self.camP2.x1, self.camP2.x2, self.camP2.y1, self.camP2.y2)
self.cam1.node().getLens().setAspectRatio(self.camP1.getAsp(base.win))
self.cam2.node().getLens().setAspectRatio(self.camP2.getAsp(base.win))
def setKey(self, key, value):
self.keyMap[key] = value
def movement(self, task):
if (self.keyMap["cam-left"]!=0):
self.cam1.setX(self.cam1, -20 * globalClock.getDt())
if (self.keyMap["cam-right"]!=0):
self.cam1.setX(self.cam1, +20 * globalClock.getDt())
if (self.keyMap["left"]!=0):
self.env.setH(self.env.getH() + 300 * globalClock.getDt())
if (self.keyMap["right"]!=0):
self.env.setH(self.env.getH() - 300 * globalClock.getDt())
if (self.keyMap["forward"]!=0):
self.env.setY(self.env, -25 * globalClock.getDt())
return task.cont
m = InspectorGadget()
run()