Final Project: Physics Model
Andrew Cantino & Will Moss

This is lab 10 of Computer Graphics. In this lab we develop a physics engine and make some pretty pictures.

Sections:

Physics Engine

For our final project, we implemented a physics engine. We started by adapting a Runga-Kutta integrator and vector physics engine written in Java by Andrew this summer (see BigSim). This took extensive rewriting of the code in order to port it to C++ and adapt it to our graphics system. Here is an outline of the physics engine as it stands in our C++ version:

Variables
int doWorldGravity              Model acceleration in -z due to gravity? (0/1)
int doAirFriction               Model air friction? (0/1)
double airFrictionCoeff         Coefficient of air friction.  (Try .025)
double gravityConstant          g (Usually 9.8 m/s^2)
double curTime                  The current time.
double timeStep                 The integration time step (try .01)

Classes
class mass                      A mass in the physics model.
        vector3D l              Location of the mass.
        vector3D v              Velocity of the mass.
        vector3D force          The current sum of forces on this mass.
        double m                Mass of the mass.
        bool locked             If true, the mass will not move due to forces.
        double distTo(mass &t)  Returns the distance from this mass to t.
class spring                    A Hooke's Law spring in the physics model.
        int body1, body2        Ids of the masses connected to this spring.
        double k                Spring constant of this spring.
        double damping          Damping constant of this spring.
        double restLength       Rest length of this spring.
        void doForces()         Apply the force of this spring to body1 and body2.

Functions
void findForces(vector & masses, vector & springs)
        Apply air friction, world gravity, and springs to every mass in masses.
void doRungaKutta(vector & masses, vector & springs)
        Do a Runga-Kutta timeStep of the physics model.
In developing this physics engine, the first thing that we did was try making some simple particle systems. Here are two examples. The first is a burst of particles that start with the same position but random velocities, then fall under world gravity. The second is a similar case, but with continuous particle generation.


Spinning around an explosion of particle boxes.
Click for larger version (with less aliasing).

Spinning around a fountain of particle boxes.
Click for larger version (with less aliasing).

Next, we wanted to use springs in interesting ways, so we started with modeling strings (chains of masses and springs). Here are two examples of strings, drawn as a series of boxes with invisible springs connecting them. The top box is fixed, but the rest fall under world gravity until the springs stop them. The second example has a higher air friction coefficient.


A bouncy string of springs.
Click for larger version (with less aliasing).

A bouncy string of springs with lots o' air friction.
Click for larger version (with less aliasing).

After strings, we did sheets! The sheets are polygon meshes with masses at each vertex and springs connecting them on a rectangular grid. Here are two examples of a sheet being poked:


A sheet fixed at the top, hanging in Earth's gravity, is suddenly displaced upwards from the bottom.
Click for larger version.

The same sheet, but fixed on all sides and poked in the middle.
Click for larger version.

Finally, we decided to turn our models into jelly! We associated a mass with each vertex of a model, and then connected all masses together with springs. To make our motion more realistic, we weighted the spring constants by the distance between the masses, so that close masses interact more strongly than far masses. Here are our results:


A torus, bouncing off of an invisible floor.
k is large and doesn't vary much.
Click for larger version.

The same torus, but with a different distribution of spring constants -- it's like jelly!
Click for larger version.

A torus, pinned at one point, falling due to gravity.
Click for larger version.

A sphere with a very sharp decrease in spring constant with distance.
Weird!
Click for larger version.

[Back to Lab Index]