JFLib

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 Transform a 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 1

  • const fn at(pos: Vec3) -> Transform at pos, not rotated, scale 1

  • const fn new(pos: Vec3, rot: Quat) -> Transform at pos with rotation rot, scale 1

  • const fn scaled(self, scale: [f32; 3]) -> Transform the same with another scale

  • fn lerp(&self, b: &Transform, t: f64) -> Transform the 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 exactly

  • fn nlerp(a: Quat, b: Quat, t: f64) -> Quat the 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 normalisation

  • struct Pose where 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 draws

    • now: Transform -- the state the systems write
    • prev: Transform -- the state at the start of the tick (World::begin_tick sets it from now)

impl Pose

  • const fn new(t: Transform) -> Pose standing at t (prev = now)
  • const fn at(pos: Vec3) -> Pose standing at pos, not rotated
  • fn teleport(&mut self, t: Transform) a jump to t without the frames in between (prev = now = t)
  • fn moving(&self) -> bool now differs from prev: frames show it between the two
  • fn interpolate(&self, alpha: f64) -> Transform the state a frame shows at alpha (FixedTick::alpha: 0 at the start of the tick, towards 1 at its end): prev.lerp(now, alpha)

Source: docs/API.md in the JFLib repository.