Exemplo n.º 1
0
class InputMapperTecladoMouse(InputMapper):

    # teclas accion defecto
    TeclasAccionDefecto = {
        KeyboardButton.enter(): InputMapper.AccionArrojar,
        KeyboardButton.space(): InputMapper.AccionAscender,
        KeyboardButton.tab(): InputMapper.AccionUsar,
        KeyboardButton.control(): InputMapper.AccionAgachar,
        KeyboardButton.alt(): InputMapper.AccionAgarrar,
        KeyboardButton.asciiKey(b"c"): InputMapper.AccionFlotar,
        KeyboardButton.asciiKey(b"x"): InputMapper.AccionSoltar,
        KeyboardButton.asciiKey(b"z"): InputMapper.AccionFrenar,
        KeyboardButton.asciiKey(b"w"): InputMapper.AccionAvanzar,
        KeyboardButton.asciiKey(b"a"): InputMapper.AccionAvanzar,
        KeyboardButton.asciiKey(b"s"): InputMapper.AccionAvanzar,
        KeyboardButton.asciiKey(b"d"): InputMapper.AccionAvanzar,
        KeyboardButton.asciiKey(b"r"): InputMapper.AccionAvanzar,
        KeyboardButton.asciiKey(b"f"): InputMapper.AccionAvanzar
    }

    # teclas parametro defecto
    TeclasParamDefecto = {
        KeyboardButton.asciiKey(b"w"): InputMapper.ParametroAdelante,
        KeyboardButton.asciiKey(b"a"): InputMapper.ParametroIzquierda,
        KeyboardButton.asciiKey(b"s"): InputMapper.ParametroAtras,
        KeyboardButton.asciiKey(b"d"): InputMapper.ParametroDerecha,
        KeyboardButton.asciiKey(b"r"): InputMapper.ParametroArriba,
        KeyboardButton.asciiKey(b"f"): InputMapper.ParametroAbajo,
        KeyboardButton.asciiKey(b"q"):
        InputMapper.ParametroGirando | InputMapper.ParametroIzquierda,
        KeyboardButton.asciiKey(b"e"):
        InputMapper.ParametroGirando | InputMapper.ParametroDerecha,
        KeyboardButton.shift(): InputMapper.ParametroRapido,
        KeyboardButton.asciiKey(b"v"): InputMapper.ParametroLento
    }

    def __init__(self, base):
        InputMapper.__init__(self, base)

    def update(self):
        # parametros
        self.parametros = InputMapper.ParametroNulo
        for tecla, parametro in InputMapperTecladoMouse.TeclasParamDefecto.items(
        ):
            if self.isButtonDown(tecla):
                self.parametros |= parametro
        # acciones
        self.accion = InputMapper.AccionNula
        for tecla, accion in InputMapperTecladoMouse.TeclasAccionDefecto.items(
        ):
            if self.isButtonDown(tecla):
                self.accion = accion
                break
Exemplo n.º 2
0
    def initialize(self):
        self.lens = self.makeLens()
        self.camera = self.doc.render.attachNewNode(
            ModelNode("viewportCameraParent"))
        self.camNode = Camera("viewportCamera")
        self.camNode.setLens(self.lens)
        self.camNode.setCameraMask(self.getViewportMask())
        self.cam = self.camera.attachNewNode(self.camNode)

        winprops = WindowProperties.getDefault()
        winprops.setParentWindow(int(self.winId()))
        winprops.setForeground(False)
        winprops.setUndecorated(True)

        gsg = self.doc.gsg

        output = base.graphicsEngine.makeOutput(
            base.pipe, "viewportOutput", 0, FrameBufferProperties.getDefault(),
            winprops,
            (GraphicsPipe.BFFbPropsOptional | GraphicsPipe.BFRequireWindow),
            gsg)

        self.qtWindow = QtGui.QWindow.fromWinId(
            output.getWindowHandle().getIntHandle())
        self.qtWidget = QtWidgets.QWidget.createWindowContainer(
            self.qtWindow, self, QtCore.Qt.WindowDoesNotAcceptFocus
            | QtCore.Qt.WindowTransparentForInput
            | QtCore.Qt.WindowStaysOnBottomHint
            | QtCore.Qt.BypassWindowManagerHint | QtCore.Qt.SubWindow)  #,
        #(QtCore.Qt.FramelessWindowHint | QtCore.Qt.WindowDoesNotAcceptFocus
        #| QtCore.Qt.WindowTransparentForInput | QtCore.Qt.BypassWindowManagerHint
        #| QtCore.Qt.SubWindow | QtCore.Qt.WindowStaysOnBottomHint))
        self.qtWidget.setFocusPolicy(QtCore.Qt.NoFocus)

        self.inputDevice = output.getInputDevice(0)

        assert output is not None, "Unable to create viewport output!"

        dr = output.makeDisplayRegion()
        dr.disableClears()
        dr.setCamera(self.cam)
        self.displayRegion = dr

        output.disableClears()
        output.setClearColor(Viewport.ClearColor)
        output.setClearColorActive(True)
        output.setClearDepthActive(True)
        output.setActive(True)

        self.win = output

        # keep track of the mouse in this viewport
        mak = MouseAndKeyboard(self.win, 0, "mouse")
        mouse = base.dataRoot.attachNewNode(mak)
        self.mouseAndKeyboard = mouse
        self.mouseWatcher = MouseWatcher()
        self.mouseWatcher.setDisplayRegion(self.displayRegion)
        mw = mouse.attachNewNode(self.mouseWatcher)
        self.mouseWatcherNp = mw

        # listen for keyboard and mouse events in this viewport
        bt = ButtonThrower("kbEvents")
        bt.setButtonDownEvent("btndown")
        bt.setButtonUpEvent("btnup")
        mods = ModifierButtons()
        mods.addButton(KeyboardButton.shift())
        mods.addButton(KeyboardButton.control())
        mods.addButton(KeyboardButton.alt())
        mods.addButton(KeyboardButton.meta())
        bt.setModifierButtons(mods)
        self.buttonThrower = mouse.attachNewNode(bt)

        # collision objects for clicking on objects from this viewport
        self.clickRay = CollisionRay()
        self.clickNode = CollisionNode("viewportClickRay")
        self.clickNode.addSolid(self.clickRay)
        self.clickNp = NodePath(self.clickNode)
        self.clickQueue = CollisionHandlerQueue()

        self.setupRender2d()
        self.setupCamera2d()

        self.gizmo = ViewportGizmo(self)

        self.doc.viewportMgr.addViewport(self)

        self.makeGrid()