From 8c0ae3fbb3a66c2320743071a0d47e51f81fb7c8 Mon Sep 17 00:00:00 2001 From: bjorn Date: Wed, 9 Oct 2019 14:53:58 -0700 Subject: [PATCH] More WebVR (controller) fixes; --- CMakeLists.txt | 3 ++- src/modules/headset/webvr.c | 2 +- src/resources/webvr.js | 10 ++++++++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c1c7aee6..d35f6cf2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -51,7 +51,8 @@ if(EMSCRIPTEN) "-s ALLOW_MEMORY_GROWTH=1 " "-s \"EXPORTED_FUNCTIONS=[ " "'_main','_lovrDestroy'," - "'_mat4_identity','_mat4_invert','_mat4_multiply','_mat4_rotateQuat','_mat4_transform','_mat4_transformDirection'," + "'_webvr_onAnimationFrame'," + "'_mat4_set','_mat4_identity','_mat4_invert','_mat4_multiply','_mat4_rotateQuat','_mat4_transform','_mat4_transformDirection'," "'_quat_fromMat4','_quat_getAngleAxis'" "]\" " "-s \"EXTRA_EXPORTED_RUNTIME_METHODS=['getValue','setValue']\" " diff --git a/src/modules/headset/webvr.c b/src/modules/headset/webvr.c index 7899a108..4b9b4b8f 100644 --- a/src/modules/headset/webvr.c +++ b/src/modules/headset/webvr.c @@ -28,7 +28,7 @@ static struct { void* renderData; } state; -static void webvr_onAnimationFrame(float* leftView, float* rightView, float* leftProjection, float* rightProjection) { +void webvr_onAnimationFrame(float* leftView, float* rightView, float* leftProjection, float* rightProjection) { Camera camera = { .canvas = NULL, .stereo = true }; memcpy(camera.projection[0], leftProjection, 16 * sizeof(float)); memcpy(camera.projection[1], rightProjection, 16 * sizeof(float)); diff --git a/src/resources/webvr.js b/src/resources/webvr.js index 9435dde0..3c52bb2a 100644 --- a/src/resources/webvr.js +++ b/src/resources/webvr.js @@ -69,7 +69,8 @@ var LibraryLOVR = { HEAPF32[webvr.poseTransform >> 2 + 13] = webvr.offset; } - Module._mat4_invert(Module._mat4_init(e, webvr.poseTransform)); + Module._mat4_set(e, webvr.poseTransform); + Module._mat4_invert(e); HEAPF32.set(webvr.frameData.leftViewMatrix, a >> 2); HEAPF32.set(webvr.frameData.rightViewMatrix, b >> 2); HEAPF32.set(webvr.frameData.leftProjectionMatrix, c >> 2); @@ -175,7 +176,8 @@ var LibraryLOVR = { if (pose.orientation) { HEAPF32.set(pose.orientation, orientation >> 2); - Module._mat4_rotateQuat(Module._mat4_init(webvr.matA, webvr.poseTransform), orientation); + Module._mat4_set(webvr.matA, webvr.poseTransform); + Module._mat4_rotateQuat(webvr.matA, orientation); Module._quat_fromMat4(orientation, webvr.matA); } else { HEAPF32.fill(0, orientation >> 2, orientation >> 2 + 4); @@ -297,6 +299,10 @@ var LibraryLOVR = { ORIGIN_HEAD: 0, ORIGIN_FLOOR: 1, + // Device + DEVICE_HAND_LEFT: 0, + DEVICE_HAND_RIGHT: 1, + // DeviceAxis AXIS_TRIGGER: 0, AXIS_THUMBSTICK: 1,