7#include <glm/gtc/quaternion.hpp>
22 glm::vec3 position{0.0f};
23 glm::quat rotation{1.0f, 0.0f, 0.0f, 0.0f};
39 void record(uint32_t tick,
const glm::vec3& position,
const glm::quat& rotation) {
61 bool poseAt(
double tick, glm::vec3& position, glm::quat& rotation)
const {
62 if (
count == 0)
return false;
64 if (tick <=
static_cast<double>(
samples[0].tick)) {
70 if (tick >=
static_cast<double>(
newest.tick)) {
71 position =
newest.position;
72 rotation =
newest.rotation;
76 for (
size_t i = 0; i + 1 <
count; ++i) {
77 const Sample& from =
samples[i];
78 const Sample& to =
samples[i + 1];
79 if (tick <
static_cast<double>(from.tick) || tick >
static_cast<double>(to.tick))
continue;
81 const double span =
static_cast<double>(to.tick - from.tick);
82 const float at = span > 0.0
83 ?
static_cast<float>((tick -
static_cast<double>(from.tick)) / span)
85 position = glm::mix(from.position, to.position, at);
87 rotation = glm::slerp(from.rotation, to.rotation, at);
A short history of where one entity was, kept by tick.
Definition sample_track.h:19
void record(uint32_t tick, const glm::vec3 &position, const glm::quat &rotation)
Remember position and rotation as of tick.
Definition sample_track.h:39
Sample samples[N]
Oldest first, newest last; the first count are held.
Definition sample_track.h:26
bool poseAt(double tick, glm::vec3 &position, glm::quat &rotation) const
Where the entity was at tick, which may fall between two samples.
Definition sample_track.h:61
size_t count
Samples held.
Definition sample_track.h:27
uint32_t newest() const
The newest moment remembered, or zero when nothing is.
Definition sample_track.h:94