protected EdgeEqn edge[];
protected int area;
protected int xMin, xMax, yMin, yMax;
private static byte sort[][] = {
{0, 1}, {1, 2}, {0, 2}, {2, 0}, {2, 1}, {1, 0}
};
public void Draw(Raster r) {
if (!triangleSetup(r)) return;
int x, y;
int A0 = edge[0].A; int A1 = edge[1].A; int A2 = edge[2].A;
int B0 = edge[0].B; int B1 = edge[1].B; int B2 = edge[2].B;
int t0 = A0*xMin + B0*yMin + edge[0].C;
int t1 = A1*xMin + B1*yMin + edge[1].C;
int t2 = A2*xMin + B2*yMin + edge[2].C;
yMin *= r.width;
yMax *= r.width;
/* .... scan convert triangle .... */
for (y = yMin; y <= yMax; y += r.width) {
int e0 = t0;
int e1 = t1;
int e2 = t2;
int xflag = 0;
for (x = xMin; x <= xMax; x++) {
if ((e0|e1|e2) >= 0) { // ***Hack 1*** all 3 edges must be >= 0
r.pixel[y+x] = color;
xflag++;
} else if (xflag != 0) break; // ***Hack 2***
e0 += A0;
e1 += A1;
e2 += A2;
}
t0 += B0;
t1 += B1;
t2 += B2;
}
}
|