< Back

Gravity Simulation Game

Andrew Buck and Justin Reynolds

CS 4610/7610 - Computer Graphics I
University of Missouri
Spring 2013

Code

The gravity-sim application is written in C++ using OpenGL and FLTK. The source is available on GitHub here.

Screenshots

The simulation can handle many hundreds of objects.

 

Levels in which the actor must collect all objects can be created and played.

 

A force grid shows the gravitational potential caused by the objects.

Design

This application provides a sandbox environment for experimenting with the effects of gravity. It offers the following features:

How It Works

The objects in the simulation obey Newton's law of universal gravitation. The force between each pair of objects is computed as an inverse-square relation. The forces are aggregated and applied to each object to advance the simulation. The current implementation has O(n^2) complexity.

Each object in the simulation is defined as a Body class.

 

A universe class is defined that manages the simulation.

 

The GlWindow class is a child of the Fl_Gl_Window class and handles user input and drawing commands.

 

Each keypress or mouse movement generates an event, and the appropriate action is taken depending on the state of the program. This allows additional functionality such as drawing the force grid, and adding static members, actors, and targets.

Graphics Lessons Learned

Future Enhancements