overte/libraries/shared/src/AtRestDetector.h
Anthony J. Thibault 2dabe69341 When HMD is at rest, re-center the body under the avatar.
This should help the case when a user avatar is stuck in an
uncomfortable pose for a long period of time.  If they stop
moving their head, the body should recenter itself and
appear more natural.

Added an AtRestDetector class.  That tracks the average and variance
of both position and rotation (quaternion logarithms), then
detects when the variance falls under a threshold.

Also, renamed variables with the straighting prefix to straightening.
2015-10-06 20:37:51 -07:00

34 lines
903 B
C++

//
// AtRestDetector.h
// libraries/shared/src
//
// Created by Anthony Thibault on 10/6/2015
// Copyright 2015 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#ifndef hifi_AtRestDetector_h
#define hifi_AtRestDetector_h
#include <glm/glm.hpp>
#include <glm/gtx/quaternion.hpp>
class AtRestDetector {
public:
AtRestDetector(const glm::vec3& startPosition, const glm::quat& startRotation);
void reset(const glm::vec3& startPosition, const glm::quat& startRotation);
// returns true if object is at rest, dt in assumed to be seconds.
bool update(float dt, const glm::vec3& position, const glm::quat& startRotation);
protected:
glm::vec3 _positionAverage;
float _positionVariance;
glm::vec3 _quatLogAverage;
float _quatLogVariance;
};
#endif