[][src]Crate zvxryb_broadphase

Overview

broadphase-rs is a broadphase collision detection library. It transforms object bounds into a lightweight spatial index representation. These indices are integer values which are sorted directly to yield a result which is a topologically-sorted Morton order, after which full-system collision detection can be accomplished by a single pass over the sorted list with only a minimal auxiliary stack necessary to maintain state. Collision tests between indices are accomplished with simple bitwise shifts, masks, and XORs.

This method is capable of supporting objects of varying scale (unlike uniform grids), while having a straightforward, non-hierarchical structure in memory (unlike quad- or oct-trees), as the entire representation exists in a single vector of index/object pairs.

Usage

Layer is the "main" struct of broadphase — this is where the sorted list of spatial indices is stored.

The usual sequence of operations on a Layer is as follows:

extern crate zvxryb_broadphase as broadphase;
 
use broadphase::{Bounds, Layer, LayerBuilder, Index64_3D};
type ID = u64;
 
let mut layer: Layer<Index64_3D, ID> = LayerBuilder::new().build();
 
// clears existing object index-ID pairs:
layer.clear();
 
// appends an iterator of object bounds-ID pairs to the layer:
layer.extend(system_bounds, objects);
 
// scans the layer for collisions:
let potential_collisions = layer.scan();

Structs

Bounds

An axis-aligned bounding box

Index64_3D

A 64-bit 3D index which provides 19 bits' precision per axis

Layer

A group of collision data

LayerBuilder

A builder for Layers

RayTestGeometry

A type implementing TestGeometry for rays

Traits

SpatialIndex

An index representing an object's position and scale

SystemBounds

System bounds supporting conversions between local and global coordinates

TestGeometry

A trait for implementing individual geometry tests