webxr: Add support for lovr.headset.getVelocity;

This commit is contained in:
bjorn 2021-03-31 22:37:29 -06:00
parent 35032bb21c
commit 72403de209
1 changed files with 15 additions and 1 deletions

View File

@ -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) {