WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 11-04-2014, 07:05 AM
JB_HP_Viz JB_HP_Viz is offline
Member
 
Join Date: Jun 2014
Posts: 31
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
Reply With Quote
  #2  
Old 11-04-2014, 12:12 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
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)
Reply With Quote
  #3  
Old 11-05-2014, 12:40 PM
JB_HP_Viz JB_HP_Viz is offline
Member
 
Join Date: Jun 2014
Posts: 31
Thank you. Just tested, works great.

John
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
multi user environment tutorial maya Vizard 0 11-23-2013 08:35 AM
User keyboard input without halting the program Zhi Vizard 2 06-23-2011 12:53 PM
Controlling User Input ohad Vizard 1 03-15-2010 05:16 PM
User Input Hodge1620 Vizard 2 11-17-2005 06:58 AM
user input problem Jerry Vizard 1 11-16-2005 03:15 PM


All times are GMT -7. The time now is 07:34 AM.


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