Overte C++ Documentation
AtRestDetector.h
1 //
2 // AtRestDetector.h
3 // libraries/shared/src
4 //
5 // Created by Anthony Thibault on 10/6/2015
6 // Copyright 2015 High Fidelity, Inc.
7 //
8 // Distributed under the Apache License, Version 2.0.
9 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
10 //
11 
12 #ifndef hifi_AtRestDetector_h
13 #define hifi_AtRestDetector_h
14 
15 #include <glm/glm.hpp>
16 #include <glm/gtx/quaternion.hpp>
17 
18 class AtRestDetector {
19 public:
20  AtRestDetector() {};
21  AtRestDetector(const glm::vec3& startPosition, const glm::quat& startRotation);
22  void reset(const glm::vec3& startPosition, const glm::quat& startRotation);
23 
24  // returns true if object is at rest, dt in assumed to be seconds.
25  void update(const glm::vec3& position, const glm::quat& startRotation);
26 
27  void invalidate() { _isValid = false; }
28  bool isAtRest() const { return _isAtRest; }
29  bool onRest() const { return !_lastIsAtRest && _isAtRest; }
30  bool onWake() const { return _lastIsAtRest && !_isAtRest; }
31 
32 protected:
33  bool _isValid { false };
34  glm::vec3 _positionAverage;
35  glm::vec3 _quatLogAverage;
36  uint64_t _lastUpdateTime { 0 };
37  float _positionVariance { 0.0f };
38  float _quatLogVariance { 0.0f };
39  bool _isAtRest { false };
40  bool _lastIsAtRest { false };
41 };
42 
43 #endif