split RotationAccumulator into its own files

This commit is contained in:
Andrew Meadows 2015-09-17 22:30:44 -07:00
parent 420acde720
commit b6a153d926
3 changed files with 68 additions and 31 deletions

View file

@ -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:

View 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;
}

View 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