Allright, here's an update on Manic Motion. I've spent the last couple of days implementing a 3D-clipping system. Like I said before, that's when one of the real advantages of homogeneous coordinates come into play. After a homogeneous perspective transform (ie. a transformation to the perspective space I talked about last time), the W-coordinate contains the clipping boundary for X, Y and Z. Yes, one clipping value for all.
Basically, the clipper as it is now is based on the standard Sutherland-Hodgeman clipping algortithm. The only thing that's different is the calculation of the distance to the clipping plane. Here's a piece of code:
This particulair piece clips a polygon against the right plane of the viewing-frustum. Note the if-statements, where each X-coordinate is checked against the W-coordinate of that same vertex. For the left plane, each coordinate is checked against -W. This is clearly faster than finding the distance to a plane using classic 3D coordinates.
The only disadvantage I've come across so far is that it is not yet possible to define an arbitrary clipping plane. Now I don't think Manic Motion will be a portal-based engine, but there are other uses for this as well. However, I think it will be possible by tweaking the perspective matrix. Maybe more on that later.
There's also an updated test-application. The most obvious change is the group of CPU-usage bars. These only give meaningful values when displaying 1000 objects, because of the resolution of the timer (1/18.2 second intervals). One interesting thing is that the actual drawing of the faces takes up about half the CPU-time. That's way too much in my opinion, so lot can be optimized there. Try switching off the 3D-clipping. You can see the complete rejection of entire objects at work on the left and right sides. Oh, and don't try gouraud-shading with 3D-clipping on (you're going to anyway, aren't you? :).
Well, that's it for the moment. I'm working on the C-Buffer implementation now. For flat-shaded non-textured polygons it doesn't seem to be faster than just drawing the faces back to front with a normal poly-filler, but that's no surprise really :). Finding an efficient way to manage the segments is a bit of a challenge really.
Download The Sample Program: ManicMotion.exe