Overte C++ Documentation
AnimTwoBoneIK.h
1 //
2 // AnimTwoBoneIK.h
3 //
4 // Created by Anthony J. Thibault on 5/12/18.
5 // Copyright (c) 2018 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_AnimTwoBoneIK_h
12 #define hifi_AnimTwoBoneIK_h
13 
14 #include "AnimNode.h"
15 #include "AnimChain.h"
16 
17 // Simple two bone IK chain
18 class AnimTwoBoneIK : public AnimNode {
19 public:
20  friend class AnimTests;
21 
22  AnimTwoBoneIK(const QString& id, float alpha, bool enabled, float interpDuration,
23  const QString& baseJointName, const QString& midJointName,
24  const QString& tipJointName, const glm::vec3& midHingeAxis,
25  const QString& alphaVar, const QString& enabledVar,
26  const QString& endEffectorRotationVarVar, const QString& endEffectorPositionVarVar);
27  virtual ~AnimTwoBoneIK() override;
28 
29  virtual const AnimPoseVec& evaluate(const AnimVariantMap& animVars, const AnimContext& context, float dt, AnimVariantMap& triggersOut) override;
30 
31 protected:
32 
33  enum class InterpType {
34  None = 0,
35  SnapshotToUnderPoses,
36  SnapshotToSolve,
37  NumTypes
38  };
39 
40  // for AnimDebugDraw rendering
41  virtual const AnimPoseVec& getPosesInternal() const override;
42  virtual void setSkeletonInternal(AnimSkeleton::ConstPointer skeleton) override;
43 
44  void lookUpIndices();
45  void beginInterp(InterpType interpType, const AnimChain& chain);
46 
47  AnimPoseVec _poses;
48 
49  float _alpha;
50  bool _enabled;
51  float _interpDuration; // in frames (1/30 sec)
52  QString _baseJointName;
53  QString _midJointName;
54  QString _tipJointName;
55  glm::vec3 _midHingeAxis; // in baseJoint relative frame, should be normalized
56 
57  int _baseParentJointIndex { -1 };
58  int _baseJointIndex { -1 };
59  int _midJointIndex { -1 };
60  int _tipJointIndex { -1 };
61 
62  QString _alphaVar; // float - (0, 1) 0 means underPoses only, 1 means IK only.
63  QString _enabledVar; // bool
64  QString _endEffectorRotationVarVar; // string
65  QString _endEffectorPositionVarVar; // string
66 
67  QString _prevEndEffectorRotationVar;
68  QString _prevEndEffectorPositionVar;
69 
70  InterpType _interpType { InterpType::None };
71  float _interpAlphaVel { 0.0f };
72  float _interpAlpha { 0.0f };
73 
74  AnimChain _snapshotChain;
75 
76  bool _lastEnableDebugDrawIKTargets { false };
77 
78  // no copies
79  AnimTwoBoneIK(const AnimTwoBoneIK&) = delete;
80  AnimTwoBoneIK& operator=(const AnimTwoBoneIK&) = delete;
81 };
82 
83 #endif // hifi_AnimTwoBoneIK_h