载入中...
搜索中...
未找到
CollapsePlayback.cpp
浏览该文件的文档.
1// eve-hot-path
3#include <new>
6
7namespace eve::physics {
8CollapsePlayback::CollapsePlayback(std::shared_ptr<const CollapseAnimation> animation)
9 : animation_(std::move(animation)) {}
10Result<CollapsePlayback> CollapsePlayback::prepare(CollapseAnimation animation) try {
11 if (animation.frameCount() == 0)
12 return Result<CollapsePlayback>::failure(collapse_detail::invalid("cannot play an empty recording"));
14 CollapsePlayback(std::make_shared<const CollapseAnimation>(std::move(animation))));
15} catch (const std::bad_alloc&) {
17 Diagnostic::error(DiagnosticCode::Failed, "collapse playback allocation failed", "collapsePlayback"));
18}
19Result<void> CollapsePlayback::advance(double seconds) { return clock_.advance(seconds, animation_->duration()); }
20Result<void> CollapsePlayback::seek(double seconds) { return clock_.seek(seconds, animation_->duration()); }
21Result<void> CollapsePlayback::setRate(double rate) { return clock_.setRate(rate); }
22void CollapsePlayback::setPaused(bool paused) noexcept { clock_.setPaused(paused); }
23Result<void> CollapsePlayback::setWrap(CollapsePlaybackWrap wrap) { return clock_.setWrap(wrap); }
24Result<void> CollapsePlayback::setPlacement(CollapsePlacement placement) { return transform_.set(placement); }
25CollapsePlacement CollapsePlayback::placement() const noexcept { return transform_.placement(); }
26double CollapsePlayback::time() const noexcept { return clock_.time(); }
27double CollapsePlayback::rate() const noexcept { return clock_.rate(); }
28bool CollapsePlayback::paused() const noexcept { return clock_.paused(); }
29Result<BonePresentation> CollapsePlayback::sample(int bone) const {
30 auto sampled = animation_->sample(static_cast<float>(clock_.time()), bone);
31 if (!sampled) return sampled;
32 auto pose = sampled.value();
33 auto transformed =
34 transform_.apply({pose.worldX, pose.worldY, pose.worldZ, pose.rotX, pose.rotY, pose.rotZ, pose.rotW});
35 if (!transformed) return Result<BonePresentation>::failure(transformed.status());
36 const auto placed = transformed.value();
37 pose.worldX = placed.x;
38 pose.worldY = placed.y;
39 pose.worldZ = placed.z;
40 pose.rotX = placed.qx;
41 pose.rotY = placed.qy;
42 pose.rotZ = placed.qz;
43 pose.rotW = placed.qw;
45}
46
47std::shared_ptr<const CollapseAnimation> CollapsePlayback::animation() const noexcept { return animation_; }
48} // namespace eve::physics
eve::EntitySpatialPose pose
std::uint32_t bone
Placement placement
bool placed
Move-only operation result carrying either a value or Status.
Definition Result.h:176
Owning, solver-independent baked rigid-fragment animation within Physics. @ownership Owns all samples...
int frameCount() const noexcept
Number of recorded frames.
Independent clock over a frozen, shared collapse animation. @ownership Owns a shared immutable snapsh...
Optional physics backend for vehicle mobility and body attach.
Definition Climbing.h:36
BakePlaybackWrap
Endpoint policy: advances clamp or wrap; explicit seeks always clamp inclusively.
Rotation about the baked origin followed by translation, in the track's explicit units; no scaling.