Chapter 13. Connecting Objects

Simulating particles and rigid bodies is great fun, and with these simple entities you can achieve a wide variety of effects or simulate a wide variety of objects. In this chapter we’ll take things a step further, showing you how to simulate connected particles and rigid bodies. Doing so opens a whole new realm of possibilities. In this book’s first edition, David showed you how to use springs and particles to simulate cloth. Chapter 17 in the first edition covers that, and the corresponding “Cloth Simulation” example on the book’s website implements the model. As shown in Figure 13-1, the flag model is simply a collection of particles initially laid out in a grid pattern connected by linear springs that are then rendered to look like cloth. The springs give structure to the particles, keeping them organized in a mesh that can be rendered while allowing them to move, emulating the movement of a flowing fabric.

Network of particles and springs
Figure 13-1. Network of particles and springs

Each line in the wireframe flag shown in Figure 13-1 represents a spring-damper element, while the nodes where these springs intersect represent the particles. We modeled the springs using the spring-damper formulas that we showed you back in Chapter 3. The (initially) horizontal and vertical springs provide the basic structure for the flag, while the diagonal springs are there to resist shear forces ...

Get Physics for Game Developers, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.