static void split(pl_collisioncontext_t *ctxt, pl_recgrid_t *grid) { if (grid->children[0] == NULL) { for (int i = 0 ; i < 8 ; i++) { grid->children[i] = pl_new_recgrid(ctxt, grid->size/2.0); grid->children[i]->centre = grid->centre; } lwc_translate3f(&grid->children[0]->centre, grid->size/4.0, grid->size/4.0, grid->size/4.0); lwc_translate3f(&grid->children[1]->centre, grid->size/4.0, grid->size/4.0, -grid->size/4.0); lwc_translate3f(&grid->children[2]->centre, grid->size/4.0, -grid->size/4.0, grid->size/4.0); lwc_translate3f(&grid->children[3]->centre, grid->size/4.0, -grid->size/4.0, -grid->size/4.0); lwc_translate3f(&grid->children[4]->centre, -grid->size/4.0, grid->size/4.0, grid->size/4.0); lwc_translate3f(&grid->children[5]->centre, -grid->size/4.0, grid->size/4.0, -grid->size/4.0); lwc_translate3f(&grid->children[6]->centre, -grid->size/4.0, -grid->size/4.0, grid->size/4.0); lwc_translate3f(&grid->children[7]->centre, -grid->size/4.0, -grid->size/4.0, -grid->size/4.0); } for (int i = 0 ; i < grid->objs.length ; i++) { pl_object_t *obj = grid->objs.elems[i]; int octant = getoctant(&grid->centre, obj); if (fits(grid->children[octant], obj)) { pl_collcontext_insert_object(ctxt, grid->children[octant], obj); obj_array_remove(&grid->objs, i); i --; } } }
static void split(PLcollisioncontext *ctxt, PLrecgrid *grid) { if (grid->children[0] == NULL) { for (int i = 0 ; i < 8 ; i++) { grid->children[i] = plNewRecgrid(ctxt, grid->size/2.0); grid->children[i]->centre = grid->centre; } ooLwcTranslate3f(&grid->children[0]->centre, grid->size/4.0, grid->size/4.0, grid->size/4.0); ooLwcTranslate3f(&grid->children[1]->centre, grid->size/4.0, grid->size/4.0, -grid->size/4.0); ooLwcTranslate3f(&grid->children[2]->centre, grid->size/4.0, -grid->size/4.0, grid->size/4.0); ooLwcTranslate3f(&grid->children[3]->centre, grid->size/4.0, -grid->size/4.0, -grid->size/4.0); ooLwcTranslate3f(&grid->children[4]->centre, -grid->size/4.0, grid->size/4.0, grid->size/4.0); ooLwcTranslate3f(&grid->children[5]->centre, -grid->size/4.0, grid->size/4.0, -grid->size/4.0); ooLwcTranslate3f(&grid->children[6]->centre, -grid->size/4.0, -grid->size/4.0, grid->size/4.0); ooLwcTranslate3f(&grid->children[7]->centre, -grid->size/4.0, -grid->size/4.0, -grid->size/4.0); } for (int i = 0 ; i < grid->objs.length ; i++) { PLobject *obj = grid->objs.elems[i]; int octant = getoctant(&grid->centre, obj); if (fits(grid->children[octant], obj)) { plInsertObject(ctxt, grid->children[octant], obj); obj_array_remove(&grid->objs, i); i --; } } }