mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-25 17:14:59 +02:00
less complicated RotationAccumulator
This commit is contained in:
parent
b6a153d926
commit
9e94e7f1d0
2 changed files with 17 additions and 22 deletions
|
@ -11,19 +11,18 @@
|
|||
|
||||
#include <glm/gtx/quaternion.hpp>
|
||||
|
||||
glm::quat RotationAccumulator::getAverage() {
|
||||
glm::quat average;
|
||||
uint32_t numRotations = _rotations.size();
|
||||
if (numRotations > 0) {
|
||||
average = _rotations[0];
|
||||
for (uint32_t i = 1; i < numRotations; ++i) {
|
||||
glm::quat rotation = _rotations[i];
|
||||
if (glm::dot(average, rotation) < 0.0f) {
|
||||
rotation = -rotation;
|
||||
}
|
||||
average += rotation;
|
||||
void RotationAccumulator::add(glm::quat rotation) {
|
||||
if (_numRotations == 0) {
|
||||
_rotationSum = rotation;
|
||||
} else {
|
||||
if (glm::dot(_rotationSum, rotation) < 0.0f) {
|
||||
rotation = -rotation;
|
||||
}
|
||||
average = glm::normalize(average);
|
||||
_rotationSum += rotation;
|
||||
}
|
||||
return average;
|
||||
++_numRotations;
|
||||
}
|
||||
|
||||
glm::quat RotationAccumulator::getAverage() {
|
||||
return (_numRotations > 0) ? glm::normalize(_rotationSum) : glm::quat();
|
||||
}
|
||||
|
|
|
@ -10,25 +10,21 @@
|
|||
#ifndef hifi_RotationAccumulator_h
|
||||
#define hifi_RotationAccumulator_h
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
#include <glm/gtx/quaternion.hpp>
|
||||
|
||||
class RotationAccumulator {
|
||||
public:
|
||||
RotationAccumulator() {}
|
||||
int size() const { return _numRotations; }
|
||||
|
||||
uint32_t size() const { return _rotations.size(); }
|
||||
|
||||
void add(const glm::quat& rotation) { _rotations.push_back(rotation); }
|
||||
void add(glm::quat rotation);
|
||||
|
||||
glm::quat getAverage();
|
||||
|
||||
void clear() { _rotations.clear(); }
|
||||
void clear() { _numRotations = 0; }
|
||||
|
||||
private:
|
||||
std::vector<glm::quat> _rotations;
|
||||
glm::quat _rotationSum;
|
||||
int _numRotations = 0;
|
||||
};
|
||||
|
||||
#endif // hifi_RotationAccumulator_h
|
||||
|
|
Loading…
Reference in a new issue