mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-25 21:35:04 +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>
|
#include <glm/gtx/quaternion.hpp>
|
||||||
|
|
||||||
glm::quat RotationAccumulator::getAverage() {
|
void RotationAccumulator::add(glm::quat rotation) {
|
||||||
glm::quat average;
|
if (_numRotations == 0) {
|
||||||
uint32_t numRotations = _rotations.size();
|
_rotationSum = rotation;
|
||||||
if (numRotations > 0) {
|
} else {
|
||||||
average = _rotations[0];
|
if (glm::dot(_rotationSum, rotation) < 0.0f) {
|
||||||
for (uint32_t i = 1; i < numRotations; ++i) {
|
rotation = -rotation;
|
||||||
glm::quat rotation = _rotations[i];
|
|
||||||
if (glm::dot(average, rotation) < 0.0f) {
|
|
||||||
rotation = -rotation;
|
|
||||||
}
|
|
||||||
average += 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
|
#ifndef hifi_RotationAccumulator_h
|
||||||
#define hifi_RotationAccumulator_h
|
#define hifi_RotationAccumulator_h
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include <glm/gtc/quaternion.hpp>
|
#include <glm/gtc/quaternion.hpp>
|
||||||
#include <glm/gtx/quaternion.hpp>
|
|
||||||
|
|
||||||
class RotationAccumulator {
|
class RotationAccumulator {
|
||||||
public:
|
public:
|
||||||
RotationAccumulator() {}
|
int size() const { return _numRotations; }
|
||||||
|
|
||||||
uint32_t size() const { return _rotations.size(); }
|
void add(glm::quat rotation);
|
||||||
|
|
||||||
void add(const glm::quat& rotation) { _rotations.push_back(rotation); }
|
|
||||||
|
|
||||||
glm::quat getAverage();
|
glm::quat getAverage();
|
||||||
|
|
||||||
void clear() { _rotations.clear(); }
|
void clear() { _numRotations = 0; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<glm::quat> _rotations;
|
glm::quat _rotationSum;
|
||||||
|
int _numRotations = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_RotationAccumulator_h
|
#endif // hifi_RotationAccumulator_h
|
||||||
|
|
Loading…
Reference in a new issue