Ball and Spring Toy
Chapter 4 of Ian Parberry's "Introduction to Game Physics with Box2D"
 All Classes Files Functions Variables Enumerations Pages
Ball and Spring Toy

This code was written by Ian Parberry to accompany his book "Introduction to Game Physics with Box2D", published by CRC Press in 2013.

Having been introduced to the theory of Verlet integration and Gauss- Seidel relaxation in Chapter 2, we now examine code for a Ball and Spring Toy, which lets you play with a body made up of a bunch of balls connected by constraints. The constraints can be either stick-like (with no springiness), or spring-like (with lots of springiness). You can cycle through various types of body and you can apply impulses to them to see how they react. The toy starts with the body in the air, from which position it drops under gravity to rest at the bottom of the screen.

The controls are very basic. The space bar applies an impulse in a random direction, the Enter key restarts with the current body type, and the Back key advances to the next body type. The Escape key, as always, quits.

This is a toy, not a game, because there is no concept of winning or losing.