From 61d4ac26751cd16d35f997dd99f6dc35832a14d0 Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Thu, 6 Jun 2013 09:52:39 -0700 Subject: [PATCH] Fixes per code review. --- interface/src/Avatar.cpp | 12 ++++++------ interface/src/SerialInterface.cpp | 16 ++++++++-------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index 3eefd6e791..00439986fa 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -524,8 +524,8 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) { } // Compute instantaneous acceleration - ; - float fwdAcceleration = glm::length(glm::dot(getBodyFrontDirection(), getVelocity() - oldVelocity)) / deltaTime; + + float forwardAcceleration = glm::length(glm::dot(getBodyFrontDirection(), getVelocity() - oldVelocity)) / deltaTime; const float ACCELERATION_PITCH_DECAY = 0.4f; const float ACCELERATION_YAW_DECAY = 0.4f; const float ACCELERATION_PULL_THRESHOLD = 0.2f; @@ -535,11 +535,11 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) { // Decay HeadPitch as a function of acceleration, so that you are pulled to look straight ahead when // you start moving, but don't do this with an HMD like the Oculus. if (!OculusManager::isConnected()) { - if (fwdAcceleration > ACCELERATION_PULL_THRESHOLD) { - _head.setPitch(_head.getPitch() * (1.f - fwdAcceleration * ACCELERATION_PITCH_DECAY * deltaTime)); - _head.setYaw(_head.getYaw() * (1.f - fwdAcceleration * ACCELERATION_YAW_DECAY * deltaTime)); + if (forwardAcceleration > ACCELERATION_PULL_THRESHOLD) { + _head.setPitch(_head.getPitch() * (1.f - forwardAcceleration * ACCELERATION_PITCH_DECAY * deltaTime)); + _head.setYaw(_head.getYaw() * (1.f - forwardAcceleration * ACCELERATION_YAW_DECAY * deltaTime)); } - } else if (fabsf(fwdAcceleration) > OCULUS_ACCELERATION_PULL_THRESHOLD + } else if (fabsf(forwardAcceleration) > OCULUS_ACCELERATION_PULL_THRESHOLD && fabs(_head.getYaw()) > OCULUS_YAW_OFFSET_THRESHOLD) { // if we're wearing the oculus // and this acceleration is above the pull threshold diff --git a/interface/src/SerialInterface.cpp b/interface/src/SerialInterface.cpp index 1fc993c174..1e472c5a11 100644 --- a/interface/src/SerialInterface.cpp +++ b/interface/src/SerialInterface.cpp @@ -259,20 +259,20 @@ void SerialInterface::readData(float deltaTime) { } else { // Use gravity reading to do sensor fusion on the pitch and roll estimation float truePitchAngle = glm::angle(glm::normalize(glm::vec3(0, _gravity.y, _gravity.z)), - glm::normalize(glm::vec3(0, _lastAcceleration.y, _lastAcceleration.z))) * - ((_lastAcceleration.z > _gravity.z) ? -1.0 : 1.0); + glm::normalize(glm::vec3(0, _lastAcceleration.y, _lastAcceleration.z))) + * ((_lastAcceleration.z > _gravity.z) ? -1.0 : 1.0); float trueRollAngle = glm::angle(glm::normalize(glm::vec3(_gravity.x, _gravity.y, 0)), - glm::normalize(glm::vec3(_lastAcceleration.x, _lastAcceleration.y, 0))) * - ((_lastAcceleration.x > _gravity.x) ? -1.0 : 1.0); + glm::normalize(glm::vec3(_lastAcceleration.x, _lastAcceleration.y, 0))) + * ((_lastAcceleration.x > _gravity.x) ? -1.0 : 1.0); // PER: BUG: This is bizarre, because glm::angle() SOMETIMES returns NaN for what seem to // be perfectly valid inputs. So I added these NaN tests, gotta fix. if (!glm::isnan(truePitchAngle) && !glm::isnan(trueRollAngle)) { - _estimatedRotation.x = (1.f - 1.f/(float)SENSOR_FUSION_SAMPLES) * _estimatedRotation.x + - 1.f/(float)SENSOR_FUSION_SAMPLES * truePitchAngle; - _estimatedRotation.z = (1.f - 1.f/(float)SENSOR_FUSION_SAMPLES) * _estimatedRotation.z + - 1.f/(float)SENSOR_FUSION_SAMPLES * trueRollAngle; + _estimatedRotation.x = (1.f - 1.f/(float)SENSOR_FUSION_SAMPLES) * _estimatedRotation.x + + 1.f/(float)SENSOR_FUSION_SAMPLES * truePitchAngle; + _estimatedRotation.z = (1.f - 1.f/(float)SENSOR_FUSION_SAMPLES) * _estimatedRotation.z + + 1.f/(float)SENSOR_FUSION_SAMPLES * trueRollAngle; // Without a compass heading, always decay estimated Yaw slightly const float YAW_DECAY = 0.995; _estimatedRotation.y *= YAW_DECAY;