| 164 | } |
| 165 | |
| 166 | static void ShatterShape(cpSpace* space, cpShape* shape, cpFloat cellSize, cpVect focus) |
| 167 | { |
| 168 | cpSpaceRemoveShape(space, shape); |
| 169 | cpSpaceRemoveBody(space, cpShapeGetBody(shape)); |
| 170 | |
| 171 | cpBB bb = cpShapeGetBB(shape); |
| 172 | int width = (int)((bb.r - bb.l) / cellSize) + 1; |
| 173 | int height = (int)((bb.t - bb.b) / cellSize) + 1; |
| 174 | // printf("Splitting as %dx%d\n", width, height); |
| 175 | struct WorleyContex context = {(uint32_t)rand(), cellSize, width, height, bb, focus}; |
| 176 | |
| 177 | for (int i = 0; i < context.width; i++) |
| 178 | { |
| 179 | for (int j = 0; j < context.height; j++) |
| 180 | { |
| 181 | cpVect cell = WorleyPoint(i, j, &context); |
| 182 | if (cpShapePointQuery(shape, cell, NULL) < 0.0f) |
| 183 | { |
| 184 | ShatterCell(space, shape, cell, i, j, &context); |
| 185 | } |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | cpBodyFree(cpShapeGetBody(shape)); |
| 190 | cpShapeFree(shape); |
| 191 | } |
| 192 | |
| 193 | static void update(cpSpace* space, double dt) |
| 194 | { |
no test coverage detected