mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 11:45:36 +02:00
split RotationAccumulator into its own files
This commit is contained in:
parent
420acde720
commit
b6a153d926
3 changed files with 68 additions and 31 deletions
|
@ -12,41 +12,15 @@
|
|||
|
||||
#include <string>
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
#include "AnimNode.h"
|
||||
|
||||
#include "RotationAccumulator.h"
|
||||
|
||||
class RotationConstraint;
|
||||
|
||||
class RotationAccumulator {
|
||||
public:
|
||||
RotationAccumulator() {}
|
||||
|
||||
uint32_t size() const { return _rotations.size(); }
|
||||
|
||||
void add(const glm::quat& rotation) { _rotations.push_back(rotation); }
|
||||
|
||||
glm::quat 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;
|
||||
}
|
||||
average = glm::normalize(average);
|
||||
}
|
||||
return average;
|
||||
}
|
||||
|
||||
void clear() { _rotations.clear(); }
|
||||
|
||||
private:
|
||||
std::vector<glm::quat> _rotations;
|
||||
};
|
||||
|
||||
class AnimInverseKinematics : public AnimNode {
|
||||
public:
|
||||
|
||||
|
|
29
libraries/animation/src/RotationAccumulator.cpp
Normal file
29
libraries/animation/src/RotationAccumulator.cpp
Normal file
|
@ -0,0 +1,29 @@
|
|||
//
|
||||
// RotationAccumulator.h
|
||||
//
|
||||
// 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
|
||||
//
|
||||
|
||||
#include "RotationAccumulator.h"
|
||||
|
||||
#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;
|
||||
}
|
||||
average = glm::normalize(average);
|
||||
}
|
||||
return average;
|
||||
}
|
34
libraries/animation/src/RotationAccumulator.h
Normal file
34
libraries/animation/src/RotationAccumulator.h
Normal file
|
@ -0,0 +1,34 @@
|
|||
//
|
||||
// RotationAccumulator.h
|
||||
//
|
||||
// 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_RotationAccumulator_h
|
||||
#define hifi_RotationAccumulator_h
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
#include <glm/gtx/quaternion.hpp>
|
||||
|
||||
class RotationAccumulator {
|
||||
public:
|
||||
RotationAccumulator() {}
|
||||
|
||||
uint32_t size() const { return _rotations.size(); }
|
||||
|
||||
void add(const glm::quat& rotation) { _rotations.push_back(rotation); }
|
||||
|
||||
glm::quat getAverage();
|
||||
|
||||
void clear() { _rotations.clear(); }
|
||||
|
||||
private:
|
||||
std::vector<glm::quat> _rotations;
|
||||
};
|
||||
|
||||
#endif // hifi_RotationAccumulator_h
|
Loading…
Reference in a new issue