Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

Sponsored Links

Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs

Simulate fuzzy phenomena with particle systems

Use particle systems to simulate explosion rings, fireworks explosions, vapor trails, and more

  • Print
  • Feedback

Page 2 of 5

Spacewar involves a pair of spaceships battling around a star whose gravity pulls them in. While trying to avoid the star, these spaceships fire torpedoes at each other. As Figure 1 reveals, the particle system rips apart a spaceship when the spaceship is hit by a torpedo.

Figure 1. The lower-right spaceship's breakup is generated by a particle system



The Spacewar particle system also generates explosions whenever both spaceships collide. Despite a low resolution and the absence of color, Figure 2 indicates a degree of realism that the particle system achieves when simulating explosions.

Figure 2. The particle system manages two explosions when both spaceships collide



Note
If you would like to play the original Spacewar game (which is in the public domain), point your Web browser to the Spacewar instructions page and follow the instructions. After you download the Perl and Java source files, you will need to install a copy of Perl on your system (if you don't already have Perl installed) and execute the following commands to create spacewar.bin:

  • perl macro.pl spacewar.mac >out expands macros in spacewar.mac's PDP-1 assembly language and stores the expanded assembly language in a file named out
  • perl pass12.pl out >out1 performs a two-pass assembly of out's expanded assembly language and stores a binary listing in a file named out1
  • perl tape.pl out1 extracts the object code from out1's binary listing and stores it in spacewar.bin


After you create spacewar.bin, compile pdp1b.java, which also compiles all of the associated Java source files. Execute java pdp1b and click the resulting GUI's Run button to play. The pdp1b program loads spacewar.bin and starts a PDP-1 emulator to interpret this file's contents.



Subsequent to Spacewar, particle systems were used in other games (such as Asteroids). But their potential was not realized until 1983. In that year, Lucasfilm's William T. Reeves published his paper "Particle Systems: A Technique for Modeling a Class of Fuzzy Objects." This paper formalized the particle system concept. It was well received because it described the particle system that generated the Genesis Effect's planetary wall of fire in the movie Star Trek II: The Wrath of Kahn. If you have an account with the Association for Computing Machinery, you can read Reeves's paper, a link to which appears in Resources.

Particle system software

Particle system software lets you simulate fuzzy phenomena by supporting the modeling, rendering, and animation of particles. My Java-based particle system software provides the PS class to support modeling and facilitate animation. It also provides the Display class to support rendering. I first discuss Display because PS depends on this class.

The renderer

The Display class is a java.awt.Canvas component that renders particles. It renders particles as individual pixels, although there is no reason why Display could not render them as groups of pixels, images, and so on.

When you create a Display object, you identify a window and a viewport. CG courses typically define window as the portion of a 2D world that you want to see. The window's coordinates are specified as floating-point values and are known as world coordinates. CG courses also typically define viewport as the portion of the screen where you want to display the window's contents. The viewport's coordinates are specified as integer values and are known as screen coordinates. A transformation known as the windowing transformation maps world coordinates to screen coordinates. Figure 3 illustrates this mapping in terms of world point (xw, yw) and equivalent screen point (xs, ys).

  • Print
  • Feedback

Resources