I have a problem calculating the scissor rectangle of a box.
This only seems to happen with a long and narrow box when the camera direction is almost the same as the “long” side of the box. (It is not in the box.)
Shot: http://tenebrae.sourceforge.net/tenebrae2/broken.jpg
The box is about double the height as you see in the shot so there is a part of it behind the near plane. It works nomally untill suddenly the box “flips” over. I tried checking for w < 0 but that doesn’t fix it. (As it only uses the 4 vertices before the front plane then.)
…
This is the code used to calculate it. (But well, I hate reading the posted code here myself…) It just projects the 8 points.
I tried using gluProject, but it gives exacly the same results.
for (i=1; i<=8; i++) {
float *v = &verts[i*3];
point[0] = v[0];
point[1] = v[1];
point[2] = v[2];
point[3] = 1.0f;Mat_Mul_1x4_4x4(point, modelviewproj, res); px = (res[0]*(1/res[3])+1.0) * 0.5 * r_Iviewport[2] + r_Iviewport[0]; py = (res[1]*(1/res[3])+1.0) * 0.5 * r_Iviewport[3] + r_Iviewport[1]; if (px > maxx) maxx = px; if (px < minx) minx = px; if (py > maxy) maxy = py; if (py < miny) miny = py;
}
Charles