public void Draw(Raster r) {
int width = r.getWidth();
int height = r.getHeight();
if (!triangleSetup(width, height)) return;
int x, y;
int A0 = edge[0].A; int B0 = edge[0].B;
int A1 = edge[1].A; int B1 = edge[1].B;
int A2 = edge[2].A; 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 *= width;
yMax *= width;
// .... scan convert triangle ....
for (y = yMin; y <= yMax; y += width) {
int e0 = t0;
int e1 = t1;
int e2 = t2;
boolean beenInside = false;
for (x = xMin; x <= xMax; x++) {
if ((e0|e1|e2) >= 0) { // all 3 edges must be >= 0
r.pixel[y+x] = color;
beenInside = true;
} else if (beenInside) break;
e0 += A0;
e1 += A1;
e2 += A2;
}
t0 += B0;
t1 += B1;
t2 += B2;
}
}
|