mirror of
https://github.com/overte-org/overte.git
synced 2025-04-25 20:16:16 +02:00
Fixes per code review.
This commit is contained in:
parent
53e7ef439c
commit
61d4ac2675
2 changed files with 14 additions and 14 deletions
|
@ -524,8 +524,8 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute instantaneous acceleration
|
// 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_PITCH_DECAY = 0.4f;
|
||||||
const float ACCELERATION_YAW_DECAY = 0.4f;
|
const float ACCELERATION_YAW_DECAY = 0.4f;
|
||||||
const float ACCELERATION_PULL_THRESHOLD = 0.2f;
|
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
|
// 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.
|
// you start moving, but don't do this with an HMD like the Oculus.
|
||||||
if (!OculusManager::isConnected()) {
|
if (!OculusManager::isConnected()) {
|
||||||
if (fwdAcceleration > ACCELERATION_PULL_THRESHOLD) {
|
if (forwardAcceleration > ACCELERATION_PULL_THRESHOLD) {
|
||||||
_head.setPitch(_head.getPitch() * (1.f - fwdAcceleration * ACCELERATION_PITCH_DECAY * deltaTime));
|
_head.setPitch(_head.getPitch() * (1.f - forwardAcceleration * ACCELERATION_PITCH_DECAY * deltaTime));
|
||||||
_head.setYaw(_head.getYaw() * (1.f - fwdAcceleration * ACCELERATION_YAW_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) {
|
&& fabs(_head.getYaw()) > OCULUS_YAW_OFFSET_THRESHOLD) {
|
||||||
// if we're wearing the oculus
|
// if we're wearing the oculus
|
||||||
// and this acceleration is above the pull threshold
|
// and this acceleration is above the pull threshold
|
||||||
|
|
|
@ -259,20 +259,20 @@ void SerialInterface::readData(float deltaTime) {
|
||||||
} else {
|
} else {
|
||||||
// Use gravity reading to do sensor fusion on the pitch and roll estimation
|
// 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)),
|
float truePitchAngle = glm::angle(glm::normalize(glm::vec3(0, _gravity.y, _gravity.z)),
|
||||||
glm::normalize(glm::vec3(0, _lastAcceleration.y, _lastAcceleration.z))) *
|
glm::normalize(glm::vec3(0, _lastAcceleration.y, _lastAcceleration.z)))
|
||||||
((_lastAcceleration.z > _gravity.z) ? -1.0 : 1.0);
|
* ((_lastAcceleration.z > _gravity.z) ? -1.0 : 1.0);
|
||||||
|
|
||||||
float trueRollAngle = glm::angle(glm::normalize(glm::vec3(_gravity.x, _gravity.y, 0)),
|
float trueRollAngle = glm::angle(glm::normalize(glm::vec3(_gravity.x, _gravity.y, 0)),
|
||||||
glm::normalize(glm::vec3(_lastAcceleration.x, _lastAcceleration.y, 0))) *
|
glm::normalize(glm::vec3(_lastAcceleration.x, _lastAcceleration.y, 0)))
|
||||||
((_lastAcceleration.x > _gravity.x) ? -1.0 : 1.0);
|
* ((_lastAcceleration.x > _gravity.x) ? -1.0 : 1.0);
|
||||||
|
|
||||||
// PER: BUG: This is bizarre, because glm::angle() SOMETIMES returns NaN for what seem to
|
// 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.
|
// be perfectly valid inputs. So I added these NaN tests, gotta fix.
|
||||||
if (!glm::isnan(truePitchAngle) && !glm::isnan(trueRollAngle)) {
|
if (!glm::isnan(truePitchAngle) && !glm::isnan(trueRollAngle)) {
|
||||||
_estimatedRotation.x = (1.f - 1.f/(float)SENSOR_FUSION_SAMPLES) * _estimatedRotation.x +
|
_estimatedRotation.x = (1.f - 1.f/(float)SENSOR_FUSION_SAMPLES) * _estimatedRotation.x
|
||||||
1.f/(float)SENSOR_FUSION_SAMPLES * truePitchAngle;
|
+ 1.f/(float)SENSOR_FUSION_SAMPLES * truePitchAngle;
|
||||||
_estimatedRotation.z = (1.f - 1.f/(float)SENSOR_FUSION_SAMPLES) * _estimatedRotation.z +
|
_estimatedRotation.z = (1.f - 1.f/(float)SENSOR_FUSION_SAMPLES) * _estimatedRotation.z
|
||||||
1.f/(float)SENSOR_FUSION_SAMPLES * trueRollAngle;
|
+ 1.f/(float)SENSOR_FUSION_SAMPLES * trueRollAngle;
|
||||||
// Without a compass heading, always decay estimated Yaw slightly
|
// Without a compass heading, always decay estimated Yaw slightly
|
||||||
const float YAW_DECAY = 0.995;
|
const float YAW_DECAY = 0.995;
|
||||||
_estimatedRotation.y *= YAW_DECAY;
|
_estimatedRotation.y *= YAW_DECAY;
|
||||||
|
|
Loading…
Reference in a new issue