vrJoystick demo¶
joystick.py¶
1# © 2024 Autodesk, Inc. All rights reserved.
2
3print("Executing move script!")
4
5newScene()
6
7def moveLeft(node, step):
8 pos = node.getTranslation()
9 node.setTranslation(pos[0] - step, pos[1], pos[2])
10
11def moveRight(node, step):
12 pos = node.getTranslation()
13 node.setTranslation(pos[0] + step, pos[1], pos[2])
14
15def moveUp(node, step):
16 pos = node.getTranslation()
17 node.setTranslation(pos[0], pos[1] + step, pos[2])
18
19def moveDown(node, step):
20 pos = node.getTranslation()
21 node.setTranslation(pos[0], pos[1] - step, pos[2])
22
23def movedJoystick(js, node):
24 #print js.getButtons()
25 #print js.getAxes()
26
27 # move speed
28 step = 0.1
29
30 # buttons
31 buttons = js.getButtons()
32
33 if buttons & 8:
34 moveLeft(node, step)
35 if buttons & 2:
36 moveRight(node, step)
37 if buttons & 1:
38 moveUp(node, step)
39 if buttons & 4:
40 moveDown(node, step)
41
42 # analog stick
43 axes = js.getAxes()
44 if len(axes) >= 2:
45 if axes[0] < 0.0:
46 moveLeft(node, abs(axes[0] * step))
47 if axes[0] > 0.0:
48 moveRight(node, abs(axes[0] * step))
49 if axes[1] < 0.0:
50 moveUp(node, abs(axes[1] * step))
51 if axes[1] > 0.0:
52 moveDown(node, abs(axes[1] * step))
53
54loadGeometry("$VRED_EXAMPLES/geo/cube.osb")
55updateScene()
56setFromAtUp(0, 0.5,0.5,8, 0.5,0.5,0.5, 0,1,0)
57
58# Searches for the node via regular expression.
59cube = findNode("*cube*", true);
60cube.makeTransform()
61
62joystick = vrJoystick()
63joystick.connect(movedJoystick, joystick, cube)
64
65vrLogWarning("Use your joystick to move the object.")