CellSpacePartitioning constructor
CellSpacePartitioning()
Constructs a new spatial index with the given values.
Implementation
CellSpacePartitioning( this.width, this.height, this.depth, this.cellsX, this.cellsY, this.cellsZ ) {
_halfWidth = width / 2;
_halfHeight = height / 2;
_halfDepth = depth / 2;
_min = Vector3( - _halfWidth, - _halfHeight, - _halfDepth );
_max = Vector3( _halfWidth, _halfHeight, _halfDepth );
//
final cellSizeX = width / cellsX;
final cellSizeY = height / cellsY;
final cellSizeZ = depth / cellsZ;
for ( int i = 0; i < cellsX; i ++ ) {
final x = ( i * cellSizeX ) - _halfWidth;
for ( int j = 0; j < cellsY; j ++ ) {
final y = ( j * cellSizeY ) - _halfHeight;
for ( int k = 0; k < cellsZ; k ++ ) {
final z = ( k * cellSizeZ ) - _halfDepth;
final min = Vector3();
final max = Vector3();
min.set( x, y, z );
max.x = min.x + cellSizeX;
max.y = min.y + cellSizeY;
max.z = min.z + cellSizeZ;
final aabb = AABB( min, max );
final cell = Cell( aabb );
cells.add( cell );
}
}
}
}