载入中...
搜索中...
未找到
ControlAnim.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
5#include "common/Time.h"
6
7#include <string>
8#include <unordered_map>
9#include <vector>
10
11namespace eve::animation {
12
26public:
28 ControlAnim(float frequencyHz = 3.f, float dampingZeta = 1.f, float response = 1.f);
30 ~ControlAnim() = default;
31
32 ControlAnim(const ControlAnim &) = delete;
33 ControlAnim &operator=(const ControlAnim &) = delete;
34
36 void setFrequency(float frequencyHz);
38 float getFrequency() const { return frequencyHz_; }
40 void setDamping(float dampingZeta);
42 float getDamping() const { return dampingZeta_; }
44 void setResponse(float response);
46 float getResponse() const { return response_; }
47
49 void setIntegrator(const std::string &kind);
51 std::string getIntegrator() const;
52
54 void set(const std::string &name, float value);
56 void setTarget(const std::string &name, float value);
58 void setTargetVelocity(const std::string &name, float velocity);
60 void impulse(const std::string &name, float deltaVelocity);
61
63 bool has(const std::string &name) const;
65 float get(const std::string &name) const;
67 float getVelocity(const std::string &name) const;
69 float getTarget(const std::string &name) const;
70
72 void clear();
74 void remove(const std::string &name);
76 int getPropertyCount() const { return static_cast<int>(order_.size()); }
78 std::string getPropertyName(int index) const;
79
81 [[nodiscard]] eve::Result<void> advance(const eve::SimulationStep &step);
83 void update(float dt);
84
85private:
86 enum class Integrator { SecondOrder, Spring, Pd };
87
88 struct Channel {
89 float y = 0.f;
90 float yd = 0.f;
91 float x = 0.f;
92 float xp = 0.f;
93 float xdExplicit = 0.f;
94 bool hasXd = false;
95 bool hasPrevX = false;
96 };
97
98 void refreshCoeffs();
99 Channel &ensure(const std::string &name);
100
101 float frequencyHz_ = 3.f;
102 float dampingZeta_ = 1.f;
103 float response_ = 1.f;
104 Integrator integrator_ = Integrator::SecondOrder;
105 SecondOrderCoeffs coeffs_{};
106 float kp_ = 0.f;
107 float kd_ = 0.f;
108
109 std::unordered_map<std::string, Channel> channels_;
110 std::vector<std::string> order_;
112 bool hasLastTick_ = false;
113
114 void updateUnchecked(float dt);
115};
116
117} // namespace eve::animation
double value
float y
Definition AnimClip.cpp:738
float x
Definition AnimClip.cpp:738
#define EVENGINE_API_WORLD
Definition Export.h:109
TokenKind kind
std::string name
Common time values and an injectable deterministic simulation clock.
float step
Definition TreeMesh.cpp:314
uint32_t index
Move-only operation result carrying either a value or Status.
Definition Result.h:155
Control-theory procedural animation for named scalar properties.
Definition ControlAnim.h:25
~ControlAnim()=default
Control anim.
float getResponse() const
Returns the response.
Definition ControlAnim.h:46
ControlAnim(const ControlAnim &)=delete
int getPropertyCount() const
Returns the property count.
Definition ControlAnim.h:76
float getFrequency() const
Returns the frequency.
Definition ControlAnim.h:38
float getDamping() const
Returns the damping.
Definition ControlAnim.h:42
ControlAnim & operator=(const ControlAnim &)=delete
static constexpr StrongUint64 zero() noexcept
Returns the zero value for this strong type.
One deterministic fixed-step emitted by SimulationClock.
Definition Time.h:158