This applet is a demonstration of physics-based modeling. This applet
models a chain of balls connected by springs. The two ends are fixed; the
balls in the middle are initially assigned random positions, and the
forces of the springs and of gravity then act on them. Click on the applet
with your mouse to restart the process. Physics-based modeling was once
purely the domain of academia, but there is increasing interest in it
among games developers, who are striving for ever-increasing levels of
realism in their virtual worlds. (For example, note that the balls
eventually settle into a curved shape, rather than a straight line;
this is due to the interaction of gravity with the mass of the
balls and the force applied by the springs. Pretty cool, eh?).
This applet is essentially a Java port of an example program by
Dr. Jim X. Chen. The program was
originally written in SGI GL. I first ported it to OpenGL, and then, for
grins, to Java.
This applet makes use of double buffering. There is no built-in support
for double buffering in Java, as there is in OpenGL (that is, there is
nothing analogous to auxSwapBuffers() in Java). However, you can get
the same effect by doing all your drawing to an offscreen Image and then
responding to paint() messages by simply drawing the image onscreen.
The Source