Documentation
¶
Overview ¶
Package geometry provides allocation-free 3D collision primitives: vectors, quaternions, capsules, spheres, AABBs, OBBs, rays, triangles, and pairwise + swept intersection tests. All operations are pass-by-value to stay zero-allocation on hot paths.
Used by kit/spatial (broadphase indices), kit/game/lagcomp (hit traces), kit/unreal/collision (server-side level geometry queries), and any non-game consumer that needs basic 3D geometry (robotics, AR, GIS).
Index ¶
- func AABBOverlap(a, b AABB) bool
- func OBBOverlap(a, b OBB) bool
- func RayAABB(r Ray, b AABB) (tMin, tMax float32, ok bool)
- func RaySphere(r Ray, s Sphere) (float32, bool)
- func SphereSphere(a, b Sphere) bool
- func SweptCapsuleStatic(c Capsule, motion Vec3, world []Tri) (float32, bool)
- func SweptSphereTriangles(s Sphere, motion Vec3, world []Tri) (float32, bool)
- func TriTriOverlap(t1, t2 Tri) bool
- type AABB
- type Capsule
- type OBB
- type Quat
- type Ray
- type Sphere
- type Tri
- type Vec3
- func (a Vec3) Add(b Vec3) Vec3
- func (a Vec3) Cross(b Vec3) Vec3
- func (a Vec3) Distance(b Vec3) float32
- func (a Vec3) DistanceSq(b Vec3) float32
- func (a Vec3) Div(s float32) Vec3
- func (a Vec3) Dot(b Vec3) float32
- func (a Vec3) Len() float32
- func (a Vec3) LenSq() float32
- func (a Vec3) Lerp(b Vec3, t float32) Vec3
- func (a Vec3) Mul(s float32) Vec3
- func (a Vec3) Neg() Vec3
- func (a Vec3) Normalize() Vec3
- func (a Vec3) Sub(b Vec3) Vec3
- func (a Vec3) X() float32
- func (a Vec3) Y() float32
- func (a Vec3) Z() float32
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AABBOverlap ¶
AABBOverlap reports whether two AABBs overlap on all axes.
func OBBOverlap ¶
OBBOverlap reports whether two oriented bounding boxes overlap using the Separating Axis Theorem. Tests all 15 candidate axes (3 from each OBB's local frame + 9 cross products).
func RayAABB ¶
RayAABB returns the entry and exit parameters along r for box b. ok=false means the ray misses; tMin > tMax can also be checked by the caller.
func RaySphere ¶
RaySphere returns the closest positive intersection distance and ok=true, or ok=false if the ray misses.
func SphereSphere ¶
SphereSphere reports whether two spheres overlap.
func SweptCapsuleStatic ¶
SweptCapsuleStatic sweeps a capsule by motion against a set of static triangles. Returns the earliest time-of-impact in [0, 1] and whether a hit occurred. Conservative implementation: tests the bounding sphere (capsule midpoint, longest-extent + radius) per triangle; sufficient for projectile/melee adjudication where motion magnitudes are modest.
func SweptSphereTriangles ¶
SweptSphereTriangles sweeps a sphere by motion against a set of static triangles, returning the earliest time-of-impact in [0, 1] and a hit flag. Conservative: uses the swept-sphere-vs-triangle test pairwise.
func TriTriOverlap ¶
TriTriOverlap reports whether two triangles overlap, using the Möller-style coplanarity + edge-test approach. Reasonably fast; not the absolute fastest known algorithm but clear and correct.
Types ¶
type AABB ¶
type AABB struct {
Min, Max Vec3
}
type OBB ¶
OBB is an oriented bounding box centred at Center with the given half-extents along its local axes, rotated by Rotation.
type Quat ¶
type Quat [4]float32
Quat is a unit quaternion stored as (x, y, z, w). The identity rotation is Quat{0, 0, 0, 1}.
func QuatFromAxisAngle ¶
func QuatIdentity ¶
func QuatIdentity() Quat
type Vec3 ¶
type Vec3 [3]float32
Vec3 is a 3D vector. Components are float32 for cache friendliness in game-server hot paths where millions of operations per tick are common. Use float64 conversions explicitly when interfacing with stdlib math.
func CapsuleCapsule ¶
CapsuleCapsule reports whether two capsules overlap and returns the midpoint of the closest segment pair as the contact point.
func RayTriangle ¶
RayTriangle implements Möller–Trumbore. Returns hit point, distance, and whether the triangle was hit.