载入中...
搜索中...
未找到
RigidBakePresentation.cpp
浏览该文件的文档.
1// eve-hot-path
3#include <cmath>
4#include <glm/gtc/matrix_transform.hpp>
5#include <glm/gtc/quaternion.hpp>
6#include <numbers>
10namespace eve::physics {
12 if (player.track().space() != RigidTrackSpace::Metres3D)
14 "3D renderer requires metre-space rigid playback",
15 "rigidBakePresentation"));
16 auto sampled = player.sample(identity);
17 if (!sampled) return Result<void>::failure(sampled.status());
18 const auto pose = sampled.value();
19 auto transform = target.transform();
20 const auto matrix = glm::translate(glm::mat4(1.f), glm::vec3(pose.x, pose.y, pose.z)) *
21 glm::mat4_cast(glm::quat(pose.qw, pose.qx, pose.qy, pose.qz)) *
22 glm::scale(glm::mat4(1.f), glm::vec3(transform->sx, transform->sy, transform->sz));
23 for (int column = 0; column < 4; ++column)
24 for (int row = 0; row < 4; ++row)
25 if (!std::isfinite(matrix[column][row]))
27 DiagnosticCode::InvalidArgument, "rigid renderer matrix is not finite", "rigidBakePresentation"));
28 transform->x = pose.x;
29 transform->y = pose.y;
30 transform->z = pose.z;
31 transform->linkedWorld = matrix;
32 transform->hasLinkedWorld = true;
33 return Result<void>::success();
34}
38 DiagnosticCode::InvalidArgument, "2D renderer requires planar pixel playback", "rigidBakePresentation"));
39 auto sampled = player.sample(identity);
40 if (!sampled) return Result<void>::failure(sampled.status());
41 const auto pose = sampled.value();
42 const float degrees = 2.f * std::atan2(pose.qz, pose.qw) * (180.f / std::numbers::pi_v<float>);
43 auto transform = target.transform();
44 transform->x = pose.x;
45 transform->y = pose.y;
46 transform->rot = degrees;
47 return Result<void>::success();
48}
49} // namespace eve::physics
LogicalId target
eve::EntitySpatialPose pose
float degrees
Definition CardTypes.cpp:38
glm::dmat4 matrix
unsigned column
uint64_t identity
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
Move-only operation result carrying either a value or Status.
Definition Result.h:176
static Result success(T value)
Construct a successful result owning value.
Definition Result.h:185
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:196
Id128 public API.
Definition Identity.h:111
Default renderable entity for declarative 2D sprites / solid quads.
EVENGINE_API_BACKENDS public API.
Independent clock over a frozen rigid track; no solver, world, renderer or wall clock....
Result< RigidTrackPose > sample(PersistentId id) const
Sample one persistent identity at this player's current time.
RigidPoseTrack track() const
Return a cheap owning copy of the immutable track, valid after player destruction.
RigidTrackSpace space() const noexcept
Coordinate contract of every pose in this track.
Optional physics backend for vehicle mobility and body attach.
Definition Climbing.h:36
Result< void > submitRigidPlayback(const RigidPlayback &player, PersistentId identity, graphics::Renderable3D &target)
Sample a metre-space rigid player into a live renderer's world matrix, preserving mesh scale....