From 5050171d30b3e74321de840143a2cb6d0cc451f2 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Wed, 13 May 2015 11:34:19 -0700 Subject: [PATCH 1/2] Fix face-tracked head disappearing into body Normalize quaternion to ensure that acos(r.w) is valid (r.w <= 1.0) and r.w = 1.0 when r.x = r.y = r.z = 0.0. --- interface/src/devices/DdeFaceTracker.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/devices/DdeFaceTracker.cpp b/interface/src/devices/DdeFaceTracker.cpp index e0b888746f..db90f92f37 100644 --- a/interface/src/devices/DdeFaceTracker.cpp +++ b/interface/src/devices/DdeFaceTracker.cpp @@ -382,7 +382,7 @@ void DdeFaceTracker::decodePacket(const QByteArray& buffer) { // Compute relative rotation rotation = glm::inverse(_referenceRotation) * rotation; if (isFiltering) { - glm::quat r = rotation * glm::inverse(_headRotation); + glm::quat r = glm::normalize(rotation * glm::inverse(_headRotation)); float theta = 2 * acos(r.w); glm::vec3 angularVelocity; if (theta > EPSILON) { From 7319c7b767c01f735eee919c1ef9b769618f4d8b Mon Sep 17 00:00:00 2001 From: David Rowe Date: Wed, 13 May 2015 11:35:04 -0700 Subject: [PATCH 2/2] Fix face-tracked head rotation for Faceshift, also --- interface/src/devices/Faceshift.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/devices/Faceshift.cpp b/interface/src/devices/Faceshift.cpp index 409f359afa..b517f9d67b 100644 --- a/interface/src/devices/Faceshift.cpp +++ b/interface/src/devices/Faceshift.cpp @@ -213,7 +213,7 @@ void Faceshift::receive(const QByteArray& buffer) { glm::quat newRotation = glm::quat(data.m_headRotation.w, -data.m_headRotation.x, data.m_headRotation.y, -data.m_headRotation.z); // Compute angular velocity of the head - glm::quat r = newRotation * glm::inverse(_headRotation); + glm::quat r = glm::normalize(newRotation * glm::inverse(_headRotation)); float theta = 2 * acos(r.w); if (theta > EPSILON) { float rMag = glm::length(glm::vec3(r.x, r.y, r.z));