From 72403de2096cbd4049dda120e312707c1db8d680 Mon Sep 17 00:00:00 2001 From: bjorn Date: Wed, 31 Mar 2021 22:37:29 -0600 Subject: [PATCH] webxr: Add support for lovr.headset.getVelocity; --- src/resources/webxr.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/resources/webxr.js b/src/resources/webxr.js index 313a0ffc..f6ea53a8 100644 --- a/src/resources/webxr.js +++ b/src/resources/webxr.js @@ -273,7 +273,21 @@ var webxr = { }, webxr_getVelocity: function(device, velocity, angularVelocity) { - return false; // Unsupported, see immersive-web/webxr#619 + if (state.hands[device]) { + var space = state.hands[device].gripSpace || state.hands[device].targetRaySpace; + var pose = state.frame.getPose(space, state.space); + if (pose && pose.linearVelocity && pose.angularVelocity) { + HEAPF32[(velocity >> 2) + 0] = pose.linearVelocity.x; + HEAPF32[(velocity >> 2) + 1] = pose.linearVelocity.y; + HEAPF32[(velocity >> 2) + 2] = pose.linearVelocity.z; + HEAPF32[(angularVelocity >> 2) + 0] = pose.angularVelocity.x; + HEAPF32[(angularVelocity >> 2) + 1] = pose.angularVelocity.y; + HEAPF32[(angularVelocity >> 2) + 2] = pose.angularVelocity.z; + return true; + } + } + + return false; }, webxr_isDown: function(device, button, down, changed) {