--- ray/src/hd/rhd_qtree2r.c 1997/11/25 16:51:41 3.1 +++ ray/src/hd/rhd_qtree2r.c 2004/01/01 11:21:55 3.6 @@ -1,9 +1,6 @@ -/* Copyright (c) 1997 Silicon Graphics, Inc. */ - #ifndef lint -static char SCCSid[] = "$SunId$ SGI"; +static const char RCSid[] = "$Id: rhd_qtree2r.c,v 3.6 2004/01/01 11:21:55 schorsch Exp $"; #endif - /* * Quadtree display support routines for rectangle output. */ @@ -12,11 +9,19 @@ static char SCCSid[] = "$SunId$ SGI"; #include "rhd_qtree.h" -static -redraw(tp, x0, y0, x1, y1, l) /* mark portion of a tree for redraw */ -register RTREE *tp; -int x0, y0, x1, y1; -int l[2][2]; +static void redraw(RTREE *tp, int x0, int y0, int x1, int y1, int l[2][2]); +static void update( BYTE ca[3], RTREE *tp, int x0, int y0, int x1, int y1); + + +static void +redraw( /* mark portion of a tree for redraw */ + register RTREE *tp, + int x0, + int y0, + int x1, + int y1, + int l[2][2] +) { int quads = CH_ANY; int mx, my; @@ -25,14 +30,14 @@ int l[2][2]; mx = (x0 + x1) >> 1; my = (y0 + y1) >> 1; /* see what to do */ - if (l[0][0] >= mx) - quads &= ~(CHF(2)|CHF(0)); + if (l[0][0] > mx) + quads &= ~(CHF(UL)|CHF(DL)); else if (l[0][1] < mx) - quads &= ~(CHF(3)|CHF(1)); - if (l[1][0] >= my) - quads &= ~(CHF(1)|CHF(0)); + quads &= ~(CHF(UR)|CHF(DR)); + if (l[1][0] > my) + quads &= ~(CHF(DR)|CHF(DL)); else if (l[1][1] < my) - quads &= ~(CHF(3)|CHF(2)); + quads &= ~(CHF(UR)|CHF(UL)); tp->flgs |= quads; /* mark quadrants for update */ /* climb the branches */ for (i = 0; i < 4; i++) @@ -42,25 +47,45 @@ int l[2][2]; } -static -update(ca, tp, x0, y0, x1, y1) /* update tree display as needed */ -BYTE ca[3]; /* returned average color */ -register RTREE *tp; -int x0, y0, x1, y1; +static void +update( /* update tree display as needed */ + BYTE ca[3], /* returned average color */ + register RTREE *tp, + int x0, + int y0, + int x1, + int y1 +) { int csm[3], nc; register BYTE *cp; BYTE rgb[3]; + double dpth2[4], d2; int gaps = 0; int mx, my; register int i; + /* compute leaf depths */ + d2 = FHUGE*FHUGE; + for (i = 0; i < 4; i++) + if (tp->flgs & LFF(i)) { + FVECT dv; + register float *wp = qtL.wp[tp->k[i].li]; + + dv[0] = wp[0] - odev.v.vp[0]; + dv[1] = wp[1] - odev.v.vp[1]; + dv[2] = wp[2] - odev.v.vp[2]; + dpth2[i] = DOT(dv,dv); + if (dpth2[i] < d2) + d2 = dpth2[i]; + } + d2 *= (1.+qtDepthEps)*(1.+qtDepthEps); /* compute midpoint */ mx = (x0 + x1) >> 1; my = (y0 + y1) >> 1; + /* draw leaves */ csm[0] = csm[1] = csm[2] = nc = 0; - /* do leaves first */ for (i = 0; i < 4; i++) { - if (tp->flgs & LFF(i)) { + if (tp->flgs & LFF(i) && dpth2[i] <= d2) { cp = qtL.rgb[tp->k[i].li]; csm[0] += cp[0]; csm[1] += cp[1]; csm[2] += cp[2]; nc++; @@ -70,7 +95,7 @@ int x0, y0, x1, y1; } else if ((tp->flgs & CHBRF(i)) == CHF(i)) gaps |= 1<flgs & CHBRF(i)) == CHBRF(i)) { update(rgb, tp->k[i].b, i&01 ? mx : x0, i&02 ? my : y0, @@ -92,21 +117,27 @@ int x0, y0, x1, y1; } -qtRedraw(x0, y0, x1, y1) /* redraw part or all of our screen */ -int x0, y0, x1, y1; +extern void +qtRedraw( /* redraw part or all of our screen */ + int x0, + int y0, + int x1, + int y1 +) { int lim[2][2]; if (is_stump(&qtrunk)) return; - if (!qtMapLeaves((lim[0][0]=x0) <= 0 & (lim[1][0]=y0) <= 0 & - (lim[0][1]=x1) >= odev.hres-1 & (lim[1][1]=y1) >= odev.vres-1)) + if (!qtMapLeaves(((lim[0][0]=x0) <= 0) & ((lim[1][0]=y0) <= 0) & + ((lim[0][1]=x1) >= odev.hres-1) & ((lim[1][1]=y1) >= odev.vres-1))) return; redraw(&qtrunk, 0, 0, odev.hres, odev.vres, lim); } -qtUpdate() /* update our tree display */ +extern void +qtUpdate(void) /* update our tree display */ { BYTE ca[3];