oreilly.comSafari Books Online.Conferences.


Building a Black Hole With OpenGL
Pages: 1, 2, 3, 4, 5

Closing notes

If we were interested, the singularity in this simulation could be eliminated, and a mass value could be added for each particle. By calculating the distance between each particle and the force of gravity each particle's mass exerted upon all the others, accurate n-body predictions could be made. In this way, our simulation would grow from an "m" times 2-body environment to a truly chaotic n-body system.

It is in some ways reassuring to know that the simple algorithm, "foreach (Particle) { P += V; V += GravSum(ParticleList); }", turns out to be the only way to calculate n-body trajectories when "n" grows to be more than (currently) about six; the more direct equations quickly become too complex for we puny humans, or our computers, to solve. In fact, specialized hardware has been built that does nothing but run essentially the n-body version of this algorithm to simulate our solar system at very fine temporal resolution for highly accurate predictions.

In the less abstract, limited term simulations can be used for various effects such as simulated jet exhaust smoke trails, artillery trajectories, or fireworks. By replacing the ourMoveParticle() function, radically different types of simulations can be built such as non-deterministic bird or bee behavioral motion.

Program and Makefile

• bhole.c - The OpenGL black hole simulator.

• Makefile - Simple makefile.

Particle systems can be a wonderful way of adding complexity to an environment with a minimum of programmer effort, providing the hardware can support enough particles to make the aggregate effect convincing. The results can often be mesmerizing, as I found during the construction of this program.

And, of course, no software is finished, only abandoned; there are lots of things that could be added to this program to make it even more interesting. Suggestions include optical warping effects around the black hole of those particles behind it, rendering each particle using a single quad as a true "billboard" facing the observer, and doing some kind of visual effect when a particle is captured. Having a mode where the particle's color is a function of its position or one of its vectors would likely be educational too.

It's your universe; imagine, then create!

Chris Halsall

Chris Halsall is the Managing Director of Ideas 4 Lease (Barbados). Chris is a specialist... at automating information gathering and presentation systems.

Related Articles:

Creating Real Time 3D Graphics With OpenGL

OpenGL Rendering and Drawing

Preparing to Build an OpenGL Application

Discuss this article in the O'Reilly Network Linux Forum.

Return to the Linux DevCenter.


Linux Online Certification

Linux/Unix System Administration Certificate Series
Linux/Unix System Administration Certificate Series — This course series targets both beginning and intermediate Linux/Unix users who want to acquire advanced system administration skills, and to back those skills up with a Certificate from the University of Illinois Office of Continuing Education.

Enroll today!

Linux Resources
  • Linux Online
  • The Linux FAQ
  • Linux Kernel Archives
  • Kernel Traffic

  • Sponsored by: