Overte C++ Documentation
AnimContext.h
1 //
2 // AnimContext.h
3 //
4 // Created by Anthony J. Thibault on 9/19/16.
5 // Copyright (c) 2016 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_AnimContext_h
12 #define hifi_AnimContext_h
13 
14 #include <glm/glm.hpp>
15 #include <glm/gtc/quaternion.hpp>
16 
17 #include <QString>
18 #include <QStringList>
19 #include <map>
20 
21 enum class AnimNodeType {
22  Clip = 0,
23  BlendLinear,
24  BlendLinearMove,
25  Overlay,
26  StateMachine,
27  RandomSwitchStateMachine,
28  Manipulator,
29  InverseKinematics,
30  DefaultPose,
31  TwoBoneIK,
32  SplineIK,
33  PoleVectorConstraint,
34  BlendDirectional,
35  NumTypes
36 };
37 
38 enum AnimBlendType {
39  AnimBlendType_Normal,
40  AnimBlendType_AddRelative,
41  AnimBlendType_AddAbsolute,
42  AnimBlendType_NumTypes
43 };
44 
45 class AnimContext {
46 public:
47  AnimContext() {}
48  AnimContext(bool enableDebugDrawIKTargets, bool enableDebugDrawIKConstraints, bool enableDebugDrawIKChains,
49  const glm::mat4& geometryToRigMatrix, const glm::mat4& rigToWorldMatrix, int evaluationCount);
50 
51  bool getEnableDebugDrawIKTargets() const { return _enableDebugDrawIKTargets; }
52  bool getEnableDebugDrawIKConstraints() const { return _enableDebugDrawIKConstraints; }
53  bool getEnableDebugDrawIKChains() const { return _enableDebugDrawIKChains; }
54  const glm::mat4& getGeometryToRigMatrix() const { return _geometryToRigMatrix; }
55  const glm::mat4& getRigToWorldMatrix() const { return _rigToWorldMatrix; }
56  int getEvaluationCount() const { return _evaluationCount; }
57 
58  float getDebugAlpha(const QString& key) const {
59  auto it = _debugAlphaMap.find(key);
60  if (it != _debugAlphaMap.end()) {
61  return std::get<0>(it->second);
62  } else {
63  return 1.0f;
64  }
65  }
66 
67  using DebugAlphaMapValue = std::tuple<float, AnimNodeType>;
68  using DebugAlphaMap = std::map<QString, DebugAlphaMapValue>;
69 
70  void setDebugAlpha(const QString& key, float alpha, AnimNodeType type) const {
71  _debugAlphaMap[key] = DebugAlphaMapValue(alpha, type);
72  }
73 
74  const DebugAlphaMap& getDebugAlphaMap() const {
75  return _debugAlphaMap;
76  }
77 
78  using DebugStateMachineMapValue = QString;
79  using DebugStateMachineMap = std::map<QString, DebugStateMachineMapValue>;
80 
81  void addStateMachineInfo(const QString& stateMachineName, const QString& currentState, const QString& previousState, bool duringInterp, float alpha) const {
82  if (duringInterp) {
83  _stateMachineMap[stateMachineName] = QString("%1: %2 -> %3 (%4)").arg(stateMachineName).arg(previousState).arg(currentState).arg(QString::number(alpha, 'f', 2));
84  } else {
85  _stateMachineMap[stateMachineName] = QString("%1: %2").arg(stateMachineName).arg(currentState);
86  }
87  }
88 
89  const DebugStateMachineMap& getStateMachineMap() const { return _stateMachineMap; }
90 
91 protected:
92 
93  bool _enableDebugDrawIKTargets { false };
94  bool _enableDebugDrawIKConstraints { false };
95  bool _enableDebugDrawIKChains { false };
96  glm::mat4 _geometryToRigMatrix;
97  glm::mat4 _rigToWorldMatrix;
98  int _evaluationCount{ 0 };
99 
100  // used for debugging internal state of animation system.
101  mutable DebugAlphaMap _debugAlphaMap;
102  mutable DebugStateMachineMap _stateMachineMap;
103 };
104 
105 #endif // hifi_AnimContext_h