Fixes per code review.

This commit is contained in:
Philip Rosedale 2013-06-06 09:52:39 -07:00
parent 53e7ef439c
commit 61d4ac2675
2 changed files with 14 additions and 14 deletions

View file

@ -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

View file

@ -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;