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 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! :) |
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()]) |
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()? |
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) |
All times are GMT -7. The time now is 07:39 PM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC