WorldViz User Forum

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

Plasma 01-31-2004 08:06 AM

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!

farshizzo 02-02-2004 09:46 AM

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.

Plasma 02-03-2004 08:15 AM

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!

farshizzo 02-03-2004 11:16 AM

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)



All times are GMT -7. The time now is 10:13 PM.

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