View Single Post
Old 01-16-2014, 07:06 AM
4711 4711 is offline
Join Date: Jan 2010
Posts: 15
MainView velocity depending on joystick deflection

Hi all,

how can I move the viz.MainView with a certain velocity (in virtual meters per second) independent of the controlling device (i.e. joystick, gamepad, ...) and the machine on which I'm running the script (i.e., old laptop, new desktop, ...)?

Currently I'm using:

# add joystick
joy = vizjoy.add()

# define joystick parameters
thresh = 0.2
stepWidth = 0.01

# timer function, called every 0.05 seconds
def updateJoystick(self):
	# get joystick position
	joy_x, joy_y, joy_z = joy.getPosition()

	# move viewpoint forward/backward based on y-axis value
	if abs(joy_y) > thresh:
		viz.MainView.move([0, 0, -joy_y*stepWidth], viz.VIEW_ORI)
	# move viewpoint left/right based on x-axis value
	if abs(joy_x) > thresh:
		viz.MainView.move([joy_x*stepWidth, 0, 0], viz.VIEW_ORI)

# schedule timer
vizact.ontimer(0.05, updateJoystick)
This works nice in principle, but the actual speed, that is, the distance moved within the 0.05 seconds, seems to depend on both the input device (i.e.., one joystick seems to generate faster movement than another), and the machine (i.e., on faster computers the distance is larger than on older machines). That means I have to determine the stepWidth manually for each machine and device, based on trial and error.

So, is there a way around this? Is it possible to set the MainView's velocity in m/s, depending on the joystick's current deflection (via joy.getPosition())?

Any help is appreciated!
Reply With Quote