This IOTD demonstrates my 2d metaball engine I wrote in a couple days, rendered in OpenGL.
Rendering and calculating metaballs are very cpu extensive, 2d or 3d. My goal was to have many metaballs on the screen at once without slowdown, so I opted for 2d. To reduce the computing load and increase fps, the
window itself is rendered in 320x240, and then is broken into 160x120 chunks. Even then, rendering a mere 10 metaballs would mean 192000 illiterations! (120x160x10). With certain optimizations I managed to reduce that
number to around 15000.
Drawing the metaballs involves density/electrical fields. Density fields are usually used to display things such as air pressure or temperature but they can be used to display blobs also. Every point on my 160x120 graph is
tested to see how far away it is from all the metaball's centers. If that value passes a certain threshhold the pixel passes, and is rendered. Surprisingly, the color of each pixel is determined almost the same way.
The 'A' key adds a metaball. The 'S' key subtracts a metaball. 'Enter' singles out a a certain threshhold value, and only draws it. (torus)
The demo is available for download here: iotd-04-06-2002_metaballs.zip (41k)
Brian Washburn, 2002