(Deprecated) Use vibration on touch¶
Deprecated classes vrOculusTouchController and vrOpenVRController. See vrDeviceService, vrdVRDevice, vrdDeviceInteraction instead.
Oculus Rift¶
deprecated_VR_examples/VR-hands-vibrate-oculus.py¶
1# © 2024 Autodesk, Inc. All rights reserved.
2
3class OculusVibration:
4
5 def __init__(self, controller):
6 self.controller = controller
7
8 def stopVibration(self):
9 self.controller.triggerVibration(0.0, 0.0)
10 self.timer = None
11
12 def vibrate(self, frequency, amplitude, seconds):
13 # timer to stop the vibration
14 self.timer = vrTimer()
15 self.timer.setSingleShot(True)
16 self.timer.connect(self.stopVibration)
17 self.timer.setInterval(seconds)
18 self.timer.setActive(True)
19 # start vibration
20 self.controller.triggerVibration(frequency, amplitude)
21
22 def strongPulse(self):
23 frequency = 0.0 # 160 Hz
24 amplitude = 0.1
25 seconds = 0.1
26 self.vibrate(frequency, amplitude, seconds)
27
28 def weakPulse(self):
29 frequency = 0.0 # 160 Hz
30 amplitude = 0.1
31 seconds = 0.05
32 self.vibrate(frequency, amplitude, seconds)
33
34
35handRoleString = { Hand_Left : "Left", Hand_Right : "Right" }
36
37def handTouchStarted(touchedNodeId, fingerId, vibration):
38 print("handTouchStarted on controller {}, finger {}".format(handRoleString[vibration.controller.getHandRole()], str(fingerId)))
39 vibration.strongPulse()
40
41def handTouchStopped(touchedNodeId, fingerId, vibration):
42 print("handTouchStopped on controller {}, finger {}".format(handRoleString[vibration.controller.getHandRole()], str(fingerId)))
43 vibration.weakPulse()
44
45# Deprecated class vrOculusTouchController. See vrDeviceService, vrdVRDevice, vrdDeviceInteraction instead.
46leftController = vrOculusTouchController("LeftTouch")
47leftController.setVisible(True)
48leftVib = OculusVibration(leftController)
49
50leftController.connectSignal("handTouchStarted", handTouchStarted, leftVib)
51leftController.connectSignal("handTouchStopped", handTouchStopped, leftVib)
52
53rightController = vrOculusTouchController("RightTouch")
54rightController.setVisible(True)
55rightVib = OculusVibration(rightController)
56
57rightController.connectSignal("handTouchStarted", handTouchStarted, rightVib)
58rightController.connectSignal("handTouchStopped", handTouchStopped, rightVib)
Open VR¶
deprecated_VR_examples/VR-hands-vibrate-openvr.py¶
1# © 2024 Autodesk, Inc. All rights reserved.
2
3handRoleString = { Hand_Left : "Left", Hand_Right : "Right" }
4
5def handTouchStarted(touchedNodeId, fingerId, controller):
6 print("handTouchStarted on controller {}, finger {}".format(handRoleString[controller.getHandRole()], str(fingerId)))
7 controller.triggerHapticPulse(0,1000)
8
9def handTouchStopped(touchedNodeId, fingerId, controller):
10 print("handTouchStopped on controller {}, finger {}".format(handRoleString[controller.getHandRole()], str(fingerId)))
11 controller.triggerHapticPulse(0,300)
12
13# Deprecated class vrOpenVRController. See vrDeviceService, vrdVRDevice, vrdDeviceInteraction instead.
14controller0 = vrOpenVRController("Controller0")
15controller1 = vrOpenVRController("Controller1")
16controller0.setVisualizationMode(Visualization_Hand)
17controller1.setVisualizationMode(Visualization_Hand)
18
19controller0.connectSignal("handTouchStarted", handTouchStarted, controller0)
20controller1.connectSignal("handTouchStarted", handTouchStarted, controller1)
21controller0.connectSignal("handTouchStopped", handTouchStopped, controller0)
22controller1.connectSignal("handTouchStopped", handTouchStopped, controller1)