载入中...
搜索中...
未找到
PhysicalBalancePose.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
5#include "common/Result.h"
6#include "common/Time.h"
7
8#include <vector>
9
10namespace eve::animation {
11
12class AnimSkeleton;
13
31public:
37 explicit PhysicalBalancePose(AnimSkeleton* skeleton);
40
43
49 [[nodiscard]] AnimSkeleton* getSkeleton() const;
50
55 [[nodiscard]] eve::Result<void> setSupportBone(int boneIndex);
56 [[nodiscard]] int getSupportBone() const;
57
62 [[nodiscard]] eve::Result<void> setBalanceBone(int boneIndex);
63 [[nodiscard]] int getBalanceBone() const;
64
69 [[nodiscard]] eve::Result<void> setBoneMass(int boneIndex, float mass);
70 [[nodiscard]] float getBoneMass(int boneIndex) const;
71
77 [[nodiscard]] eve::Result<void> setRecovery(float frequencyHz, float dampingZeta);
78 [[nodiscard]] float getRecoveryFrequency() const;
79 [[nodiscard]] float getRecoveryDamping() const;
80
84 [[nodiscard]] eve::Result<void> setRecoil(float frequencyHz, float dampingZeta);
85 [[nodiscard]] float getRecoilFrequency() const;
86 [[nodiscard]] float getRecoilDamping() const;
87
89 [[nodiscard]] eve::Result<void> setGravity(float metersPerSecondSquared);
90 [[nodiscard]] float getGravity() const;
91
93 [[nodiscard]] eve::Result<void> setPendulumHeight(float meters);
94 [[nodiscard]] float getPendulumHeight() const;
95
97 [[nodiscard]] eve::Result<void> setInertia(float inertia);
98 [[nodiscard]] float getInertia() const;
99
101 [[nodiscard]] eve::Result<void> setRecoilInertia(float inertia);
102 [[nodiscard]] float getRecoilInertia() const;
103
105 [[nodiscard]] eve::Result<void> setMaxLean(float radians);
106 [[nodiscard]] float getMaxLean() const;
107
113 [[nodiscard]] eve::Result<void> setTargetPose(const AnimPose* target);
114
116 [[nodiscard]] eve::Result<void> snapToTarget();
117
125 [[nodiscard]] eve::Result<void> applyImpulse(int boneIndex, float impulseX, float impulseY, float impulseZ,
126 float pointX, float pointY, float pointZ);
127
132 [[nodiscard]] eve::Result<void> advance(const eve::SimulationStep& step);
134 void update(float dt);
135
141 [[nodiscard]] AnimPose* getPose();
147 [[nodiscard]] AnimPose* getTargetPose();
148
149 [[nodiscard]] float getLeanX() const;
150 [[nodiscard]] float getLeanZ() const;
151 [[nodiscard]] float getLeanVelocityX() const;
152 [[nodiscard]] float getLeanVelocityZ() const;
153 [[nodiscard]] float getCenterOfMassX() const;
154 [[nodiscard]] float getCenterOfMassY() const;
155 [[nodiscard]] float getCenterOfMassZ() const;
156 [[nodiscard]] float getSupportX() const;
157 [[nodiscard]] float getSupportY() const;
158 [[nodiscard]] float getSupportZ() const;
159
160private:
161 struct Recoil {
162 float x = 0.f, y = 0.f, z = 0.f;
163 float vx = 0.f, vy = 0.f, vz = 0.f;
164 float pendingTx = 0.f, pendingTy = 0.f, pendingTz = 0.f;
165 };
166
167 void ensureBones();
168 void resetDynamics();
169 void writeOverlayPose();
170 void refreshDiagnostics();
171 void updateUnchecked(float dt);
172 [[nodiscard]] bool boneInRange(int boneIndex) const;
173 [[nodiscard]] eve::Result<void> requireFinitePositive(const char* name, float value, bool allowZero);
174
175 AnimSkeleton* skeleton_ = nullptr;
176 AnimPose pose_;
177 AnimPose target_;
178
179 int supportBone_ = 0;
180 int balanceBone_ = 0;
181 float recoveryHz_ = 2.f;
182 float recoveryZeta_ = 0.45f;
183 float recoilHz_ = 4.f;
184 float recoilZeta_ = 0.5f;
185 float gravity_ = 9.81f;
186 float pendulumHeight_ = 1.f;
187 float inertia_ = 1.f;
188 float recoilInertia_ = 0.15f;
189 float maxLean_ = 0.7f;
190
191 float leanX_ = 0.f, leanZ_ = 0.f;
192 float leanVelX_ = 0.f, leanVelZ_ = 0.f;
193 float pendingLeanTx_ = 0.f, pendingLeanTz_ = 0.f;
194
195 float comX_ = 0.f, comY_ = 0.f, comZ_ = 0.f;
196 float supportX_ = 0.f, supportY_ = 0.f, supportZ_ = 0.f;
197
198 std::vector<float> masses_;
199 std::vector<Recoil> recoils_;
200 bool hasTarget_ = false;
202 bool hasLastTick_ = false;
203};
204
205} // namespace eve::animation
LogicalId target
double value
float y
Definition AnimClip.cpp:738
float x
Definition AnimClip.cpp:738
float z
Definition AnimClip.cpp:738
#define EVENGINE_API_WORLD
Definition Export.h:109
std::string name
Move-only, checked operation results for the common layer.
Common time values and an injectable deterministic simulation clock.
float inertia
Definition TreeMesh.cpp:309
float step
Definition TreeMesh.cpp:314
float vz
float vy
float vx
Move-only operation result carrying either a value or Status.
Definition Result.h:155
Evaluated local (and optional world) pose for an AnimSkeleton. Script type: AnimPose.
Definition AnimPose.h:17
3D bone hierarchy + bind-pose local TRS for skeletal animation. Independent of ik::Skeleton3D (FABRIK...
Authored-pose overlay that wobbles from world impulses and recovers balance.
PhysicalBalancePose & operator=(const PhysicalBalancePose &)=delete
~PhysicalBalancePose()=default
Physical balance pose.
PhysicalBalancePose(const PhysicalBalancePose &)=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