tbase = ix_buf[ibase++] << 1
vbase = tbase << 1;
poss[2].x = pos_buf[vbase++]; uv_2u = tx_buf[tbase++];
poss[2].y = pos_buf[vbase++]; uv_2v = tx_buf[tbase];
if (z_clip && (pos_buf[vbase] < 0 || pos_buf[vbase] > 1)) {continue;}
var vAd = [ poss[1].x – poss[0].x , poss[1].y – poss[0].y ];
var vBd = [ poss[2].x – poss[0].x , poss[2].y – poss[0].y ];
var vCd = [ poss[2].x – poss[1].x , poss[2].y – poss[1].y ];
// z component of cross product < 0 ?
if( (((vAd[0] * vCd[1]) – (vAd[1] * vCd[0]))*culling) < 0)
continue;
if (color_polygon) {
g.fillStyle = uv_0u;
g.beginPath();
g.moveTo(poss[0].x, poss[0].y);
g.lineTo(poss[1].x, poss[1].y);
g.lineTo(poss[2].x, poss[2].y);
g.fill();
continue;
}
var vA = [ uv_1u – uv_0u , uv_1v – uv_0v ];
var vB = [ uv_2u – uv_0u , uv_2v – uv_0v ];
vA[0] *= w;
vA[1] *= h;
vB[0] *= w;
vB[1] *= h;
m._11 = vA[0];
m._12 = vA[1];
m._21 = vB[0];
m._22 = vB[1];
var im = m.getInvert();
if (!im) { continue;}
var a = im._11 * vAd[0] + im._12 * vBd[0];
var b = im._21 * vAd[0] + im._22 * vBd[0];
var c = im._11 * vAd[1] + im._12 * vBd[1];
var d = im._21 * vAd[1] + im._22 * vBd[1];
var wu = uv_0u * w;
var hv = uv_0v * h;
var du = wu * a + hv * b;
var dv = wu * c + hv * d;
g.save();
g.beginPath();
g.moveTo(poss[0].x, poss[0].y);
g.lineTo(poss[1].x, poss[1].y);
g.lineTo(poss[2].x, poss[2].y);
g.clip();
g.transform(a, c, b, d, poss[0].x – du, poss[0].y – dv);
// bounds
var bx = [wu, wu+vA[0], wu+vB[0]];
var by = [hv, hv+vA[1], hv+vB[1]];
bx.sort(P3D.num_cmp);