simplify logic of RotationAccumulator::add()

This commit is contained in:
Andrew Meadows 2015-09-18 10:13:21 -07:00
parent 6ed0a57d9f
commit a85afb5280
2 changed files with 8 additions and 8 deletions

View file

@ -12,14 +12,12 @@
#include <glm/gtx/quaternion.hpp> #include <glm/gtx/quaternion.hpp>
void RotationAccumulator::add(glm::quat rotation) { void RotationAccumulator::add(glm::quat rotation) {
if (_numRotations == 0) { // make sure both quaternions are on the same hyper-hemisphere before we add them
_rotationSum = rotation;
} else {
if (glm::dot(_rotationSum, rotation) < 0.0f) { if (glm::dot(_rotationSum, rotation) < 0.0f) {
rotation = -rotation; rotation = -rotation;
} }
// sum the rotation linearly (lerp)
_rotationSum += rotation; _rotationSum += rotation;
}
++_numRotations; ++_numRotations;
} }

View file

@ -14,6 +14,8 @@
class RotationAccumulator { class RotationAccumulator {
public: public:
RotationAccumulator() : _rotationSum(0.0f, 0.0f, 0.0f, 0.0f), _numRotations(0) { }
int size() const { return _numRotations; } int size() const { return _numRotations; }
void add(glm::quat rotation); void add(glm::quat rotation);
@ -24,7 +26,7 @@ public:
private: private:
glm::quat _rotationSum; glm::quat _rotationSum;
int _numRotations = 0; int _numRotations;
}; };
#endif // hifi_RotationAccumulator_h #endif // hifi_RotationAccumulator_h