WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 10-22-2007, 02:08 PM
Vinicius Lima Vinicius Lima is offline
Member
 
Join Date: Jul 2007
Posts: 40
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)
Reply With Quote
  #2  
Old 10-22-2007, 02:11 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
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.
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


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


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