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)