PDA

View Full Version : Degenerate scissor rect?



Pentagram
04-25-2003, 12:40 PM
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 = &amp;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

zeckensack
04-25-2003, 12:42 PM
Originally posted by Pentagram:



for (i=1; i<=8; i++) {
float *v = &amp;verts[i*3];
You're sure these two lines are right?

Pentagram
04-26-2003, 02:07 AM
No it's not that
Altrough it looks fishy... http://www.opengl.org/discussion_boards/ubb/wink.gif but the first vertex in the list is used for something else.
As I said it works if the camera is ortogonal-ish to the "long" side of the box.
See: http://tenebrae.sourceforge.net/tenebrae2/working.jpg


Charles

[This message has been edited by Pentagram (edited 04-26-2003).]