Overte C++ Documentation
AnimPose.h
1 //
2 // AnimPose.h
3 //
4 // Created by Anthony J. Thibault on 10/14/15.
5 // Copyright (c) 2015 High Fidelity, Inc. All rights reserved.
6 //
7 // Distributed under the Apache License, Version 2.0.
8 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
9 //
10 
11 #ifndef hifi_AnimPose
12 #define hifi_AnimPose
13 
14 #include <QtGlobal>
15 #include <QDebug>
16 #include <vector>
17 #include <glm/glm.hpp>
18 #include <glm/gtc/quaternion.hpp>
19 
20 class AnimPose {
21 public:
22  AnimPose() {}
23  explicit AnimPose(const glm::mat4& mat);
24 
25  explicit AnimPose(const glm::quat& rotIn) : _scale(1.0f), _rot(rotIn), _trans(0.0f) {}
26  AnimPose(const glm::quat& rotIn, const glm::vec3& transIn) : _scale(1.0f), _rot(rotIn), _trans(transIn) {}
27  AnimPose(const glm::vec3& scaleIn, const glm::quat& rotIn, const glm::vec3& transIn) : _scale(scaleIn), _rot(rotIn), _trans(transIn) {}
28 
29  static const AnimPose identity;
30 
31  glm::vec3 xformPoint(const glm::vec3& rhs) const;
32  glm::vec3 xformVector(const glm::vec3& rhs) const; // really slow, but accurate for transforms with non-uniform scale
33  glm::vec3 xformVectorFast(const glm::vec3& rhs) const; // faster, but does not handle non-uniform scale correctly.
34 
35  glm::vec3 operator*(const glm::vec3& rhs) const; // same as xformPoint
36  AnimPose operator*(const AnimPose& rhs) const;
37 
38  AnimPose inverse() const;
39  AnimPose mirror() const;
40  operator glm::mat4() const;
41 
42  const glm::vec3& scale() const { return _scale; }
43  glm::vec3& scale() { return _scale; }
44 
45  const glm::quat& rot() const { return _rot; }
46  glm::quat& rot() { return _rot; }
47 
48  const glm::vec3& trans() const { return _trans; }
49  glm::vec3& trans() { return _trans; }
50 
51  void blend(const AnimPose& srcPose, float alpha);
52 
53 private:
54  friend QDebug operator<<(QDebug debug, const AnimPose& pose);
55  glm::vec3 _scale { 1.0f };
56  glm::quat _rot;
57  glm::vec3 _trans;
58 };
59 
60 inline QDebug operator<<(QDebug debug, const AnimPose& pose) {
61  debug << "AnimPose, trans = (" << pose.trans().x << pose.trans().y << pose.trans().z << "), rot = (" << pose.rot().x << pose.rot().y << pose.rot().z << pose.rot().w << "), scale = (" << pose.scale().x << pose.scale().y << pose.scale().z << ")";
62  return debug;
63 }
64 
65 using AnimPoseVec = std::vector<AnimPose>;
66 
67 #endif