game/src/pose.rs#
Source: lib/game/src/pose.rs
pose -- where an entity is: position (f64), rotation, scale; now and at the end of the tick before,
so that a frame between two ticks shows a state between the two
Transform pos (Vec3, f64 as in render3d), rot (Quat, x y z w), scale ([f32; 3] as in
render3d); lerp: positions and scales straight, rotations by nlerp
Pose now (what the systems write) and prev (the state when the tick began);
interpolate(alpha) for a frame, teleport for a jump without the in-between
nlerp(a, b, t) the normalised straight blend of two rotations on the shorter way
The world settles the poses at every tick (World::begin_tick -> settle): a pose written in the tick
before gets prev = now. Only the poses with a newer version than the mark of the tick before are
touched, so a world of standing things costs a scan of their versions. Everything is + - * / and the
correctly rounded square root of lib/physics: the same bits on every target.
struct Transforma placement: rotate (rot), scale (scale, along the rotated axes), move (pos)pos: Vec3-- the position in the world (metres)rot: Quat-- the rotation, a unit quaternion (x, y, z, w)scale: [f32; 3]-- the scale per axis (render3d's; negative values mirror)
impl Transform
const IDENTITY: Transform = Transform { pos: Vec3::ZERO, rot: Quat::IDENTITY, scale: ...at the origin, not rotated, scale 1const fn at(pos: Vec3) -> Transformat pos, not rotated, scale 1const fn new(pos: Vec3, rot: Quat) -> Transformat pos with rotation rot, scale 1const fn scaled(self, scale: [f32; 3]) -> Transformthe same with another scalefn lerp(&self, b: &Transform, t: f64) -> Transformthe state t of the way from self (0) to b (1): positions and scales straight, the rotation by nlerp; t = 0 and t = 1 give self and b exactlyfn nlerp(a: Quat, b: Quat, t: f64) -> Quatthe straight blend of two unit quaternions, normalised, on the shorter of the two ways (b's sign flipped when a . b < 0); t = 0 and 1 give a and b (or -b) exactly up to the normalisationstruct Posewhere an entity is now and where it was when the tick began: the component the world interpolates (World::begin_tick) and the bridge to render3d drawsnow: Transform-- the state the systems writeprev: Transform-- the state at the start of the tick (World::begin_tick sets it from now)
impl Pose
const fn new(t: Transform) -> Posestanding at t (prev = now)const fn at(pos: Vec3) -> Posestanding at pos, not rotatedfn teleport(&mut self, t: Transform)a jump to t without the frames in between (prev = now = t)fn moving(&self) -> boolnow differs from prev: frames show it between the twofn interpolate(&self, alpha: f64) -> Transformthe state a frame shows at alpha (FixedTick::alpha: 0 at the start of the tick, towards 1 at its end): prev.lerp(now, alpha)