WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   Joystick Navigation (https://forum.worldviz.com/showthread.php?t=1253)

Vinicius Lima 10-20-2007 02:43 PM

Joystick Navigation
 
Hi,

I am trying to use a joystick to navigate in interior spaces. So, I would like to be able to look up and down at the ceiling and floor and so far, my script is not doing that. I pasted the script I am using here and if I could get the information I am missing it would be great.

Thanks!

Vinicius


import viz
import vizjoy
viz.go()

#Add a ground model
viz.add('tut_ground.wrl')

#Add a joystick
joy = vizjoy.add()

def UpdateJoystick():
#Get the joystick position
x,y,z = joy.getPosition()
#Get the twist of the joystick
twist = joy.getTwist()
#Move the viewpoint forward/backward based on y-axis value
if abs(y) > 0.2: #Make sure value is above a certain threshold
viz.MainView.move(0,0,-y*0.1,viz.BODY_ORI)
#Move the viewpoint left/right based on x-axis value
if abs(x) > 0.2: #Make sure value is above a certain threshold
viz.MainView.move(x*0.1,0,0,viz.BODY_ORI)
#Turn the viewpoint left/right based on twist value
if abs(twist) > 0.2: #Make sure value is above a certain threshold
viz.MainView.rotate(0,1,0,twist,viz.BODY_ORI,viz.R ELATIVE_WORLD)

#UpdateJoystick every frame
vizact.ontimer(0,UpdateJoystick)

#Register a callback for joystick button events
def onjoybutton(e):
print 'Joystick button',e.button,'pressed'
viz.callback(vizjoy.BUTTONDOWN_EVENT,onjoybutton)

farshizzo 10-22-2007 11:50 AM

Can you please repost your script using the [code][/code] tags?

Vinicius Lima 10-22-2007 01:08 PM

Hi,

is that the way I'm supposed to do it?



Code:

import viz
import vizjoy
viz.go()

#Add a ground model
viz.add('tut_ground.wrl')

#Add a joystick
joy = vizjoy.add()

def UpdateJoystick():
#Get the joystick position
x,y,z = joy.getPosition()
#Get the twist of the joystick
twist = joy.getTwist()
#Move the viewpoint forward/backward based on y-axis value
if abs(y) > 0.2: #Make sure value is above a certain threshold
viz.MainView.move(0,0,-y*0.1,viz.BODY_ORI)
#Move the viewpoint left/right based on x-axis value
if abs(x) > 0.2: #Make sure value is above a certain threshold
viz.MainView.move(x*0.1,0,0,viz.BODY_ORI)
#Turn the viewpoint left/right based on twist value
if abs(twist) > 0.2: #Make sure value is above a certain threshold
viz.MainView.rotate(0,1,0,twist,viz.BODY_ORI,viz.R ELATIVE_WORLD)

#UpdateJoystick every frame
vizact.ontimer(0,UpdateJoystick)

#Register a callback for joystick button events
def onjoybutton(e):
print 'Joystick button',e.button,'pressed'
viz.callback(vizjoy.BUTTONDOWN_EVENT,onjoybutton)


farshizzo 10-22-2007 01:11 PM

No, you need to copy the code from Vizard then paste it into the form inside the code tags. The reason this is necessary is because it will preserve the original indentation of your code. Without the indentation, I cannot run your code.

Vinicius Lima 10-22-2007 01:14 PM

I'm trying again.

Code:

import viz
import vizjoy
viz.go()

#Add a ground model
viz.add('tut_ground.wrl')

#Add a joystick
joy = vizjoy.add()

def UpdateJoystick():
    #Get the joystick position
    x,y,z = joy.getPosition()
    #Get the twist of the joystick
    twist = joy.getTwist()
    #Move the viewpoint forward/backward based on y-axis value
    if abs(y) > 0.2: #Make sure value is above a certain threshold
        viz.MainView.move(0,0,-y*0.1,viz.BODY_ORI)
    #Move the viewpoint left/right based on x-axis value
    if abs(x) > 0.2: #Make sure value is above a certain threshold
        viz.MainView.move(x*0.1,0,0,viz.BODY_ORI)
    #Turn the viewpoint left/right based on twist value
    if abs(twist) > 0.2: #Make sure value is above a certain threshold
        viz.MainView.rotate(0,1,0,twist,viz.BODY_ORI,viz.RELATIVE_WORLD)

#UpdateJoystick every frame
vizact.ontimer(0,UpdateJoystick)

#Register a callback for joystick button events
def onjoybutton(e):
    print 'Joystick button',e.button,'pressed'
viz.callback(vizjoy.BUTTONDOWN_EVENT,onjoybutton)


farshizzo 10-22-2007 02:04 PM

I tried your script and the behavior I get is that moving the joystick forward/backward will move the viewpoint forward/backward. Moving the joystick left/right will move the viewpoint left/right. Turning the joystick will also turn the viewpoint. Is this not what you want? I don't understand what the problem is.

Vinicius Lima 10-23-2007 10:39 AM

well, what I am trying to do is be able to navigate in a room and look up and down as well (at the ceiling and the floor). So far, with this script I haven't been able to.

farshizzo 10-23-2007 10:42 AM

You've programmed the script to move the viewpoint when the joystick is moved. If you want the viewpoint to look up/down when the joystick is moved, then use the viewpoint.rotate() command instead of the viewpoint.move() command.


All times are GMT -7. The time now is 02:22 AM.

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