MCPcopy Create free account
hub / github.com/axmolengine/axmol / ShatterShape

Function ShatterShape

tests/cpp-tests/Source/ChipmunkTestBed/demo/Shatter.cpp:166–191  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

164}
165
166static 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
193static void update(cpSpace* space, double dt)
194{

Callers 1

updateFunction · 0.85

Calls 9

cpSpaceRemoveShapeFunction · 0.85
cpSpaceRemoveBodyFunction · 0.85
cpShapeGetBodyFunction · 0.85
cpShapeGetBBFunction · 0.85
WorleyPointFunction · 0.85
cpShapePointQueryFunction · 0.85
ShatterCellFunction · 0.85
cpBodyFreeFunction · 0.85
cpShapeFreeFunction · 0.85

Tested by

no test coverage detected