Nicholas Retallack
CS161 - Winter 07

Squishy Dynamics

Introduction

I had originally proposed to build a simple physics engine for my final project and implement rigid body dynamics. However, after finding this was far too difficult for me to learn all at once, I decided to instead elaborate on my own imaginary squishy physics you may remember from the rolling balls assignment. Although the physics I made up has no basis in reality, it does create a very interesting and useful result, and would be very useful in a game engine.

This project simulates bouncy spheres that can be nested inside other spheres. They'll collide and respond with eachother and their container, and bounce around for your entertainment. Since there is no friction and the transfer of momentum is imprecise, some simulations will eventually blow up after steadily increasing in kinetic energy. This is intentional. In a practical use of this physics system there would be elastic friction applied.

Download

squish-src.zip

Invocation

Requires a Ruby interpreter and ruby-opengl. The One-Click Ruby Installer for Windows has everything you need. For Mac and Linux users, just look for ruby1.8 and ruby-opengl on your favorite package manager. To run, call the ruby interpreter on main.rb and provide a yaml file to specify the object properties.

ruby main.rb yaml/zoo.yaml

Controls

General -
Toggles displays
esc
Quit
a
Stop/Start Animating
s
Toggle Slow Motion

Physics

This project simulates imaginary elastic balls, which attempt to return to their original shape when compressed. However, the physics does not really use the visual compression shown. Instead, it simply uses their uncompressed forms to check how many units any two sibling objects are intersecting, or how far an oject is escaping its container. Each ball is then repelled with a force proportional to the intersection divided by the radius, giving the percentage of compression.

Squishing

The squishing graphical effect was a simple but clever idea. Whenever two balls are found to be touching during a physics step, they each get a new squish effect added to their squishes list which records both the angle and the amount of compression in the squish. When a ball is rendered, it loops through the list of squishes and for each one it rotates to the direction of the squish, then scales the object by the amount of compression, then rotates back so further squishes can be applied.

YAML

You can specify any configuration of objects you want by writing your own yaml file. The format used is a sequence of balls with properties for position, velocity, radius, density, color, and contains. Contains is yet another sequence of balls. Entries start with a -, and indentation matters. All fields are optional: most will assume zero, but radius defaults to 5, density to 1, and color to something random. Here is an example of how to specify these properties:

        - radius: 20
          position: {x: 2, y: 3}
          velocity: {x: -2, y: 1 }
          color:    {r: 0.5, g: 0, b: 1 }
          contains:
          - radius: 3
            velocity: {x: -0.4, y: .2 }   
      

ScreenShots!

eye1 eye2 eye3
zoo1 zoo2 zoo3
beads1 beads2 beads3 beads4
beads5 beads6 beads7 beads8