Game Development Reference
// Get the origin and half size of the block, in old-body
// local coordinates.
cyclone::Vector3 halfSize = (max - min) * 0.5f;
cyclone::Vector3 newPos = halfSize + min;
// Convert the origin to world coordinates.
newPos = tempBody.getPointInWorldSpace(newPos);
// Set the body's properties (we assume the block has a body
// already that we're going to overwrite).
blocks[i].offset = cyclone::Matrix4();
blocks[i].exists = true;
// Finally calculate the mass and inertia tensor of the new block.
This assumes that the collision will occur on the YZ plane of the block (which it
must in our demo). More complete code would have similar algorithms for the other
possible collision planes.
Because the resulting pieces are roughly rectangular, they are treated like rectan-
gular blocks for calculating their inertia tensors. This is done simply as
Excerpt from src/demos/fracture/fracture.cpp
* Calculates and sets the mass and inertia tensor of this block,
* assuming it has the given constant density.
void calculateMassProperties(cyclone::real invDensity)
// Check for infinite mass.
if (invDensity <= 0)
// Just set zeros for both mass and inertia tensor.