Implementation


The algorithm can be implemented very easily. First we extend the drawable interface so that any object that might be drawn is capable of supplying a z value for sorting.

    import Raster;

    public abstract interface Drawable {
        public abstract void Draw(Raster r);
        public abstract float zCentroid();
    } 
Next, we add the required method to our triangle routine:

    public final float zCentroid() {
        return (1f/3f) * (vlist[v[0]].z + vlist[v[1]].z + vlist[v[2]].z);
    } 
Lecture 14   Slide 11   6.837 Fall '00