Beispiel #1
0
    def __init__(self):

        self.PTracker = 1
        self.ControlPressed = 0
        self.AltPressed = 0
        self.PanConstantX = 50
        self.PanConstantY = 50
        self.ZoomConstant = 1
        self.FrontWidth = 100
        self.FrontHeight = 100
        self.TopWidth = 100
        self.TopHeight = 100
        self.LeftWidth = 100
        self.LeftHeight = 100

        self.MouseButton = 0
        self.CurrentQuad = 4
        self.HorizontalAxis = 0.0
        self.VerticalAxis = 0.0
        #base.disableMouse()
        self.MouseDragging = 0
        self.currX = 0
        self.oldX = self.currX
        self.currY = 0
        self.oldY = self.currY

        self.FrontTexture = 1
        self.LeftTexture = 1
        self.PerspectiveTexture = 1
        self.TopTexture = 1

        self.FrontWire = 0
        self.LeftWire = 0
        self.PerspectiveWire = 0
        self.TopWire = 0

        # Keep track of the currently selected window... values are 1-4 for four quadrants of a standard
        # Cartesian coordinate system

        # These are the orthographic cameras
        # They will be restricted to panning and zooming i.e. no rotation
        # Top could be flipped to back, left to right and front to back
        self.topCam = render.attachNewNode(Camera('topCam'))
        self.frontCam = render.attachNewNode(Camera('frontCam'))
        self.leftCam = render.attachNewNode(Camera('leftCam'))

        # This camera will have a trackball control since its perspective
        self.perspectiveCam = render.attachNewNode(Camera('perspectiveCam'))

        #self.toplens=OrthographicLens()
        #self.leftLens=OrthographicLens()
        #self.frontLens=OrthographicLens()
        #self.perspectiveLens=base.cam.node().getLens()

        # For now all lenses are same as that of base.cam
        #self.topCamLens=OrthographicLens()
        #self.frontCamLens= base.cam.node().getLens()
        #self.leftCamLens= base.cam.node().getLens()
        #self.perspectiveCamLens= base.cam.node().getLens()

        # Manipulate lenses here if need be
        #self.topCamLens.setFilmSize(250)

        # Set the Lenses
        #self.topCam.node().setLens(self.topCamLens)
        #self.frontCam.node().setLens(self.frontCamLens)
        #self.leftCam.node().setLens(self.leftCamLens)
        #self.perspectiveCam.node().setLens(self.perspectiveCamLens)

        #self.badwiz = loader.loadModel('badwizard1')
        #self.badwiz.reparentTo(render)

        # Create four separate display regions for the quad view.
        # These will overlap the main display region
        # To stack these overlapping DisplayRegions, we need a new layer.  If
        # they didn't overlap, we could put them in the same layer.

        self.newLayer = base.win.getChannel(0).makeLayer()

        self.PerspectiveScene = NodePath('PerspectiveScene')
        self.FrontScene = NodePath('FrontScene')
        self.TopScene = NodePath('TopScene')
        self.LeftScene = NodePath('LeftScene')
        self.SceneParent = NodePath('SceneParent')

        #self.PerspectiveScene=render.copyTo(self.SceneParent)
        #self.FrontScene=render.copyTo(self.SceneParent)
        #self.TopScene=render.copyTo(self.SceneParent)
        #self.LeftScene=render.copyTo(self.SceneParent)

        self.PerspectiveScene = render
        self.FrontScene = render
        self.TopScene = render
        self.LeftScene = render

        #self.PerspectiveScene.reparentTo(self.SceneParent)
        #self.FrontScene.reparentTo(self.SceneParent)
        #self.TopScene.reparentTo(self.SceneParent)
        #self.LeftScene.reparentTo(self.SceneParent)

        self.Perspective = ViewPort(0.5, 1.0, 0.0, 0.5, self.newLayer,
                                    self.perspectiveCam,
                                    Vec4(0.75, 0.75, 0.75, 1), "perspective",
                                    "perspective", self.PerspectiveScene)
        self.Top = ViewPort(0.0, 0.5, 0.5, 1.0, self.newLayer, self.topCam,
                            Vec4(0.80, 0.80, 0.80, 1), "ortho", "top",
                            self.TopScene)
        self.Left = ViewPort(0.0, 0.5, 0.0, 0.5, self.newLayer, self.leftCam,
                             Vec4(0.85, 0.85, 0.85, 1), "ortho", "left",
                             self.LeftScene)
        self.Front = ViewPort(0.5, 1.0, 0.5, 1.0, self.newLayer, self.frontCam,
                              Vec4(0.85, 0.85, 0.85, 1), "ortho", "front",
                              self.FrontScene)
        #self.Perspective=None
        #self.Top=None
        #self.Front=None
        #self.Left=None

        #self.raycaster = RayCaster( camera )
        #self.lastPickPoint = None

        #base.useTrackball()

        #self.dataRoot = NodePath('dataRoot')
        # Cache the node so we do not ask for it every frame
        #self.dataRootNode = self.dataRoot.node()
        #self.dataUnused = NodePath('dataUnused')
        #self.mak=None
        #self.mak = self.dataRoot.attachNewNode(MouseAndKeyboard(base.win, 0, 'mak'))
        #self.mak.node().setSource(base.win, 0)
        self.mouseWatcherNode = MouseWatcher('mouseWatcher')

        self.mouseWatcher = base.mak.attachNewNode(self.mouseWatcherNode)
        #self.Perspective.setDR(self.mouseWatcherNode)

        self.buttonThrower = self.mouseWatcher.attachNewNode(
            ButtonThrower('buttons'))

        #ddr=DisplayRegionContext(self.Perspective.getCam())
        #base.setMouseOnNode(self.smiley.node()) # Let Mouse Control Perspective View for now
        #base.enableSoftwareMousePointer()

        # Message Handlers
        self.accept("a", self.setLeft)
        self.accept("q", self.setTop)
        self.accept("w", self.setFront)
        self.accept("s", self.setPerspective)
        self.accept("mouse1", self.MouseTell, [1])
        self.accept("mouse2", self.MouseTell, [2])
        self.accept("mouse3", self.MouseTell, [3])
        self.accept("mouse1-up", self.MouseTellUp, [4])
        self.accept("mouse2-up", self.MouseTellUp, [5])
        self.accept("mouse3-up", self.MouseTellUp, [6])
        self.accept("mouse2-scroll", self.resizedr)
        self.accept("r", self.resizedr)
        self.accept("alt", self.AltHandler)
        self.accept("alt-up", self.AltUpHandler)
        self.accept("alt-mouse1", self.AltDown)
        self.accept("alt-mouse1-up", self.AltUp)
        self.accept("control-mouse1", self.CtlDown)
        self.accept("control-mouse1-up", self.CtlUp)
Beispiel #2
0
 def setupMouse(self, win):
   """
   Creates the structures necessary to monitor the mouse input,
   using the indicated window.  If the mouse has already been set
   up for a different window, those structures are deleted first.
   """
   if self.buttonThrowers != None:
     for bt in self.buttonThrowers:
       mw = bt.getParent()
       mk = mw.getParent()
       bt.removeNode()
       mw.removeNode()
       mk.removeNode()
   # For each mouse/keyboard device, we create
   #  - MouseAndKeyboard
   #  - MouseWatcher
   #  - ButtonThrower
   # The ButtonThrowers are stored in a list, self.buttonThrowers.
   # Given a ButtonThrower, one can access the MouseWatcher and
   # MouseAndKeyboard using getParent.
   #
   # The MouseAndKeyboard generates mouse events and mouse
   # button/keyboard events; the MouseWatcher passes them through
   # unchanged when the mouse is not over a 2-d button, and passes
   # nothing through when the mouse *is* over a 2-d button.  Therefore,
   # objects that don't want to get events when the mouse is over a
   # button, like the driveInterface, should be parented to
   # MouseWatcher, while objects that want events in all cases, like the
   # chat interface, should be parented to the MouseAndKeyboard.
   
   self.buttonThrowers = []
   self.pointerWatcherNodes = []
   for i in range(win.getNumInputDevices()):
     name = win.getInputDeviceName(i)
     mk = base.dataRoot.attachNewNode(MouseAndKeyboard(win, i, name))
     mw = mk.attachNewNode(MouseWatcher("watcher%s" % (i)))
     mb = mw.node().getModifierButtons()
     mb.addButton(KeyboardButton.shift())
     mb.addButton(KeyboardButton.control())
     mb.addButton(KeyboardButton.alt())
     mb.addButton(KeyboardButton.meta())
     mw.node().setModifierButtons(mb)
     bt = mw.attachNewNode(ButtonThrower("buttons%s" % (i)))
     if (i != 0):
       bt.node().setPrefix('mousedev%s-' % (i))
     mods = ModifierButtons()
     mods.addButton(KeyboardButton.shift())
     mods.addButton(KeyboardButton.control())
     mods.addButton(KeyboardButton.alt())
     mods.addButton(KeyboardButton.meta())
     bt.node().setModifierButtons(mods)
     self.buttonThrowers.append(bt)
     if (win.hasPointer(i)):
       self.pointerWatcherNodes.append(mw.node())
   
   self.mouseWatcher = self.buttonThrowers[0].getParent()
   self.mouseWatcherNode = self.mouseWatcher.node()
   # print "ButtonThrowers = ", self.buttonThrowers
   # print "PointerWatcherNodes = ", self.pointerWatcherNodes
   
   # Now we have the main trackball & drive interfaces.
   # useTrackball() and useDrive() switch these in and out; only
   # one is in use at a given time.
   self.trackball = base.dataUnused.attachNewNode(Trackball('trackball'))
   self.drive = base.dataUnused.attachNewNode(DriveInterface('drive'))
   self.mouse2cam = base.dataUnused.attachNewNode(Transform2SG('mouse2cam'))
   self.mouse2cam.node().setNode(self.camera.node())
   
   # A special ButtonThrower to generate keyboard events and
   # include the time from the OS.  This is separate only to
   # support legacy code that did not expect a time parameter; it
   # will eventually be folded into the normal ButtonThrower,
   # above.
   mw = self.buttonThrowers[0].getParent()
   self.timeButtonThrower = mw.attachNewNode(ButtonThrower('timeButtons'))
   self.timeButtonThrower.node().setPrefix('time-')
   self.timeButtonThrower.node().setTimeFlag(1)