(Deprecated) Oculus touch example¶
Deprecated. See “Implementation of a custom device interaction”, “Combine a custom and a default device interaction”, “Scale geometry in VR by using controllers” and “Print the current finger position on the touchpad” instead.
deprecated_VR_examples/OculusTouchExample.vpb¶
1## Example on how to setup the oculus touch controller
2## Any print calls should be avoided in a real world scenario
3## since the can limit performance a lot
4from math import sqrt
5
6## find and remember the Controller nodes.
7## it should be avoided to call findNode often since it can
8## slow down rendering quite a bit
9leftNode = findNode("MatrixLeft")
10rightNode = findNode("MatrixRight")
11
12## Controller Movement
13def leftControllerMoved():
14 leftNode.setTransformMatrix( leftController.getWorldMatrix(), false)
15
16def rightControllerMoved():
17 rightNode.setTransformMatrix( rightController.getWorldMatrix(), false)
18
19## Button presses
20def buttonXPressed():
21 print "button X pressed"
22 leftController.setPickingAxis(0)
23 leftController.showPickingAxis(true)
24
25
26def buttonXReleased():
27 print "button X released"
28 leftController.setPickingAxis(0)
29 leftController.showPickingAxis(false)
30
31
32def buttonXIsPressed():
33 print "button X is pressed "
34
35def buttonXTouched():
36 print "button X touched"
37
38def buttonXUntouched():
39 print "button X untouched"
40
41def buttonXIsTouched():
42 print "button X is touched"
43
44def buttonYPressed():
45 print "button Y pressed"
46 leftController.setPickingAxis(1)
47 leftController.showPickingAxis(true)
48
49
50def buttonYReleased():
51 print "button Y released"
52 leftController.setPickingAxis(1)
53 leftController.showPickingAxis(false)
54 leftNode.setActive(false); # hide the controller so it is not picked
55 selectNode(leftController.pickNode())
56 leftNode.setActive(true); # unhide the controller so it is not picked
57
58def buttonYIsPressed():
59 print "button Y is pressed "
60
61def buttonYTouched():
62 print "button Y touched"
63
64def buttonYUntouched():
65 print "button Y untouched"
66
67def buttonYIsTouched():
68 print "button Y is touched"
69
70def buttonAPressed():
71 print "button A pressed"
72 rightController.setPickingAxis(2)
73 rightController.showPickingAxis(true)
74
75def buttonAReleased():
76 print "button A released"
77 rightController.setPickingAxis(2)
78 rightController.showPickingAxis(false)
79
80
81def buttonAIsPressed():
82 print "button A is pressed"
83
84def buttonATouched():
85 print "button A touched"
86
87def buttonAUntouched():
88 print "button A untouched"
89
90def buttonAIsTouched():
91 print "button A is touched"
92
93def buttonBPressed():
94 print "button B pressed"
95 rightController.setPickingAxis(3)
96 rightController.showPickingAxis(true)
97
98def buttonBReleased():
99 print "button B released"
100 rightController.setPickingAxis(3)
101 rightController.showPickingAxis(false)
102 rightNode.setActive(false); # hide the controller so it is not picked
103 selectNode(rightController.pickNode())
104 rightNode.setActive(true); # unhide the controller so it is not picked
105
106def buttonBIsPressed():
107 print "button B is pressed "
108
109def buttonBTouched():
110 print "button B touched"
111
112def buttonBUntouched():
113 print "button B untouched"
114
115def buttonBIsTouched():
116 print "button B is touched"
117
118## Thumbsticks
119def leftThumbstickPressed():
120 print("leftThumbstick pressed")
121
122def leftThumbstickReleased():
123 print("leftThumbstick released")
124
125def leftThumbstickIsPressed():
126 print("leftThumbstick is pressed")
127
128def leftThumbstickTouched():
129 print "leftThumbstick touched"
130
131def leftThumbstickUntouched():
132 print "leftThumbstick untouched"
133
134def leftThumbstickIsTouched():
135 print "leftThumbstick is touched"
136
137def leftThumbstickChanged(position):
138 #print "left Thumbstick PositionChanged"
139 oldPos = getOculusRiftTrackingOrigin()
140 touchPos = leftController.getThumbstickPosition()
141 scaleFactor = 25.0
142 #moveScaleForward = scaleFactor * touchPos.y()
143 #moveScaleSideways = scaleFactor * touchPos.x()
144 #camDirForward = getNormalizedDirection( getCamNode(-1).getWorldTransform())
145 #camDirSideways = Vec2f( -camDirForward.y(), camDirForward.x())
146 #newPos = Pnt3f(oldPos.x() + moveScaleForward * camDirForward.x() + moveScaleSideways * camDirSideways.x(), oldPos.y(), oldPos.z() + moveScaleForward*camDirForward.y() + moveScaleSideways * camDirSideways.y())
147 newPos = Pnt3f( oldPos.x() + scaleFactor * touchPos.x(), oldPos.y(), oldPos.z() + scaleFactor * touchPos.y());
148 setOculusRiftTrackingOrigin(newPos)
149
150def rightThumbstickPressed():
151 print("rightThumbstick pressed")
152
153def rightThumbstickReleased():
154 print("rightThumbstick released")
155
156def rightThumbstickIsPressed():
157 print("rightThumbstick is pressed")
158
159def rightThumbstickTouched():
160 print "rightThumbstick touched"
161
162def rightThumbstickUntouched():
163 print "rightThumbstick untouched"
164
165def rightThumbstickIsTouched():
166 print "rightThumbstick is touched"
167
168def rightThumbstickChanged(position):
169 print "rightThumbstick PositionChanged"
170 print position
171
172## Trigger
173def leftTriggerPressed():
174 print "left trigger"
175
176def leftTriggerReleased():
177 print "left trigger released"
178
179def leftTriggerIsPressed():
180 print "left trigger is pressed"
181
182def leftTriggerTouched():
183 print "leftTrigger touched"
184
185def leftTriggerUntouched():
186 print "leftTrigger untouched"
187
188def leftTriggerIsTouched():
189 print "leftTrigger is touched"
190
191def leftTriggerChanged(value):
192 print "leftTriggerChanged "
193 print value
194
195def rightTriggerPressed():
196 print "right trigger"
197
198def rightTriggerReleased():
199 print "right trigger released"
200
201def rightTriggerIsPressed():
202 print "right trigger is pressed"
203
204def rightTriggerTouched():
205 print "rightTrigger touched"
206
207def rightTriggerUntouched():
208 print "rightTrigger untouched"
209
210def rightTriggerIsTouched():
211 print "rightTrigger is touched"
212
213def rightTriggerChanged(value):
214 print "rightTriggerChanged "
215 print value
216
217## Hand Trigger (Grip)
218def leftHandTriggerPressed():
219 print "left hand trigger"
220
221def leftHandTriggerReleased():
222 print "left hand trigger released"
223
224def leftHandTriggerIsPressed():
225 print "left hand trigger is pressed"
226
227def leftHandTriggerChanged(value):
228 print "leftHandTriggerChanged "
229 leftController.triggerVibration(1.0, value)
230
231def rightHandTriggerPressed():
232 print "right hand trigger"
233
234def rightHandTriggerReleased():
235 print "right hand trigger released"
236
237def rightHandTriggerIsPressed():
238 print "right hand trigger is pressed"
239
240def rightHandTriggerChanged(value):
241 print "rightHandTriggerChanged "
242 rightController.triggerVibration(0.5, value)
243
244def getNormalizedDirection(matrix):
245 inVec = Vec2f( -matrix[2], matrix[6])
246 rescale = 1.0 / sqrt( inVec.x()*inVec.x() + inVec.y() * inVec.y())
247 return Vec2f( inVec.x() * rescale, inVec.y() * rescale)
248
249## Thumb Rest
250def leftThumbRestTouched():
251 print "leftThumbRest touched"
252
253def leftThumbRestUntouched():
254 print "leftThumbRest untouched"
255
256def leftThumbRestIsTouched():
257 print "leftThumbRest is touched"
258
259def rightThumbRestTouched():
260 print "rightThumbRest touched"
261
262def rightThumbRestUntouched():
263 print "rightThumbRest untouched"
264
265def rightThumbRestIsTouched():
266 print "rightThumbRest is touched"
267
268##
269## Create two controller and connect their signals to functions as needed
270##
271
272#
273## Left controller, must be namend LeftTouch
274leftController = vrOculusTouchController("LeftTouch")
275leftController.connectSignal("controllerMoved", leftControllerMoved)
276leftController.connectSignal("button0Pressed", buttonXPressed)
277leftController.connectSignal("button0Released", buttonXReleased)
278leftController.connectSignal("button0IsPressed", buttonXIsPressed)
279leftController.connectSignal("button0Touched", buttonXTouched)
280leftController.connectSignal("button0Untouched", buttonXUntouched)
281leftController.connectSignal("button0IsTouched", buttonXIsTouched)
282
283leftController.connectSignal("button1Pressed", buttonYPressed)
284leftController.connectSignal("button1Released", buttonYReleased)
285leftController.connectSignal("button1IsPressed", buttonYIsPressed)
286leftController.connectSignal("button1Touched", buttonYTouched)
287leftController.connectSignal("button1Untouched", buttonYUntouched)
288leftController.connectSignal("button1IsTouched", buttonYIsTouched)
289
290leftController.connectSignal("thumbstickPressed", leftThumbstickPressed)
291leftController.connectSignal("thumbstickReleased", leftThumbstickReleased)
292leftController.connectSignal("thumbstickIsPressed", leftThumbstickIsPressed)
293leftController.connectSignal("thumbstickTouched", leftThumbstickTouched)
294leftController.connectSignal("thumbstickUntouched", leftThumbstickUntouched)
295leftController.connectSignal("thumbstickIsTouched", leftThumbstickIsTouched)
296leftController.connectSignal("thumbstickChanged", leftThumbstickChanged)
297
298leftController.connectSignal("thumbRestTouched", leftThumbRestTouched)
299leftController.connectSignal("thumbRestUntouched", leftThumbRestUntouched)
300leftController.connectSignal("thumbRestIsTouched", leftThumbRestIsTouched)
301
302leftController.connectSignal("triggerPressed", leftTriggerPressed)
303leftController.connectSignal("triggerReleased", leftTriggerReleased)
304leftController.connectSignal("triggerIsPressed", leftTriggerIsPressed)
305leftController.connectSignal("triggerTouched", leftTriggerTouched)
306leftController.connectSignal("triggerUntouched", leftTriggerUntouched)
307leftController.connectSignal("triggerIsTouched", leftTriggerIsTouched)
308leftController.connectSignal("triggerChanged", leftTriggerChanged)
309
310leftController.connectSignal("handTriggerPressed", leftHandTriggerPressed)
311leftController.connectSignal("handTriggerReleased", leftHandTriggerReleased)
312leftController.connectSignal("handTriggerIsPressed", leftHandTriggerIsPressed)
313leftController.connectSignal("handTriggerChanged", leftHandTriggerChanged)
314
315
316
317## Right controller, must be namend RightTouch
318rightController = vrOculusTouchController("RightTouch")
319rightController.connectSignal("controllerMoved", rightControllerMoved)
320
321rightController.connectSignal("button0Pressed", buttonAPressed)
322rightController.connectSignal("button0Released", buttonAReleased)
323rightController.connectSignal("button0IsPressed", buttonAIsPressed)
324rightController.connectSignal("button0Touched", buttonATouched)
325rightController.connectSignal("button0Untouched", buttonAUntouched)
326rightController.connectSignal("button0IsTouched", buttonAIsTouched)
327
328rightController.connectSignal("button1Pressed", buttonBPressed)
329rightController.connectSignal("button1Released", buttonBReleased)
330rightController.connectSignal("button1IsPressed", buttonBIsPressed)
331rightController.connectSignal("button1Touched", buttonBTouched)
332rightController.connectSignal("button1Untouched", buttonBUntouched)
333rightController.connectSignal("button1IsTouched", buttonBIsTouched)
334
335
336rightController.connectSignal("thumbstickPressed", rightThumbstickPressed)
337rightController.connectSignal("thumbstickReleased", rightThumbstickReleased)
338rightController.connectSignal("thumbstickIsPressed", rightThumbstickIsPressed)
339rightController.connectSignal("thumbstickTouched", rightThumbstickTouched)
340rightController.connectSignal("thumbstickUntouched", rightThumbstickUntouched)
341rightController.connectSignal("thumbstickIsTouched", rightThumbstickIsTouched)
342rightController.connectSignal("thumbstickChanged", rightThumbstickChanged)
343
344rightController.connectSignal("thumbRestTouched", rightThumbRestTouched)
345rightController.connectSignal("thumbRestUntouched", rightThumbRestUntouched)
346rightController.connectSignal("thumbRestIsTouched", rightThumbRestIsTouched)
347
348rightController.connectSignal("triggerPressed", rightTriggerPressed)
349rightController.connectSignal("triggerReleased", rightTriggerReleased)
350rightController.connectSignal("triggerIsPressed", rightTriggerIsPressed)
351rightController.connectSignal("triggerTouched", rightTriggerTouched)
352rightController.connectSignal("triggerUntouched", rightTriggerUntouched)
353rightController.connectSignal("triggerIsTouched", rightTriggerIsTouched)
354rightController.connectSignal("triggerChanged", rightTriggerChanged)
355
356rightController.connectSignal("handTriggerPressed", rightHandTriggerPressed)
357rightController.connectSignal("handTriggerReleased", rightHandTriggerReleased)
358rightController.connectSignal("handTriggerIsPressed", rightHandTriggerIsPressed)
359rightController.connectSignal("handTriggerChanged", rightHandTriggerChanged)
360
361rightController.setCustomPickingDirection( Pnt3f(0.0,0.0,0.0), Vec3f(0.0,1.0,0.0), Vec3f(1.0, 0.0, 1.0))
362
363setOculusRiftTrackingOriginType(1) # set the origin to standing
364setOculusRiftTrackingOrigin( Pnt3f(0.0, 0.0, 0.0))
365resetOculusRiftOrientation()