Log inGet started
World

Builtin Library

Branchmain
Branchesmainpublish
Commitdd348ac6c3

README.md

ray_shapes

Casts rays and segments against a table of analytic shapes (plane, sphere, box, capsule) and answers the closest hit of each. A ray is 8 words of rays: origin xyz, tmin, direction xyz, tmax; the direction need not be unit length, so a segment from a to b is origin a, direction b - a, tmin 0, tmax 1. The table is one columns binding named shapes, a row a shape, columns in this order: shapeKind (Int: 0 plane, 1 sphere, 2 box, 3 capsule), center (Vec3), extent (Vec3: a plane's unit normal, a sphere's radius in x, a box's half size, a capsule's radius in x and half length in y), rotation (Vec4 quaternion x y z w; a capsule lies along its own y), bounce, friction (Float, carried for the caller) and index (Int, the caller's id for the shape).

Outputs, a value per ray: hit (t, then three zeros), hit_prim (the row of the hit shape, 0xffffffff for a miss), hit_normal (the unit surface normal, turned to face the ray's origin side, zero for a miss) and hit_end (the hit point pushed out along the normal by the skin param; for a miss the ray's end, origin + direction * tmax). A shape is hit from outside at its entry and from inside at its exit; of two hits at equal t the lower row wins. Exact.

sim.particles runs it in its collision stage, against the shape table of its colliders.