WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 01-31-2004, 08:06 AM
Plasma Plasma is offline
Member
 
Join Date: Jan 2004
Posts: 22
Another Joystick Question

I'm trying to get Vizard to print the user's yaw and positional information when the joystick trigger is pulled. I've used the sid.get() command to determine that the trigger is button number 1.

However, when I to call on that button using something like this:

if data[2] == viz.BUTTON_1:
print yaw,pos

it returns the following message:

AttributeError: 'module' object has no attribute 'BUTTON_1'

How does Vizard call on joystick buttons?

Thanks!
Reply With Quote
  #2  
Old 02-02-2004, 09:46 AM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Hi,

To test whether joystick button 1 is down use the following code:
Code:
buttons = sid.buttons()
if buttons & 1:
	print 'button 1 is down'
Accessing joystick information is somewhat cryptic right now, in the next version we will make it a lot easier to use.
Reply With Quote
  #3  
Old 02-03-2004, 08:15 AM
Plasma Plasma is offline
Member
 
Join Date: Jan 2004
Posts: 22
Perfect.

I have it set up to give the user's yaw and positional data on the trigger press, but because it is within the joystick control loop, when the trigger is pressed, I get about 10 sets of information.

Is there a way to make it so that, no matter how long the trigger is held down, it only prints the information once?

Thanks!
Reply With Quote
  #4  
Old 02-03-2004, 11:16 AM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Hi,

The upcoming version of Vizard will allow you to create callbacks for joystick buttons, but for now you'll have to manually check when a button is first pressed. Here's a simple example:
Code:
import viz
import sid

viz.go()

laststate = sid.buttons()

def mytimer(num):
	global laststate
	state = sid.buttons()
	if state & 1 and not laststate & 1:
		print 'button pressed down'
	laststate = state

viz.callback(viz.TIMER_EVENT,mytimer)
viz.starttimer(0,0.001,viz.FOREVER)
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:48 AM.


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