From d2d28e6100fd06c3e485d90b8355904355d8c755 Mon Sep 17 00:00:00 2001 From: bjorn Date: Fri, 6 Jan 2017 18:43:24 -0800 Subject: [PATCH] Audio fixes; --- CMakeLists.txt | 10 ++++++++++ src/audio/audio.c | 9 ++++++++- src/matrix.c | 6 +++--- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e73dcde8..c790925c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -79,6 +79,14 @@ else() set(LOVR_ASSIMP ${ASSIMP_LIBRARIES}) endif() +# OpenAL +if (WIN32) + add_subdirectory(deps/openal-soft openal) + include_directories(deps/openal-soft/include) + set(LOVR_OPENAL OpenAL32) +endif() + + # openvr if(WIN32) include_directories(deps/openvr/headers) @@ -109,6 +117,7 @@ set(LOVR_LIB ${LOVR_GLFW} ${LOVR_PHYSFS} ${LOVR_ASSIMP} + ${LOVR_OPENAL} ${LOVR_OPENVR} ) @@ -120,4 +129,5 @@ if(WIN32) move_dll(${LOVR_GLFW}) move_dll(${LOVR_PHYSFS}) move_dll(${LOVR_ASSIMP}) + move_dll(${LOVR_OPENAL}) endif() diff --git a/src/audio/audio.c b/src/audio/audio.c index 9d56986d..eb2e80cd 100644 --- a/src/audio/audio.c +++ b/src/audio/audio.c @@ -78,9 +78,16 @@ void lovrAudioGetOrientation(float* angle, float* ax, float* ay, float* az) { float cx, cy, cz; cross(v[0], v[1], v[2], v[3], v[4], v[5], &cx, &cy, &cz); float w = 1 + v[0] * v[3] + v[1] * v[4] + v[2] * v[5]; + float len = sqrt(cx * cx + cy * cy + cz * cz + w * w); + if (len != 1) { + cx /= len; + cy /= len; + cz /= len; + w /= len; + } *angle = 2 * acos(w); float s = sqrt(1 - w * w); - if (w < .001) { + if (s < .001) { *ax = cx; *ay = cy; *az = cz; diff --git a/src/matrix.c b/src/matrix.c index 2f166eb7..888cb980 100644 --- a/src/matrix.c +++ b/src/matrix.c @@ -141,9 +141,9 @@ void mat4_getRotation(mat4 matrix, float* w, float* x, float* y, float* z) { float qx = sqrt(MAX(0, 1 + matrix[0] - matrix[5] - matrix[10])) / 2; float qy = sqrt(MAX(0, 1 - matrix[0] + matrix[5] - matrix[10])) / 2; float qz = sqrt(MAX(0, 1 - matrix[0] - matrix[5] + matrix[10])) / 2; - qx = (matrix[9] - matrix[6]) < 0 ? -qx : qx; - qy = (matrix[2] - matrix[8]) < 0 ? -qy : qy; - qz = (matrix[4] - matrix[1]) < 0 ? -qz : qz; + qx = (matrix[9] - matrix[6]) > 0 ? -qx : qx; + qy = (matrix[2] - matrix[8]) > 0 ? -qy : qy; + qz = (matrix[4] - matrix[1]) > 0 ? -qz : qz; float s = sqrt(1 - qw * qw); s = s < .001 ? 1 : s;