Moving a box through a world: sliding along what it hits, and stepping up ledges.
Every function takes trace, fn from, to -> Cauldron3D.Hull.Trace.t() end, which
says how far the box gets along a straight line; the caller decides what it collides
with.
Cauldron3D.Move.slide(trace, origin, velocity, 1 / 72)
#=> %{origin: ..., velocity: ..., blocked: [:floor], hits: [trace, ...]}
Summary
Functions
velocity with the part going into a plane of normal taken out, overbounce times
over (1.0 slides along it, more than 1.0 bounces off). Components smaller than 0.1 come
out as zero.
Move for seconds at velocity, sliding along up to four surfaces. A hit plane whose
normal points up more than :floor (default 0.7) blocks as a floor; an upright one as
a wall. The velocity is stopped when it would turn back on itself or is pinned in a
corner.
Types
@type result() :: %{ origin: Cauldron3D.Vec.t(), velocity: Cauldron3D.Vec.t(), blocked: [:floor | :wall], hits: [Cauldron3D.Hull.Trace.t()] }
@type tracer() :: (Cauldron3D.Vec.t(), Cauldron3D.Vec.t() -> Cauldron3D.Hull.Trace.t())
Functions
@spec clip(Cauldron3D.Vec.t(), Cauldron3D.Vec.t(), number()) :: Cauldron3D.Vec.t()
velocity with the part going into a plane of normal taken out, overbounce times
over (1.0 slides along it, more than 1.0 bounces off). Components smaller than 0.1 come
out as zero.
@spec slide(tracer(), Cauldron3D.Vec.t(), Cauldron3D.Vec.t(), number(), keyword()) :: result()
Move for seconds at velocity, sliding along up to four surfaces. A hit plane whose
normal points up more than :floor (default 0.7) blocks as a floor; an upright one as
a wall. The velocity is stopped when it would turn back on itself or is pinned in a
corner.
@spec step( tracer(), Cauldron3D.Vec.t(), Cauldron3D.Vec.t(), number(), number(), keyword() ) :: result()
As slide/5, but a box stopped by a wall tries again from up to step higher and
settles back down, keeping whichever went further along the ground. Takes slide/5's
options.