Merge pull request #6302 from AndrewMeadows/fix-avatar-drift

fix slow drift of avatar when wearing HMD
This commit is contained in:
Anthony Thibault 2015-11-04 11:19:45 -08:00
commit 275b248547
2 changed files with 5 additions and 4 deletions

View file

@ -1284,11 +1284,11 @@ void MyAvatar::prepareForPhysicsSimulation() {
_characterController.setAvatarPositionAndOrientation(getPosition(), getOrientation()); _characterController.setAvatarPositionAndOrientation(getPosition(), getOrientation());
if (qApp->isHMDMode()) { if (qApp->isHMDMode()) {
updateHMDFollowVelocity(); updateHMDFollowVelocity();
_characterController.setHMDVelocity(_hmdFollowVelocity); } else if (_isFollowingHMD) {
} else {
_characterController.setHMDVelocity(Vectors::ZERO);
_isFollowingHMD = false; _isFollowingHMD = false;
_hmdFollowVelocity = Vectors::ZERO;
} }
_characterController.setHMDVelocity(_hmdFollowVelocity);
} }
void MyAvatar::harvestResultsFromPhysicsSimulation() { void MyAvatar::harvestResultsFromPhysicsSimulation() {
@ -1324,6 +1324,7 @@ void MyAvatar::adjustSensorTransform(glm::vec3 hmdShift) {
// the "adjustment" is more or less complete so stop following // the "adjustment" is more or less complete so stop following
_isFollowingHMD = false; _isFollowingHMD = false;
_hmdFollowSpeed = 0.0f; _hmdFollowSpeed = 0.0f;
_hmdFollowVelocity = Vectors::ZERO;
// and slam the body's transform anyway to eliminate any slight errors // and slam the body's transform anyway to eliminate any slight errors
glm::vec3 finalBodyPosition = extractTranslation(worldBodyMatrix); glm::vec3 finalBodyPosition = extractTranslation(worldBodyMatrix);
nextAttitude(finalBodyPosition, finalBodyRotation); nextAttitude(finalBodyPosition, finalBodyRotation);

View file

@ -32,7 +32,7 @@ void AtRestDetector::reset(const glm::vec3& startPosition, const glm::quat& star
bool AtRestDetector::update(const glm::vec3& position, const glm::quat& rotation) { bool AtRestDetector::update(const glm::vec3& position, const glm::quat& rotation) {
uint64_t now = usecTimestampNow(); uint64_t now = usecTimestampNow();
float dt = (float)(_lastUpdateTime - now) / (float)USECS_PER_SECOND; float dt = (float)(now - _lastUpdateTime) / (float)USECS_PER_SECOND;
_lastUpdateTime = now; _lastUpdateTime = now;
const float TAU = 1.0f; const float TAU = 1.0f;
float delta = glm::min(dt / TAU, 1.0f); float delta = glm::min(dt / TAU, 1.0f);