Game Development Reference
In-Depth Information
F IGURE 17.5
Screenshot of the fracture demo.
The second, more complex algorithm is for assigning correct physical character-
istics to the component objects. In particular, assigning a correct inertia tensor for
a general fractured shape is a nontrivial process. Appendix A gives formulae and al-
gorithms for calculating the inertia tensor of various regular objects. For a general
shape, however, these are complex and can be inefficient. Most developers opt for a
simplification and approximate shattered pieces with geometry that has easy inertia
tensors: boxes are a firm favorite.
Figure 17.5 shows the fracture demo on the CD. It contains a single large block,
made of a relatively dense, brittle material, such as concrete. You can move to aim and
fire a ball at the block. The block will shatter on impact, depending on where the ball
strikes. The decomposition scheme splits the block into eight components, dividing
it in each direction. The collision point is used as the center of two collisions, and the
other direction is split in half, as shown in figure 17.6. To make the results look more
realistic the splits are angled randomly.
The geometric division algorithm looks like this:
Excerpt from src/demos/fracture/fracture.cpp
/**
* Performs the division of the given block into four, writing the
* eight new blocks into the given blocks array. The blocks array can be
* a pointer to the same location as the target pointer: since the
* original block is always deleted, this effectively reuses its storage.
* The algorithm is structured to allow this reuse.
*/
void divideBlock(const cyclone::Contact& contact,
Block* target, Block* blocks)
{
Search Nedrilad ::




Custom Search