def createViewer (self): """create a osgViewer.Viewer and set the viewport, camera and previously created graphical context """ viewer = osgViewer.Viewer() viewer.getCamera().setViewport(osg.Viewport(0,0, self.width(), self.height())) viewer.getCamera().setProjectionMatrixAsPerspective(30.0,float(self.width())/float(self.height()), 1.0, 10000.0) if not self.gw: raise Exception("GraphicsWindow not yet created") viewer.getCamera().setGraphicsContext(self.gw) return viewer
def resetCamera(self, viewer): camera = viewer.getCamera() camera.setComputeNearFarMode(False) # camera = osg.Camera() camera.setViewport(osg.Viewport(0, 0, self.width(), self.height())) # camera.setReferenceFrame(osg.Transform.ABSOLUTE_RF) CAMERA_ANGLE = 45.0 CAMERA_Z_TRANSLATE = 2.4142135623730949 #1.0 / math.tan(math.radians(CAMERA_ANGLE / 2.0)) cameraPosition = [0.0, 0.0, CAMERA_Z_TRANSLATE] camera.setProjectionMatrixAsPerspective( CAMERA_ANGLE, float(self.width()) / float(self.height()), 0.1, 100.0) eye = osg.Vec3d(cameraPosition[0], cameraPosition[1], cameraPosition[2]) center = osg.Vec3d(0, 0, 0) up = osg.Vec3d(0, 1, 0) camera.setViewMatrixAsLookAt(eye, center, up) camera.getOrCreateStateSet().setAttributeAndModes( osg.BlendFunc(GL.GL_ONE, GL.GL_ONE_MINUS_SRC_ALPHA)) camera.getOrCreateStateSet().setMode(GL.GL_DEPTH_TEST, False) camera.getOrCreateStateSet().setMode(GL.GL_DEPTH_WRITEMASK, False) camera.getOrCreateStateSet().setMode(GL.GL_LIGHTING, False) material = osg.Material() color = osg.Vec4(1.0, 1.0, 1.0, 1.0) material.setDiffuse(osg.Material.FRONT_AND_BACK, color) material.setAmbient(osg.Material.FRONT_AND_BACK, color) camera.getOrCreateStateSet().setAttributeAndModes(material) camera.setClearColor(osg.Vec4(0, 0, 0, 0)) camera.setClearMask(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT) camera.setCullMask(VISIBLE_CULL_MASK) if not self.gw: raise Exception("GraphicsWindow not yet created") self.camera = camera # viewer.getCamera().setViewport(osg.Viewport(0,0, self.width(), self.height())) # viewer.getCamera().addChild(camera) camera.setGraphicsContext(self.gw)
def camera_build(self): texture = self.texture_build() camera = osg.Camera() camera.setViewport(osg.Viewport(0, 0, self.width(), self.height())) camera.setReferenceFrame(osg.Transform.ABSOLUTE_RF) camera.setRenderOrder(osg.Camera.PRE_RENDER) camera.setRenderTargetImplementation(osg.Camera.FRAME_BUFFER_OBJECT) camera.attach(osg.Camera.COLOR_BUFFER, texture, 0, 0, False, 0, 0) CAMERA_ANGLE = 45.0 CAMERA_Z_TRANSLATE = 2.4142135623730949 #1.0 / math.tan(math.radians(CAMERA_ANGLE / 2.0)) cameraPosition = [0.0, 0.0, CAMERA_Z_TRANSLATE] camera.setProjectionMatrixAsPerspective( CAMERA_ANGLE, float(self.width()) / float(self.height()), 0.1, 10000.0) eye = osg.Vec3d(cameraPosition[0], cameraPosition[1], cameraPosition[2]) center = osg.Vec3d(0, 0, 0) up = osg.Vec3d(0, 1, 0) camera.setViewMatrixAsLookAt(eye, center, up) camera.getOrCreateStateSet().setAttributeAndModes( osg.BlendFunc(GL.GL_ONE, GL.GL_ONE_MINUS_SRC_ALPHA)) camera.getOrCreateStateSet().setMode(GL.GL_DEPTH_TEST, False) camera.getOrCreateStateSet().setMode(GL.GL_DEPTH_WRITEMASK, False) camera.getOrCreateStateSet().setMode(GL.GL_LIGHTING, False) material = osg.Material() color = osg.Vec4(1.0, 1.0, 1.0, 1.0) material.setDiffuse(osg.Material.FRONT_AND_BACK, color) material.setAmbient(osg.Material.FRONT_AND_BACK, color) camera.getOrCreateStateSet().setAttributeAndModes(material) camera.setClearColor(osg.Vec4(0, 0, 0, 0)) camera.setClearMask(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT) return camera, texture
def setup_osgwindow(self, x, y, width, height): """ pythonic alternative to setUpViewerAsEmbeddedInWindow """ self.traits = osg.GraphicsContext.Traits() self.traits.x = x self.traits.y = y self.traits.width = width self.traits.height = height #stereo is possible: # self.traits.quadBufferStereo = True # self.traits.screenNum = 1 gw = osgViewer.GraphicsWindowEmbedded(self.traits) self.viewer.getCamera().setViewport(osg.Viewport(0, 0, width, height)) self.viewer.getCamera().setProjectionMatrixAsPerspective( 30.0, float(width) / float(height), 1.0, 10000.0) self.viewer.getCamera().setGraphicsContext(gw) return gw