55
66#include " DeviceDelegatePicoVR.h"
77#include " ElbowModel.h"
8- #include " BrowserEGLContext .h"
8+ #include " VRBrowserPico .h"
99
1010#include < EGL/egl.h>
1111#include " vrb/CameraEye.h"
@@ -53,6 +53,7 @@ struct DeviceDelegatePicoVR::State {
5353 float axisX = 0 ;
5454 float axisY = 0 ;
5555 ElbowModel::HandEnum hand;
56+ int hapticFrameID = 0 ;
5657 Controller ()
5758 : index(-1 )
5859 , created(false )
@@ -142,6 +143,16 @@ struct DeviceDelegatePicoVR::State {
142143 }
143144 }
144145
146+ void UpdateHaptics (Controller& aController) {
147+ uint64_t inputFrameID = 0 ;
148+ float pulseDuration = 0 .0f , pulseIntensity = 0 .0f ;
149+ controllerDelegate->GetHapticFeedback (aController.index , inputFrameID, pulseDuration, pulseIntensity);
150+
151+ if (aController.hapticFrameID != inputFrameID) {
152+ VRBrowserPico::UpdateHaptics (aController.index , pulseIntensity, pulseDuration);
153+ }
154+ }
155+
145156 void UpdateControllers () {
146157 for (int32_t i = 0 ; i < controllers.size (); ++i) {
147158 if (!controllers[i].enabled ) {
@@ -208,6 +219,10 @@ struct DeviceDelegatePicoVR::State {
208219 }
209220
210221 controllerDelegate->SetTransform (i, transform);
222+
223+ if (controllerDelegate->GetHapticCount (i)) {
224+ UpdateHaptics (controllers[i]);
225+ }
211226 }
212227 }
213228};
@@ -227,6 +242,10 @@ DeviceDelegatePicoVR::SetRenderMode(const device::RenderMode aMode) {
227242 return ;
228243 }
229244 m.renderMode = aMode;
245+ if (aMode == device::RenderMode::StandAlone) {
246+ // Ensure that all haptics are cancelled when exiting WebVR
247+ VRBrowserPico::CancelAllHaptics ();
248+ }
230249}
231250
232251device::RenderMode
@@ -296,7 +315,7 @@ DeviceDelegatePicoVR::SetControllerDelegate(ControllerDelegatePtr& aController)
296315 beam.TranslateInPlace (vrb::Vector (0 .0f , 0 .012f , -0 .06f ));
297316 m.controllerDelegate ->CreateController (index, int32_t (controller.hand ), controller.IsRightHand () ? " Pico Neo 2 (Right)" : " Pico Neo 2 (LEFT)" , beam);
298317 m.controllerDelegate ->SetButtonCount (index, kNumButtons );
299- m.controllerDelegate ->SetHapticCount (index, 0 );
318+ m.controllerDelegate ->SetHapticCount (index, 1 );
300319 } else {
301320 vrb::Matrix beam = vrb::Matrix::Rotation (vrb::Vector (1 .0f , 0 .0f , 0 .0f ), -vrb::PI_FLOAT / 11 .5f );
302321
0 commit comments