WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   How to get the data from Logitech G25 racing wheel ? (https://forum.worldviz.com/showthread.php?t=1759)

fuyonggang 12-17-2008 11:45 PM

How to get the data from Logitech G25 racing wheel ?
 
is it same as Joystick ?

farshizzo 12-18-2008 09:29 AM

Yes, it should be the same as any other joystick. Try running the joystick script that comes with Vizard. It will show you what kind of data the joystick outputs. The script is located at [Vizard]/examples/input/joystick.py

Jeff 12-18-2008 12:01 PM

I just had to use this script recently and noticed the slider gui object was missing. Here is the script with the slider added.

Code:

import viz
import vizjoy

viz.go()

import vizinfo
vizinfo.add('This script demonstrates how to retrieve certain states\nof the joystick and how to use joystick callbacks')

#IMPORTANT: Need to add a joystick. This will return the first detected joystick
joy = vizjoy.add()

#Add slider object and disable user input
slider = viz.add(viz.SLIDER)
slider.translate(.15,.62)
slider.disable()

#Add textures
arrow = viz.add('arrow.tif')
dot = viz.add('dot.tif')
up = viz.add('button_up.tif')
down = viz.add('button_down.tif')

#Add the texture quad to display the hat position
hat = viz.add(viz.TEXQUAD,viz.SCREEN)
hat.translate(0.1,0.8)
#Set the hat texture to the dot
hat.texture(dot)

#Add the texture quad for the joystick position
joystick = viz.add(viz.TEXQUAD,viz.SCREEN)
joystick.scale(0.3,0.3,1)
#Set the joystick texture to the dot
joystick.texture(dot)



#Create a border for the joystick position
JOY_CENTER_X = 0.5
JOY_CENTER_Y = 0.35
JOY_SCALE =  10.0
viz.startlayer(viz.LINE_LOOP)
viz.vertexcolor(viz.YELLOW)
viz.vertex((JOY_CENTER_X-(1.1/JOY_SCALE)),(JOY_CENTER_Y+(1.1/JOY_SCALE)))
viz.vertex((JOY_CENTER_X+(1.1/JOY_SCALE)),(JOY_CENTER_Y+(1.1/JOY_SCALE)))
viz.vertex((JOY_CENTER_X+(1.1/JOY_SCALE)),(JOY_CENTER_Y-(1.1/JOY_SCALE)))
viz.vertex((JOY_CENTER_X-(1.1/JOY_SCALE)),(JOY_CENTER_Y-(1.1/JOY_SCALE)))
viz.endlayer(viz.SCREEN)

#Add the texture quad to display the twist position
twist = viz.add(viz.TEXQUAD,viz.SCREEN)
twist.translate(0.1,0.45)
twist.texture(arrow)

#Add the texture quad and text for each button
buttons = []
for x in range(joy.getButtonCount()):
   
    text = viz.add(viz.TEXT3D,str(x+1),viz.SCREEN)
    text.alignment(viz.TEXT_CENTER_CENTER)
    text.scale(0.5,0.5,0.5)
    text.translate(x*0.07+0.04,0.1)
   
    quad = viz.add(viz.TEXQUAD,viz.SCREEN)
    quad.translate(x*0.07+0.04,0.05)
    quad.scale(0.5,0.5,0.5)
    quad.texture(up)
   
    buttons.append(quad)

#Joystick position has changed, update dot
def joymove(e):
    # e.pos    - new position value
    # e.oldPos  - old position value
    joystick.translate(JOY_CENTER_X+(e.pos[0]/10.0),JOY_CENTER_Y-(e.pos[1]/10.0))
   
#A joystick button is down, set it its texture to the down texture
def joydown(e):
    # e.button  - button number that is down
    buttons[e.button-1].texture(down)

#A joystick button is up, set it its texture to the up texture
def joyup(e):
    # e.button  - button number that is up
    buttons[e.button-1].texture(up)

#The joystick slider changed, set the slider position
def joyslider(e):
    # e.slider      - new slider value
    # e.oldSlider  - old slider value
    slider.set( (e.slider+1)/2.0 )
   
#The joystick hat changed, rotate the quad
def joyhat(e):
    # e.hat    - new hat value
    # e.oldHat  - old hat value
    if e.hat == -1:
        hat.texture(dot)
    else:
        hat.texture(arrow)
        hat.rotate(0,0,-1,e.hat)

#The joystick twist changed, rotate the quad
def joytwist(e):
    # e.twist      - new twist value
    # e.oldTwist    - old twist value
    twist.rotate(0,0,-1,e.twist*450)
   
#Set all the joystick callbacks
viz.callback(vizjoy.BUTTONDOWN_EVENT,joydown)
viz.callback(vizjoy.BUTTONUP_EVENT,joyup)
viz.callback(vizjoy.SLIDER_EVENT,joyslider)
viz.callback(vizjoy.HAT_EVENT,joyhat)
viz.callback(vizjoy.MOVE_EVENT,joymove)
viz.callback(vizjoy.TWIST_EVENT,joytwist)


farshizzo 12-18-2008 12:39 PM

The slider object and the text labels are defined in the stage (.viz) file. If you run the script from the directory I mentioned above it should show up fine.

fuyonggang 12-18-2008 06:14 PM

thanks ! got it
 
thanks for you all


All times are GMT -7. The time now is 08:30 AM.

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