WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   In there a way in Vizconnect to allow user to select between different input devices (https://forum.worldviz.com/showthread.php?t=5214)

JB_HP_Viz 11-04-2014 07:05 AM

In there a way in Vizconnect to allow user to select between different input devices
 
Checking to see if there is a way in Vizconnect to allow the user to select controlling the MainView with either a Joystick, a tracker, a Kinect, keyboard/mouse or any other input device?

I can see how to do it using viz.link in the example code below where I have allow the user to choose between a Joystick or Keyboard Tracker using keys on the keyboard to change which controls the MainView. Just checking to see if there is a way to do this using Vizconnect?


Code:

import sys
import viz
import vizact
import vizconfig
import vizcam

viz.setMultiSample(4)
viz.fov(60)
viz.go()

import vizinfo
vizinfo.InfoPanel()

# Setup keyboard/mouse tracker
keyboard_tracker = vizcam.addWalkNavigate(moveScale=2.0)
keyboard_tracker.setPosition([0,1.8,0])

# Get list of joystick device information
dinput = viz.add('DirectInput.dle')
devices = dinput.getJoystickDevices()

# Exit if no joystick detected
if not devices:
        sys.exit('No joystick devices connected')

# If there is more than one device, then display selection dialog
if len(devices) > 1:
        selected = viz.choose('Select joystick device', [ d.productName for d in devices ])
else:
        selected = 0

# Connect to selected device
joy = dinput.addJoystick(devices[selected])
if not joy:
        sys.exit('Failed to connect to joystick')

# Set dead zone threshold so small movements of joystick are ignored
joy.setDeadZone(0.2)

# Display joystick information in config window
vizconfig.register(joy)
vizconfig.getConfigWindow().setWindowVisible(True)

# Create node for applying joystick movement and link to main view
joystick_node = viz.addGroup(pos=(0,1.8,0))
viz.link(joystick_node, viz.MainView)

# Use joystick axes to move joystick node
# Horizontal (X) axis controls yaw
# Vertical (Y) axis controls position
MOVE_SPEED = 5.0
TURN_SPEED = 90.0
def UpdateJoystickMovement():
        e = viz.elapsed()
        x,y,z = joy.getPosition()
        joystick_node.setEuler([x * TURN_SPEED * e, 0, 0], viz.REL_LOCAL)
        joystick_node.setPosition([0, 0, y * MOVE_SPEED * viz.getFrameElapsed()], viz.REL_LOCAL)
vizact.ontimer(0, UpdateJoystickMovement)

# Reset joystick when joystick button 0 is pressed
def ResetPosition():
        joystick_node.setPosition([0,1.8,0])
        joystick_node.setEuler([0,0,0])
vizact.onsensordown(joy, 0, ResetPosition)

# Add environment
viz.addChild('maze.osgb')

def linkJoystick():
        viz.link(joystick_node, viz.MainView)

vizact.onkeydown('j', linkJoystick)

def linkKeyboard():
        viz.link(keyboard_tracker,viz.MainView)
        viz.mouse.setVisible(False)

vizact.onkeydown('k', linkKeyboard)

thank you

John

Jeff 11-04-2014 12:12 PM

In the script that imports the vizconnect config you'll want to get a handle to the display (which includes the viewpoint) and whatever trackers/transports you'll want to set as the parent of the display. Then you can change the display's parent through the code. Here's a simple example:

Code:

import viz
import vizact
import vizconnect

vizconnect.go('vizconnect_config.py')
viz.addChild('piazza.osgb')

keyTracker = vizconnect.getTracker('keyboard')
mouseKeyTracker = vizconnect.getTracker('mouse_and_keyboard_walking')

display = vizconnect.getDisplay()

vizact.onkeydown('1',display.setParent,keyTracker)
vizact.onkeydown('2',display.setParent,mouseKeyTracker)


JB_HP_Viz 11-05-2014 12:40 PM

Thank you. Just tested, works great.

John


All times are GMT -7. The time now is 10:26 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2022, vBulletin Solutions, Inc.
Copyright 2002-2018 WorldViz LLC