Source Code

I've decided to make some of my source code available via an anonymous CVS repository. Most of these are short hacks and things I tinkered together to test ideas or just to make amusing pictures. You can download this code and tinker with it as you see fit. I don't really want to bore you with a license agreement at this time, it seems really silly to do so given that there is nothing too remarkable about any of this source code. If you use it in an interesting way, credit me in whatever way seems appropriate, and let me know. I'd be interested in any uses of this code.

New! I've added a cvsweb interface to my anonymous CVS repository. You can browse my source code online from here.


The MTV RayTracer

Module=mtv-original

Module=mtv-modern

The Obligatory Teapot

When I was a graduate student back in 1987, I wrote a series of raytracing programs to help learn about computer graphics. These culminated in the MTV raytracer, which was published on the comp.sources.unix Usenet group. The original version was placed in the public domain, and remains free for any use whatsoever. It has a number of other drawbacks, not the least of which is that it does not use ANSI prototypes. Nevertheless, it does have a number of interesting features, such as an implementation of the Goldsmith Salmon optimization method for the Kay Kajiya hierarchal bounding volume acceleration scheme.

Over the years I've made a number of modifications to this original program. I tried to remove most of the compiler warnings, added prototypes and added a number of other basic primitives such as Bezier patches. Again, the code itself has several dead ends, failed bits of design, and overall reflects some of the weakness of the original design which were too troublesome to remove. It does however have some other chunks of code which may be interesting to look at, including an implementation of Toth's 1985 paper on ray/patch intersection.

Note: These programs are toys, and are the result of long evolution from flawed initial design, and do not accurately reflect the quality of code to which I hold myself to professionally. Examine them if you like, but try not to hold anything you don't like against me: I was much younger back then. I am also unable to provide signficant support for either of these programs, although I will attempt to answer email as time provides.

mtv-original
This is the source code to the raytracer that I originally wrote in 1987. It isn't even fully prototyped, and is pretty basic.
mtv-modern
This is one of the more heavily modified versions of the above code. It should compile fairly cleanly, and has a number of added features such as an implementation of the Toth ray/patch intersector.


The Original Spacewar

Module=spacewar

The original PDP-1

If you ask people what the oldest video game was, they might answer " Space Invaders" or "Pong". Both are good guesses, but the first video game actually was much older: Spacewar.

From http://lcs.www.media.mit.edu/groups/el/projects/spacewar/readme.html

Spacewar! was conceived in 1961 by Martin Graetz, Stephen Russell, and Wayne Wiitanen. It was first realized on the PDP-1 in 1962 by Stephen Russell, Peter Samson, Dan Edwards, and Martin Graetz, together with Alan Kotok, Steve Piner, and Robert A Saunders. Spacewar! is in the public domain, but this credit paragraph must accompany all distributed versions of the program.

Tom Duff discovered the code and binaries for the PDP-1 version of Spacewar, and decided to write an emulator for the machine so he could play. It sounded like so much fun I decided to do so myself. The PDP-1 is an odd little machine. It has 4096 words of 18 bit memory, used ones complement arithmetic, and had a dot addressable graphics display. It is pretty straightforward to write an emulator for it, so I did, and with help from Tom, debugged it.
Screen Dump of My Emulator

The program itself is pretty simple. Simulating the machine takes about 500 lines of code, and the total code clocks in at 841 lines, and uses OpenGL and GLUT to do the graphics. Adapting the code to other graphics systems would probably be pretty simple, as it really only requires the ability to place dots on the screen.

The PDP-1 had no framebuffer, if you wanted to plot a point, you basically had to keep replotting it over and over before the phosphor on the oscilloscope decayed away. In the photo of the original to the left you can see that the phosphors had large decay constants, and moving spaceshifts left rather large blurs.

I chose to try to mimic this behavior by directly simulating the decay. When the emulator plots a point, it stores its coordinates in a hash table. If the point was already in the hashtable, it resets the age of the pixel to zero. When the bottom of the main simulation loop of the Spacewar! program is reached, all the points are plotted, using their age as an indicator of how bright they are. Then the ages of all the points are incremented. Those which become too old are deleted, and the simulation begins anew. You can see how this works in the screen dump on the right (click on it to get the larger version). The ship leaves behind a greenish trail which decays. This makes the torpedos look much nicer as well, as they leave nice blurred trails. The actual degree of blurring is quite a bit smaller than in the original, but the effect is still pleasing.
The original video gamers

I'm currently working on a simple set of AI procedures that will be added to the basic program to make the game play against itself. It is kind of fun in itself, and will allow me to turn the entire simulation into kind of an interesting screensaver.

Update: You can download a zip file containing the compiled version for Win98/ME/2K as well.


Obtaining the Source Code

To check out any of these modules, you'll need a CVS client. On most unix-like systems, a line like:

cvs -d :pserver:anonymous@vandewettering.net:/usr/anoncvs checkout module-name

will transfer all needed files to your computer.