3D Engine Progress

Misc., Projects Add comments

Java really isn’t suited to 3D, or anything graphical at all for that matter.

However, as an “academic exercise” (read: product of boredom) I’ve been playing around with making a basic 3D renderer in Java. Thank’s to my friend Alan, I’ve been able to extrapolate on his 3D point mathematics teachings and turn it into a working basic renderer.

Currently I’ve implemented double buffering to eliminate flickering, backface elimination and Z-ordering, and with all the overloading I’ve written I’ve now got a pretty neat 3D library. I’m yet to write any shading code (hence the reason why the below screenshot is ugly - I’ve had to randomly color each face to make the object visible) but I can load in objects from a basic proprietary 3D shape format of Alan’s creation and render them in 3D space. I’ve also added functions for moving/rotating points and objects, which allows the current demonstration code to display several spinning objects.

3D Renderer Screenshot

My shape class can show objects as either solid rendering (pictured), wireframe, or as a point “cloud”.

All great fun, but the performance is pretty horrible. Once more than about 7,000 faces are loaded in, the framerate slows to only a handful of frames per second - a high-quality Torus Knot of 12,000 faces only manages 3 frames per second.

The Z-Sorting for both objects and faces was originally a basic Bubble-sort of my own writing, but for performance reasons I swapped it out with a more efficient (if more complex) Merge sort algorithm. I had to “borrow” the latter from a tutorial site on the Internet — after two complete attempts of my own I gave up and left the sorting code to the experts.

I’ll try to get some more screenshots up in the next few days, and/or coax the applet into running in a webbrowser for a live demonstration.

Leave a Reply

WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in