Overte C++ Documentation
AnimBlendLinearMove.h
1 //
2 // AnimBlendLinearMove.h
3 //
4 // Created by Anthony J. Thibault on 10/22/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_AnimBlendLinearMove_h
12 #define hifi_AnimBlendLinearMove_h
13 
14 #include "AnimNode.h"
15 
16 // Synced linear blend between two AnimNodes, where the playback speed of
17 // the animation is timeScaled to match movement speed.
18 //
19 // Each child animation is associated with a chracteristic speed.
20 // This defines the speed of that animation when played at the normal playback rate, 30 frames per second.
21 //
22 // The user also specifies a desired speed. This desired speed is used to timescale
23 // the animation to achive the desired movement velocity.
24 //
25 // Blending is determined by the alpha parameter.
26 // If the number of children is 2, then the alpha parameters should be between
27 // 0 and 1. The first animation will have a (1 - alpha) factor, and the second
28 // will have factor of alpha.
29 //
30 // This node supports more then 2 children. In this case the alpha should be
31 // between 0 and n - 1. This alpha can be used to linearly interpolate between
32 // the closest two children poses. This can be used to sweep through a series
33 // of animation poses.
34 
35 class AnimBlendLinearMove : public AnimNode {
36 public:
37  friend class AnimTests;
38 
39  AnimBlendLinearMove(const QString& id, float alpha, float desiredSpeed, const std::vector<float>& characteristicSpeeds);
40  virtual ~AnimBlendLinearMove() override;
41 
42  virtual const AnimPoseVec& evaluate(const AnimVariantMap& animVars, const AnimContext& context, float dt, AnimVariantMap& triggersOut) override;
43 
44  void setAlphaVar(const QString& alphaVar) { _alphaVar = alphaVar; }
45  void setDesiredSpeedVar(const QString& desiredSpeedVar) { _desiredSpeedVar = desiredSpeedVar; }
46 
47 protected:
48  // for AnimDebugDraw rendering
49  virtual const AnimPoseVec& getPosesInternal() const override;
50 
51  void evaluateAndBlendChildren(const AnimVariantMap& animVars, const AnimContext& context, AnimVariantMap& triggersOut, float alpha,
52  size_t prevPoseIndex, size_t nextPoseIndex,
53  float prevDeltaTime, float nextDeltaTime);
54 
55  void setFrameAndPhase(float dt, float alpha, int prevPoseIndex, int nextPoseIndex,
56  float* prevDeltaTimeOut, float* nextDeltaTimeOut, AnimVariantMap& triggersOut);
57 
58  virtual void setCurrentFrameInternal(float frame) override;
59 
60  AnimPoseVec _poses;
61 
62  float _alpha;
63  float _desiredSpeed;
64 
65  float _phase = 0.0f;
66 
67  QString _alphaVar;
68  QString _desiredSpeedVar;
69 
70  std::vector<float> _characteristicSpeeds;
71 
72  // no copies
73  AnimBlendLinearMove(const AnimBlendLinearMove&) = delete;
74  AnimBlendLinearMove& operator=(const AnimBlendLinearMove&) = delete;
75 };
76 
77 #endif // hifi_AnimBlendLinearMove_h