Hi again
Thanks for your answer.
I'm referring to the canvas example script, yes.
I tried to change the keypresses to button checks but I can't get it working. Is there a mistake somewhere in my script?
I'd be really glad for any kind of advice.
Code:
import viz
import vizact
import vizcam
import vizdlg
import vizinfo
import viztask
###
canvas = viz.addGUICanvas()
canvas.setRenderWorldOverlay([800,600],50,3)
canvas.setPosition([0,0,0])
viz.mouse.setTrap(True)
viz.mouse.setVisible(False)
canvas.setMouseStyle(viz.CANVAS_MOUSE_VIRTUAL)
# Apply settings
viz.MainWindow.setDefaultGUICanvas(canvas)
###
import oculus
hmd = oculus.Rift()
viz.link(hmd.getSensor(), viz.MainView)
viz.go()
###########################
remoteEnter = viz.addButton(oculus.BUTTON_REMOTE_ENTER)
remoteUp = viz.addButton(oculus.BUTTON_REMOTE_UP)
remoteDown = viz.addButton(oculus.BUTTON_REMOTE_DOWN)
remoteLeft = viz.addButton(oculus.BUTTON_REMOTE_LEFT)
remoteRight = viz.addButton(oculus.BUTTON_REMOTE_RIGHT)
###########################
# Load environment models
worlds = [ viz.addChild('maze.osgb'), viz.addChild('gallery.osgb'), viz.addChild('dojo.osgb') ]
for i, model in enumerate(worlds):
model.visible(i == 0)
controlPanel = vizinfo.InfoPanel(text='Navigate with WASD', title='Canvas Example')
controlPanel.addSeparator()
manual_cursor = controlPanel.addLabelItem('Manual Cursor',viz.addCheckbox())
######################
def ManualCursorPositionTask():
"""Use arrow keys to manually move canvas cursor"""
while True:
pos = canvas.getCursorPosition(viz.CANVAS_CURSOR_PIXELS)
inc = 250.0 * viz.getFrameElapsed()
# if viz.key.isDown(viz.KEY_UP):
# pos[1] += inc
# if viz.key.isDown(viz.KEY_LEFT):
# pos[0] -= inc
# if viz.key.isDown(viz.KEY_DOWN):
# pos[1] -= inc
# if viz.key.isDown(viz.KEY_RIGHT):
# pos[0] += inc
#
# canvas.setCursorPosition(pos, viz.CANVAS_CURSOR_PIXELS)
if remoteUp.get() == viz.DOWN:
pos[1] += inc
if remoteLeft.get() == viz.DOWN:
pos[0] -= inc
if remoteDown.get() == viz.DOWN:
pos[1] -= inc
if remoteRight.get() == viz.DOWN:
pos[0] += inc
canvas.setCursorPosition(pos, viz.CANVAS_CURSOR_PIXELS)
yield viztask.waitFrame(1)
######################
def ManualCursorButtonTask():
"""Use spacebar to manually simulate mouse press/release on canvas"""
while True:
# yield viztask.waitKeyDown(' ', priority=viz.PRIORITY_GUI_HANDLER-1)
#
# canvas.sendMouseButtonEvent(viz.MOUSEBUTTON_LEFT, viz.DOWN)
#
# yield viztask.waitKeyUp(' ', priority=viz.PRIORITY_GUI_HANDLER-1)
#
# canvas.sendMouseButtonEvent(viz.MOUSEBUTTON_LEFT, viz.UP)
yield viztask.waitButtonDown(remoteEnter, priority=viz.PRIORITY_GUI_HANDLER-1)
canvas.sendMouseButtonEvent(viz.MOUSEBUTTON_LEFT, viz.DOWN)
yield viztask.waitButtonUp(remoteEnter, priority=viz.PRIORITY_GUI_HANDLER-1)
canvas.sendMouseButtonEvent(viz.MOUSEBUTTON_LEFT, viz.UP)
def ToggleManualCursorTask():
"""Handle toggling of manual cursor mode"""
notice_panel = vizinfo.InfoPanel('Arrow keys control cursor.\nSpacebar simulates button press.', title='Manual Cursor Enabled', align=viz.ALIGN_RIGHT_TOP, key=None, icon=False)
notice_panel.visible(False)
while True:
yield viztask.waitButtonDown(manual_cursor)
# Enable manual cursor control
UpdateMouseStyle()
pos_task = viztask.schedule(ManualCursorPositionTask())
button_task = viztask.schedule(ManualCursorButtonTask())
notice_panel.visible(True)
yield viztask.waitButtonUp(manual_cursor)
# Disable manual cursor control
UpdateMouseStyle()
pos_task.remove()
button_task.remove()
notice_panel.visible(False)
viztask.schedule(ToggleManualCursorTask())