I am closing the default window openend by DirectStart and opening my own with it’s own display region. I would like enable the standard trackball camera controls in this window, but am having difficulty.
I have attempted to set up a mouseWatcher for the window, but I can’t seem to control the camera. Is there a simple way to grab the trackball data and attach a costume camera to it?
The code I am using to open the window and set up the mouse watcher is here.
from direct.directbase.DirectStart import *
from pandac.PandaModules import *
base.closeWindow(base.winList[0])
wp = WindowProperties()
newWindow = base.openWindow(props = wp)
newCamera = hidden.attachNewNode('newCam')
camNode = Camera('cam')
lens = PerspectiveLens()
camNode.setLens(lens)
newCam = newCamera.attachNewNode(camNode)
newRender = NodePath('newRender')
DR = newWindow.getActiveDisplayRegion(0)
camNode.setScene(newRender)
DR.setCamera(newCam)
smiley = loader.loadModel('models/misc/smiley')
smiley.reparentTo(newRender)
newCam.setPos(5,5,5)
newCam.lookAt(smiley)
cardMaker = CardMaker('test')
cardMaker.setFrame(-1,1,-1,1)
card = NodePath(cardMaker.generate())
card.reparentTo(newRender)
mak = base.dataRoot.attachNewNode(MouseAndKeyboard(newWindow, 0, 'mak'))
mouseWatcherNode = MouseWatcher('mouseWatcher')
mouseWatcher = mak.attachNewNode(mouseWatcherNode)
mb = mouseWatcherNode.getModifierButtons()
mb.addButton(KeyboardButton.shift())
mb.addButton(KeyboardButton.control())
mb.addButton(KeyboardButton.alt())
mouseWatcherNode.setModifierButtons(mb)
# 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.
trackball = base.dataUnused.attachNewNode(Trackball('trackball'))
drive = base.dataUnused.attachNewNode(DriveInterface('drive'))
mouse2cam = base.dataUnused.attachNewNode(Transform2SG('mouse2cam'))
mouse2cam.node().setNode(newCam.node())
# The default is trackball mode, which is more convenient for
# ad-hoc development in Python using ShowBase. Applications
# can explicitly call base.useDrive() if they prefer a drive
# interface.
mouseInterface = trackball
#self.useTrackball()
# A ButtonThrower to generate events from the mouse and
# keyboard buttons as they are pressed.
buttonThrower = mouseWatcher.attachNewNode(ButtonThrower('buttons'))
buttonThrower.node().setPrefix('seatView-')
# Specialize the events based on whether the modifier keys are
# being held down.
mods = ModifierButtons()
mods.addButton(KeyboardButton.shift())
mods.addButton(KeyboardButton.control())
mods.addButton(KeyboardButton.alt())
buttonThrower.node().setModifierButtons(mods)
mouseWatcherNode.addRegion(PGMouseWatcherBackground())