载入中...
搜索中...
未找到
ControlAnim.h
浏览该文件的文档.
1#pragma once
2
4
5#include <string>
6#include <unordered_map>
7#include <vector>
8
9namespace eve::animation {
10
24public:
25 ControlAnim(float frequencyHz = 3.f, float dampingZeta = 1.f, float response = 1.f);
26 ~ControlAnim() = default;
27
28 ControlAnim(const ControlAnim &) = delete;
29 ControlAnim &operator=(const ControlAnim &) = delete;
30
31 void setFrequency(float frequencyHz);
32 float getFrequency() const { return frequencyHz_; }
33 void setDamping(float dampingZeta);
34 float getDamping() const { return dampingZeta_; }
35 void setResponse(float response);
36 float getResponse() const { return response_; }
37
39 void setIntegrator(const std::string &kind);
40 std::string getIntegrator() const;
41
43 void set(const std::string &name, float value);
45 void setTarget(const std::string &name, float value);
47 void setTargetVelocity(const std::string &name, float velocity);
49 void impulse(const std::string &name, float deltaVelocity);
50
51 bool has(const std::string &name) const;
52 float get(const std::string &name) const;
53 float getVelocity(const std::string &name) const;
54 float getTarget(const std::string &name) const;
55
56 void clear();
57 void remove(const std::string &name);
58 int getPropertyCount() const { return static_cast<int>(order_.size()); }
59 std::string getPropertyName(int index) const;
60
62 void update(float dt);
63
64private:
65 enum class Integrator { SecondOrder, Spring, Pd };
66
67 struct Channel {
68 float y = 0.f;
69 float yd = 0.f;
70 float x = 0.f;
71 float xp = 0.f;
72 float xdExplicit = 0.f;
73 bool hasXd = false;
74 bool hasPrevX = false;
75 };
76
77 void refreshCoeffs();
78 Channel &ensure(const std::string &name);
79
80 float frequencyHz_ = 3.f;
81 float dampingZeta_ = 1.f;
82 float response_ = 1.f;
83 Integrator integrator_ = Integrator::SecondOrder;
84 SecondOrderCoeffs coeffs_{};
85 float kp_ = 0.f;
86 float kd_ = 0.f;
87
88 std::unordered_map<std::string, Channel> channels_;
89 std::vector<std::string> order_;
90};
91
92} // namespace eve::animation
Tok kind
std::string value
int y
Definition Grass.cpp:135
int x
Definition Grass.cpp:135
const char * name
Definition RockMesh.cpp:21
Control-theory procedural animation for named scalar properties.
Definition ControlAnim.h:23
float getVelocity(const std::string &name) const
void remove(const std::string &name)
void set(const std::string &name, float value)
Create/update a channel: current value snaps to value, velocity cleared.
ControlAnim(const ControlAnim &)=delete
void setTarget(const std::string &name, float value)
Move the tracking target (does not snap state). Creates channel if missing.
float get(const std::string &name) const
void setDamping(float dampingZeta)
void setFrequency(float frequencyHz)
bool has(const std::string &name) const
float getTarget(const std::string &name) const
void setResponse(float response)
std::string getIntegrator() const
std::string getPropertyName(int index) const
void setIntegrator(const std::string &kind)
Integrator: "secondOrder" | "spring" | "pd". Invalid → exception.
void update(float dt)
Advance all channels by dt seconds.
void setTargetVelocity(const std::string &name, float velocity)
Optional explicit target velocity (used by secondOrder / pd).
void impulse(const std::string &name, float deltaVelocity)
Inject an instantaneous velocity impulse (procedural “hit”).
ControlAnim & operator=(const ControlAnim &)=delete