Modified Triangle Code
.
.
PlaneEqn(uPlane, (u0*w0), (u1*w1), (u2*w2));
PlaneEqn(vPlane, (v0*w0), (v1*w1), (v2*w2));
PlaneEqn(wPlane, w0, w1, w2);
.
.
for (y = yMin; y <= yMax; y += raster.width) {
e0 = t0; e1 = t1; e2 = t2;
u = tu; v = tv; w = tw; z = tz;
boolean beenInside = false;
for (x = xMin; x <= xMax; x++) {
if ((e0 >= 0) && (e1 >= 0) && (e2 >= 0))) {
int iz = (int) z;
if (iz <= raster.zbuff[y+x]) {
float denom = 1.0f / w;
int uval = (int) (u * denom + 0.5f);
uval = tile(uval, texture.width);
int vval = (int) (v * denom + 0.5f);
vval = tile(vval, texture.height);
int pix = texture.getPixel(uval, vval);
if ((pix & 0xff000000) != 0) {
raster.pixel[y+x] = pix;
raster.zbuff[y+x] = iz;
}
}
beenInside = true;
} else if (beenInside) break;
e0 += A0; e1 += A1; e2 += A2;
z += Az; u += Au; v += Av; w += Aw;
}
t0 += B0; t1 += B1; t2 += B2;
tz += Bz; tu += Bu; tv += Bv; tw += Bw;
}
|