#1
|
|||
|
|||
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: Code:
# 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) 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! |
#2
|
|||
|
|||
Try setting the timer expiration time to 0 so it expires every frame. Then use viz.getFrameElapsed to get the elapsed time since the previous frame and multiply that against the speed in m/s and joystick position:
Code:
viz.MainView.move([0, 0, -joy_y * SPEED * viz.getFrameElapsed()]) |
#3
|
|||
|
|||
Thanks a lot, Jeff, that was exactly what I was looking for!
And a follow-up question: Any suggestions how to achieve the same for rotating (not translating) the viewpoint, depending on the joystick's X deflection? Probably using viewpoint.moveTo()? |
#4
|
|||
|
|||
You could use viewpoint.setEuler and update the yaw value every frame:
Code:
viz.MainView.setEuler([ joy_x * TURN_SPEED * viz.getFrameElapsed(), 0, 0 ], viz.REL_PARENT) |
Tags |
joystick, velocity |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Mainview can't go back to original point | jacky | Vizard | 1 | 06-04-2013 05:22 AM |
joystick position | nmohandes | Vizard | 2 | 01-16-2012 11:03 AM |
how to remove velocity when mouse is disabled? | jvacare1 | Vizard | 2 | 02-18-2010 11:25 AM |
Joystick Navigation | Vinicius Lima | Vizard | 7 | 10-23-2007 11:42 AM |
Facetracking and Immersion Joystick | Vygreif | Vizard | 1 | 01-25-2006 11:56 AM |