Cauldron3D.Move (Cauldron3D v0.2.2)

Copy Markdown View Source

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.

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.

Types

result()

@type result() :: %{
  origin: Cauldron3D.Vec.t(),
  velocity: Cauldron3D.Vec.t(),
  blocked: [:floor | :wall],
  hits: [Cauldron3D.Hull.Trace.t()]
}

tracer()

Functions

clip(velocity, normal, overbounce \\ 1.0)

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.

slide(trace, origin, velocity, seconds, opts \\ [])

@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.

step(trace, origin, velocity, seconds, step, opts \\ [])

@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.