Initializes buffers and data structures necessary for the collision detection (based on provided Components)
The WebGPU context
The components that will take part in the collision detection
The parameters for the collision detection
The parameters for the visual representation (rendering) of the results of the collision detection algorithm
The name of the debug context
The box where the collision detection is active
Smallest element radius for this component
Used by subclasses to execute a series of WgPasses in sequence
Runs only the rendering passes (visual representation of collision detection results)
Gets the error/imprecision of the collision detection calculations for a specific component
Explanation: The precise way to update the positions of the atoms of a Component when its matrix changes would be (1) get the initial positions of the atoms (2) transform these positions by the new matrix. However, we do not have the initial atom positions on the GPU! So instead, we (1) get the current positions of the atoms (2) transform these positions by the (newMatrix * inverse(oldMatrix)). However, this comes with a cost: the result of this operation is imprecise. It is not the same as the first method. The imprecision is the sum of all elements of the absolute element-wise difference of newMatrix and ( (newMatrix * inverse(oldMatrix)) * oldMatrix ), or, perhaps more concise:
trans = new * inv(old); <- Matrix to go from old to new position
error = sum( abs( (trans * old) - new ) ); <- abs() is elementwise
sum() sums the individual matrix elements
The component to get the collision detection error/imprecision of
Reads the collision buffer from the GPU to the CPU (slow) Each bit in the Uint32Array represents an atom 1 means this atom collides with at least one other atom 0 means this atom does not collide with any other atom
Reads the collision buffer from the GPU to the CPU and converts it to a BitArray
Resets the atom positions of a component This will copy all of the atom positions from CPU to GPU (slow)
WARNING: Make sure you run start() once before running this function Runs the entire collision detection pipeline, including rendering
The data necessary to apply a transformation to one component in the next collision detection algorithm. If nothing/undefined is provided, no transformation will occur
Sets the uniforms/parameters for the collision detection calculations
Sets the uniforms/parameters for the visual representation (rendering) of the collision detection
Sets the size of the rendering target
Performs the first iteration of this algorithm It is strongly recommended to run this function before running run() or draw(), otherwise, problems may occur
Updates the matrix of a component
Component whose matrix will be updated
The new matrix of Component 'c'
Generated using TypeDoc
Implements the collision algorithm. This class is responsible for the following:
The first step of the algorithm is defining a uniform grid that will contain all the atoms. This allows us to compare an atom only with its neighbors, and not with all other atoms. We try to have each cell of the grid have the size of the smallest atom radius. If the grid is too large and there are too many cells, we increase the size of the cells until there aren't too many cells.
The algorithm consists of the following passes:
ASSIGN passes (assigns the atoms to a cell in a grid)
and, most importantly, assign each atom to a grid cell
SORT passes (sorts the atoms by their cell - improves caching coherence - counting sort)
atom data (positions, etc.)
COLLIDE GLOBAL passes (actually only one pass... performs the collision detection!)
RENDER passes (optional - again, only one pass)
render the atoms that do collide