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