| 1 |
< |
/* Copyright (c) 1997 Silicon Graphics, Inc. */ |
| 1 |
> |
/* Copyright (c) 1998 Silicon Graphics, Inc. */ |
| 2 |
|
|
| 3 |
|
#ifndef lint |
| 4 |
|
static char SCCSid[] = "$SunId$ SGI"; |
| 10 |
|
*/ |
| 11 |
|
|
| 12 |
|
#include "standard.h" |
| 13 |
– |
#include "rhd_qtree.h" |
| 14 |
– |
|
| 13 |
|
#include <X11/Xlib.h> |
| 14 |
|
#include <X11/cursorfont.h> |
| 15 |
|
#include <X11/Xutil.h> |
| 16 |
< |
|
| 16 |
> |
#include "rhd_qtree.h" |
| 17 |
|
#include "x11icon.h" |
| 18 |
|
|
| 19 |
+ |
#ifndef RAYQLEN |
| 20 |
+ |
#define RAYQLEN 50000 /* max. rays to queue before flush */ |
| 21 |
+ |
#endif |
| 22 |
+ |
|
| 23 |
|
#ifndef FEQ |
| 24 |
|
#define FEQ(a,b) ((a)-(b) <= FTINY && (a)-(b) >= -FTINY) |
| 25 |
|
#endif |
| 83 |
|
for (cp = tail; *cp && *cp != '.'; cp++) |
| 84 |
|
; |
| 85 |
|
if (cp-tail == 3 && !strncmp(tail, "x11", 3)) |
| 86 |
< |
return(TM_F_CAMERA); |
| 86 |
> |
return(TM_F_CAMERA|TM_F_NOSTDERR); |
| 87 |
|
if (cp-tail == 4 && !strncmp(tail, "x11h", 4)) |
| 88 |
< |
return(TM_F_HUMAN); |
| 88 |
> |
return(TM_F_HUMAN|TM_F_NOSTDERR); |
| 89 |
|
error(USER, "illegal driver name"); |
| 90 |
|
} |
| 91 |
|
|
| 94 |
|
char *id; |
| 95 |
|
{ |
| 96 |
|
extern char *getenv(); |
| 97 |
< |
char *gv; |
| 97 |
> |
static RGBPRIMS myprims = STDPRIMS; |
| 98 |
> |
char *ev; |
| 99 |
|
double gamval = GAMMA; |
| 100 |
+ |
RGBPRIMP dpri = stdprims; |
| 101 |
|
int nplanes; |
| 102 |
|
XSetWindowAttributes ourwinattr; |
| 103 |
|
XWMHints ourxwmhints; |
| 130 |
|
ourwhite = WhitePixel(ourdisplay,ourscreen); |
| 131 |
|
} |
| 132 |
|
/* set gamma and tone mapping */ |
| 133 |
< |
if ((gv = XGetDefault(ourdisplay, "radiance", "gamma")) != NULL |
| 134 |
< |
|| (gv = getenv("DISPLAY_GAMMA")) != NULL) |
| 135 |
< |
gamval = atof(gv); |
| 136 |
< |
if (tmInit(mytmflags(), stdprims, gamval) == NULL) |
| 133 |
> |
if ((ev = XGetDefault(ourdisplay, "radiance", "gamma")) != NULL |
| 134 |
> |
|| (ev = getenv("DISPLAY_GAMMA")) != NULL) |
| 135 |
> |
gamval = atof(ev); |
| 136 |
> |
if ((ev = getenv("DISPLAY_PRIMARIES")) != NULL && |
| 137 |
> |
sscanf(ev, "%f %f %f %f %f %f %f %f", |
| 138 |
> |
&myprims[RED][CIEX],&myprims[RED][CIEY], |
| 139 |
> |
&myprims[GRN][CIEX],&myprims[GRN][CIEY], |
| 140 |
> |
&myprims[BLU][CIEX],&myprims[BLU][CIEY], |
| 141 |
> |
&myprims[WHT][CIEX],&myprims[WHT][CIEY]) >= 6) |
| 142 |
> |
dpri = myprims; |
| 143 |
> |
if (tmInit(mytmflags(), dpri, gamval) == NULL) |
| 144 |
|
error(SYSTEM, "not enough memory in dev_open"); |
| 145 |
|
/* open window */ |
| 146 |
|
ourwinattr.background_pixel = ourblack; |
| 169 |
|
oursizhints.min_height = MINHEIGHT; |
| 170 |
|
oursizhints.flags = PMinSize; |
| 171 |
|
XSetNormalHints(ourdisplay, gwind, &oursizhints); |
| 161 |
– |
/* map the window and get its size */ |
| 162 |
– |
XMapWindow(ourdisplay, gwind); |
| 163 |
– |
dev_input(); |
| 164 |
– |
/* allocate our leaf pile */ |
| 165 |
– |
if (!qtAllocLeaves(DisplayWidth(ourdisplay,ourscreen) * |
| 166 |
– |
DisplayHeight(ourdisplay,ourscreen) / |
| 167 |
– |
(qtMinNodesiz*qtMinNodesiz))) |
| 168 |
– |
error(SYSTEM, "insufficient memory for leaf storage"); |
| 169 |
– |
|
| 172 |
|
/* figure out sensible view */ |
| 173 |
|
pwidth = (double)DisplayWidthMM(ourdisplay, ourscreen) / |
| 174 |
|
DisplayWidth(ourdisplay, ourscreen); |
| 175 |
|
pheight = (double)DisplayHeightMM(ourdisplay, ourscreen) / |
| 176 |
|
DisplayHeight(ourdisplay, ourscreen); |
| 177 |
|
copystruct(&odev.v, &stdview); |
| 176 |
– |
odev.name = id; |
| 178 |
|
odev.v.type = VT_PER; |
| 179 |
< |
odev.v.horiz = 2.*180./PI * atan(0.5/VIEWDIST*pwidth*odev.hres); |
| 180 |
< |
odev.v.vert = 2.*180./PI * atan(0.5/VIEWDIST*pheight*odev.vres); |
| 179 |
> |
/* map the window and get its size */ |
| 180 |
> |
XMapWindow(ourdisplay, gwind); |
| 181 |
> |
dev_input(); /* sets size and view angles */ |
| 182 |
> |
/* allocate our leaf pile */ |
| 183 |
> |
if (!qtAllocLeaves(DisplayWidth(ourdisplay,ourscreen) * |
| 184 |
> |
DisplayHeight(ourdisplay,ourscreen) * 3 / |
| 185 |
> |
(qtMinNodesiz*qtMinNodesiz*2))) |
| 186 |
> |
error(SYSTEM, "insufficient memory for leaf storage"); |
| 187 |
> |
odev.name = id; |
| 188 |
|
odev.ifd = ConnectionNumber(ourdisplay); |
| 189 |
|
} |
| 190 |
|
|
| 206 |
|
} |
| 207 |
|
|
| 208 |
|
|
| 209 |
+ |
|
| 210 |
+ |
dev_clear() /* clear our quadtree */ |
| 211 |
+ |
{ |
| 212 |
+ |
qtCompost(100); |
| 213 |
+ |
if (ncolors > 0) |
| 214 |
+ |
new_ctab(ncolors); |
| 215 |
+ |
rayqleft = 0; /* hold off update */ |
| 216 |
+ |
} |
| 217 |
+ |
|
| 218 |
+ |
|
| 219 |
|
int |
| 220 |
|
dev_view(nv) /* assign new driver view */ |
| 221 |
|
VIEW *nv; |
| 222 |
|
{ |
| 223 |
|
if (nv->type == VT_PAR || /* check view legality */ |
| 224 |
< |
nv->horiz > 160. || nv->vert > 160.) { |
| 224 |
> |
nv->horiz > 160. || nv->vert > 160.) { |
| 225 |
|
error(COMMAND, "illegal view type/angle"); |
| 226 |
|
nv->type = VT_PER; |
| 227 |
|
nv->horiz = odev.v.horiz; |
| 240 |
|
int dh = DisplayHeight(ourdisplay,ourscreen); |
| 241 |
|
|
| 242 |
|
dw -= 25; /* for window frame */ |
| 243 |
< |
dh -= 100; |
| 243 |
> |
dh -= 50; |
| 244 |
|
odev.hres = 2.*VIEWDIST/pwidth * |
| 245 |
|
tan(PI/180./2.*nv->horiz); |
| 246 |
|
odev.vres = 2.*VIEWDIST/pheight * |
| 254 |
|
odev.vres = dh; |
| 255 |
|
} |
| 256 |
|
XResizeWindow(ourdisplay, gwind, odev.hres, odev.vres); |
| 257 |
+ |
dev_input(); /* wait for resize event */ |
| 258 |
|
} |
| 259 |
|
copystruct(&odev.v, nv); |
| 260 |
|
} |
| 263 |
|
} |
| 264 |
|
|
| 265 |
|
|
| 266 |
+ |
dev_auxcom(cmd, args) /* process an auxiliary command */ |
| 267 |
+ |
char *cmd, *args; |
| 268 |
+ |
{ |
| 269 |
+ |
sprintf(errmsg, "%s: unknown command", cmd); |
| 270 |
+ |
error(COMMAND, errmsg); |
| 271 |
+ |
} |
| 272 |
+ |
|
| 273 |
+ |
|
| 274 |
+ |
VIEW * |
| 275 |
+ |
dev_auxview(n, hvres) /* return nth auxiliary view */ |
| 276 |
+ |
int n; |
| 277 |
+ |
int hvres[2]; |
| 278 |
+ |
{ |
| 279 |
+ |
if (n) |
| 280 |
+ |
return(NULL); |
| 281 |
+ |
hvres[0] = odev.hres; hvres[1] = odev.vres; |
| 282 |
+ |
return(&odev.v); |
| 283 |
+ |
} |
| 284 |
+ |
|
| 285 |
+ |
|
| 286 |
|
int |
| 287 |
|
dev_input() /* get X11 input */ |
| 288 |
|
{ |
| 291 |
|
do |
| 292 |
|
getevent(); |
| 293 |
|
|
| 294 |
< |
while (XQLength(ourdisplay) > 0); |
| 294 |
> |
while (XPending(ourdisplay) > 0); |
| 295 |
|
|
| 296 |
+ |
odev.inpready = 0; |
| 297 |
+ |
|
| 298 |
|
return(inpresflags); |
| 299 |
|
} |
| 300 |
|
|
| 321 |
|
dev_flush() /* flush output */ |
| 322 |
|
{ |
| 323 |
|
qtUpdate(); |
| 324 |
< |
return(XPending(ourdisplay)); |
| 324 |
> |
rayqleft = RAYQLEN; |
| 325 |
> |
return(odev.inpready = XPending(ourdisplay)); |
| 326 |
|
} |
| 327 |
|
|
| 328 |
|
|
| 462 |
|
int dp[2][2]; |
| 463 |
|
FVECT wp[2]; |
| 464 |
|
{ |
| 465 |
< |
static FVECT vmin = {0.,0.,0.}, vmax = {1.,1.,FHUGE}; |
| 466 |
< |
FVECT ip[2]; |
| 467 |
< |
/* not exactly right, but who cares? */ |
| 468 |
< |
viewloc(ip[0], &odev.v, wp[0]); |
| 469 |
< |
viewloc(ip[1], &odev.v, wp[1]); |
| 465 |
> |
static FVECT vmin = {0.,0.,0.}, vmax = {1.-FTINY,1.-FTINY,FHUGE}; |
| 466 |
> |
FVECT wpc[2], ip[2]; |
| 467 |
> |
double d, d0, d1; |
| 468 |
> |
/* check for points behind view */ |
| 469 |
> |
d = DOT(odev.v.vp, odev.v.vdir); |
| 470 |
> |
d0 = DOT(wp[0], odev.v.vdir) - d; |
| 471 |
> |
d1 = DOT(wp[1], odev.v.vdir) - d; |
| 472 |
> |
/* work on copy of world points */ |
| 473 |
> |
if (d0 <= d1) { |
| 474 |
> |
VCOPY(wpc[0], wp[0]); VCOPY(wpc[1], wp[1]); |
| 475 |
> |
} else { |
| 476 |
> |
d = d0; d0 = d1; d1 = d; |
| 477 |
> |
VCOPY(wpc[1], wp[0]); VCOPY(wpc[0], wp[1]); |
| 478 |
> |
} |
| 479 |
> |
if (d0 <= FTINY) { |
| 480 |
> |
if (d1 <= FTINY) return(0); |
| 481 |
> |
VSUB(wpc[0], wpc[0], wpc[1]); |
| 482 |
> |
d = .99*d1/(d1-d0); |
| 483 |
> |
VSUM(wpc[0], wpc[1], wpc[0], d); |
| 484 |
> |
} |
| 485 |
> |
/* get view coordinates and clip to window */ |
| 486 |
> |
viewloc(ip[0], &odev.v, wpc[0]); |
| 487 |
> |
viewloc(ip[1], &odev.v, wpc[1]); |
| 488 |
|
if (!clip(ip[0], ip[1], vmin, vmax)) |
| 489 |
|
return(0); |
| 490 |
|
dp[0][0] = ip[0][0]*odev.hres; |
| 515 |
|
static BYTE gridrgb[3] = {0x0, 0xff, 0xff}; |
| 516 |
|
unsigned long pixel; |
| 517 |
|
|
| 458 |
– |
if (!mapped || odev.v.type != VT_PER) |
| 459 |
– |
return; |
| 518 |
|
if (ncolors > 0) |
| 519 |
|
pixel = pixval[get_pixel(gridrgb, xnewcolr)]; |
| 520 |
|
else |
| 530 |
|
int dx, dy, mov, orb; |
| 531 |
|
{ |
| 532 |
|
VIEW nv; |
| 533 |
< |
FVECT v1; |
| 533 |
> |
FVECT odir, v1; |
| 534 |
|
double d; |
| 535 |
|
register int li; |
| 536 |
|
/* start with old view */ |
| 539 |
|
if (mov | orb) { |
| 540 |
|
if ((li = qtFindLeaf(dx, dy)) < 0) |
| 541 |
|
return(0); /* not on window */ |
| 542 |
< |
VSUM(nv.vdir, qtL.wp[li], nv.vp, -1.); |
| 542 |
> |
VSUM(odir, qtL.wp[li], nv.vp, -1.); |
| 543 |
|
} else { |
| 544 |
|
if (viewray(nv.vp, nv.vdir, &odev.v, |
| 545 |
|
(dx+.5)/odev.hres, (dy+.5)/odev.vres) < -FTINY) |
| 546 |
|
return(0); /* outside view */ |
| 547 |
|
} |
| 548 |
|
if (orb && mov) { /* orbit left/right */ |
| 549 |
< |
spinvector(nv.vdir, nv.vdir, nv.vup, MOVDEG*PI/180.*mov); |
| 550 |
< |
VSUM(nv.vp, qtL.wp[li], nv.vdir, -1.); |
| 549 |
> |
spinvector(odir, odir, nv.vup, d=MOVDEG*PI/180.*mov); |
| 550 |
> |
VSUM(nv.vp, qtL.wp[li], odir, -1.); |
| 551 |
> |
spinvector(nv.vdir, nv.vdir, nv.vup, d); |
| 552 |
|
} else if (orb) { /* orbit up/down */ |
| 553 |
< |
fcross(v1, nv.vdir, nv.vup); |
| 553 |
> |
fcross(v1, odir, nv.vup); |
| 554 |
|
if (normalize(v1) == 0.) |
| 555 |
|
return(0); |
| 556 |
< |
spinvector(nv.vdir, nv.vdir, v1, MOVDEG*PI/180.*orb); |
| 557 |
< |
VSUM(nv.vp, qtL.wp[li], nv.vdir, -1.); |
| 556 |
> |
spinvector(odir, odir, v1, d=MOVDEG*PI/180.*orb); |
| 557 |
> |
VSUM(nv.vp, qtL.wp[li], odir, -1.); |
| 558 |
> |
spinvector(nv.vdir, nv.vdir, v1, d); |
| 559 |
|
} else if (mov) { /* move forward/backward */ |
| 560 |
|
d = MOVPCT/100. * mov; |
| 561 |
< |
VSUM(nv.vp, nv.vp, nv.vdir, d); |
| 561 |
> |
VSUM(nv.vp, nv.vp, odir, d); |
| 562 |
|
} |
| 563 |
|
if (!mov ^ !orb && headlocked) { /* restore head height */ |
| 564 |
|
VSUM(v1, odev.v.vp, nv.vp, -1.); |
| 659 |
|
if (ncolors > 0) |
| 660 |
|
new_ctab(ncolors); |
| 661 |
|
inpresflags |= DFL(DC_REDRAW); /* resend values from server */ |
| 662 |
+ |
rayqleft = 0; /* hold off update */ |
| 663 |
|
return; |
| 664 |
|
case 'K': /* kill rtrace process(es) */ |
| 665 |
|
inpresflags |= DFL(DC_KILL); |