webxr: also support velocity of head device;

This commit is contained in:
bjorn 2021-03-31 22:47:26 -06:00
parent 72403de209
commit 923498a927
1 changed files with 18 additions and 11 deletions

View File

@ -273,18 +273,25 @@ var webxr = {
},
webxr_getVelocity: function(device, velocity, angularVelocity) {
if (state.hands[device]) {
var pose;
if (device === 0 /* DEVICE_HEAD */) {
pose = state.viewer;
} else 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;
}
pose = state.frame.getPose(space, state.space);
} else {
return false;
}
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;