Exemplo n.º 1
0
    def __init__(self, scene, size=(800, 600), zNear=0.1, zFar=1000.0, fov=40.0, shadowing=False, interactive=True,
                 showPosition=False, cameraMask=None):

        super(Viewer, self).__init__()

        self.__dict__.update(scene=scene, size=size, fov=fov, shadowing=shadowing,
                             zNear=zNear, zFar=zFar, interactive=interactive, showPosition=showPosition,
                             cameraMask=cameraMask)

        if cameraMask is not None:
            self.cam.node().setCameraMask(self.cameraMask)
        lens = self.cam.node().getLens()
        lens.setFov(self.fov)
        lens.setNear(self.zNear)
        lens.setFar(self.zFar)

        # Change window size
        wp = WindowProperties()
        wp.setSize(size[0], size[1])
        wp.setTitle("Viewer")
        wp.setCursorHidden(True)
        self.win.requestProperties(wp)

        self.disableMouse()

        self.time = 0
        self.centX = self.win.getProperties().getXSize() / 2
        self.centY = self.win.getProperties().getYSize() / 2

        # key controls
        self.forward = False
        self.backward = False
        self.fast = 1.0
        self.left = False
        self.right = False
        self.up = False
        self.down = False
        self.up = False
        self.down = False

        # sensitivity settings
        self.movSens = 2
        self.movSensFast = self.movSens * 5
        self.sensX = self.sensY = 0.2

        self.cam.setP(self.cam, 0)
        self.cam.setR(0)

        # reset mouse to start position:
        self.win.movePointer(0, int(self.centX), int(self.centY))

        # Reparent the scene to render.
        self.scene.scene.reparentTo(self.render)

        # Task
        self.globalClock = ClockObject.getGlobalClock()
        self.taskMgr.add(self.update, 'viewer-update')

        self._addDefaultLighting()
        self._setupEvents()
Exemplo n.º 2
0
    def __init__(self, scene, size=(800, 600), zNear=0.1, zFar=1000.0, fov=40.0, shadowing=False, showPosition=False,
                 cameraTransform=None, cameraMask=None):

        ShowBase.__init__(self)
        
        self.__dict__.update(scene=scene, size=size, fov=fov,
                             zNear=zNear, zFar=zFar, shadowing=shadowing, showPosition=showPosition,
                             cameraTransform=cameraTransform, cameraMask=cameraMask)

        # Find agent and reparent camera to it
        self.agent = self.scene.scene.find('**/agents/agent*/+BulletRigidBodyNode')
        self.camera.reparentTo(self.agent)
        if self.cameraTransform is not None:
            self.camera.setTransform(cameraTransform)

        if cameraMask is not None:
            self.cam.node().setCameraMask(self.cameraMask)
        lens = self.cam.node().getLens()
        lens.setFov(self.fov)
        lens.setNear(self.zNear)
        lens.setFar(self.zFar)

        # Change window size
        wp = WindowProperties()
        wp.setSize(size[0], size[1])
        wp.setTitle("Controller")
        wp.setCursorHidden(True)
        self.win.requestProperties(wp)

        self.disableMouse()

        self.time = 0
        self.centX = wp.getXSize() / 2
        self.centY = wp.getYSize() / 2
        self.win.movePointer(0, int(self.centX), int(self.centY))

        # key controls
        self.forward = False
        self.backward = False
        self.fast = 2.0
        self.left = False
        self.right = False

        # sensitivity settings
        self.movSens = 2
        self.movSensFast = self.movSens * 5
        self.sensX = self.sensY = 0.2

        # Reparent the scene to render.
        self.scene.scene.reparentTo(self.render)

        self.render.setAntialias(AntialiasAttrib.MAuto)

        # Task
        self.globalClock = ClockObject.getGlobalClock()
        self.taskMgr.add(self.update, 'controller-update')

        self._addDefaultLighting()
        self._setupEvents()