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 |
28 |
|
|
25 |
– |
#define CTRL(c) ((c)-'@') |
26 |
– |
|
29 |
|
#define GAMMA 2.2 /* default gamma correction */ |
30 |
|
|
31 |
< |
#define MOVPCT 10 /* percent distance to move */ |
31 |
> |
#define MOVPCT 7 /* percent distance to move /frame */ |
32 |
|
#define MOVDIR(b) ((b)==Button1 ? 1 : (b)==Button2 ? 0 : -1) |
33 |
+ |
#define MOVDEG (-5) /* degrees to orbit CW/down /frame */ |
34 |
+ |
#define MOVORB(s) ((s)&ShiftMask ? 1 : (s)&ControlMask ? -1 : 0) |
35 |
|
|
36 |
|
#define MINWIDTH 480 /* minimum graphics window width */ |
37 |
|
#define MINHEIGHT 400 /* minimum graphics window height */ |
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.) { |
227 |
+ |
error(COMMAND, "illegal view type/angle"); |
228 |
+ |
nv->type = VT_PER; |
229 |
+ |
nv->horiz = odev.v.horiz; |
230 |
+ |
nv->vert = odev.v.vert; |
231 |
+ |
return(0); |
232 |
+ |
} |
233 |
+ |
if (nv->vfore > FTINY) { |
234 |
+ |
error(COMMAND, "cannot handle fore clipping"); |
235 |
+ |
nv->vfore = 0.; |
236 |
+ |
return(0); |
237 |
+ |
} |
238 |
|
if (nv != &odev.v) { |
239 |
|
if (!FEQ(nv->horiz,odev.v.horiz) || /* resize window? */ |
240 |
|
!FEQ(nv->vert,odev.v.vert)) { |
241 |
< |
odev.hres = 2.*VIEWDIST*tan(PI/180./2.*nv->horiz) / |
242 |
< |
pwidth; |
243 |
< |
odev.vres = 2.*VIEWDIST*tan(PI/180./2.*nv->vert) / |
244 |
< |
pheight; |
241 |
> |
int dw = DisplayWidth(ourdisplay,ourscreen); |
242 |
> |
int dh = DisplayHeight(ourdisplay,ourscreen); |
243 |
> |
|
244 |
> |
dw -= 25; /* for window frame */ |
245 |
> |
dh -= 50; |
246 |
> |
odev.hres = 2.*VIEWDIST/pwidth * |
247 |
> |
tan(PI/180./2.*nv->horiz); |
248 |
> |
odev.vres = 2.*VIEWDIST/pheight * |
249 |
> |
tan(PI/180./2.*nv->vert); |
250 |
> |
if (odev.hres > dw) { |
251 |
> |
odev.vres = dw * odev.vres / odev.hres; |
252 |
> |
odev.hres = dw; |
253 |
> |
} |
254 |
> |
if (odev.vres > dh) { |
255 |
> |
odev.hres = dh * odev.hres / odev.vres; |
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 |
|
} |
263 |
|
qtReplant(); |
264 |
+ |
return(1); |
265 |
|
} |
266 |
|
|
267 |
|
|
301 |
|
dev_flush() /* flush output */ |
302 |
|
{ |
303 |
|
qtUpdate(); |
304 |
+ |
rayqleft = RAYQLEN; |
305 |
|
return(XPending(ourdisplay)); |
306 |
|
} |
307 |
|
|
477 |
|
static BYTE gridrgb[3] = {0x0, 0xff, 0xff}; |
478 |
|
unsigned long pixel; |
479 |
|
|
480 |
< |
if (!mapped || odev.v.type != VT_PER) |
480 |
> |
if (!mapped) |
481 |
|
return; |
482 |
|
if (ncolors > 0) |
483 |
|
pixel = pixval[get_pixel(gridrgb, xnewcolr)]; |
490 |
|
|
491 |
|
|
492 |
|
static |
493 |
< |
moveview(dx, dy, move) /* move our view */ |
494 |
< |
int dx, dy, move; |
493 |
> |
moveview(dx, dy, mov, orb) /* move our view */ |
494 |
> |
int dx, dy, mov, orb; |
495 |
|
{ |
496 |
|
VIEW nv; |
497 |
+ |
FVECT odir, v1; |
498 |
|
double d; |
499 |
< |
register int i, li; |
499 |
> |
register int li; |
500 |
|
/* start with old view */ |
501 |
|
copystruct(&nv, &odev.v); |
502 |
|
/* change view direction */ |
503 |
< |
if (move) { |
503 |
> |
if (mov | orb) { |
504 |
|
if ((li = qtFindLeaf(dx, dy)) < 0) |
505 |
|
return(0); /* not on window */ |
506 |
< |
for (i = 0; i < 3; i++) |
456 |
< |
nv.vdir[i] = qtL.wp[li][i] - nv.vp[i]; |
506 |
> |
VSUM(odir, qtL.wp[li], nv.vp, -1.); |
507 |
|
} else { |
508 |
|
if (viewray(nv.vp, nv.vdir, &odev.v, |
509 |
|
(dx+.5)/odev.hres, (dy+.5)/odev.vres) < -FTINY) |
510 |
|
return(0); /* outside view */ |
511 |
|
} |
512 |
< |
/* move viewpoint */ |
513 |
< |
if (move > 0) |
514 |
< |
for (i = 0; i < 3; i++) |
515 |
< |
nv.vp[i] += MOVPCT/100. * nv.vdir[i]; |
516 |
< |
else if (move < 0) |
517 |
< |
for (i = 0; i < 3; i++) |
518 |
< |
nv.vp[i] -= MOVPCT/100. * nv.vdir[i]; |
519 |
< |
if (move && headlocked) { |
520 |
< |
d = 0; /* bring head back to same height */ |
521 |
< |
for (i = 0; i < 3; i++) |
522 |
< |
d += odev.v.vup[i] * (odev.v.vp[i] - nv.vp[i]); |
523 |
< |
for (i = 0; i < 3; i++) |
524 |
< |
nv.vp[i] += d * odev.v.vup[i]; |
512 |
> |
if (orb && mov) { /* orbit left/right */ |
513 |
> |
spinvector(odir, odir, nv.vup, d=MOVDEG*PI/180.*mov); |
514 |
> |
VSUM(nv.vp, qtL.wp[li], odir, -1.); |
515 |
> |
spinvector(nv.vdir, nv.vdir, nv.vup, d); |
516 |
> |
} else if (orb) { /* orbit up/down */ |
517 |
> |
fcross(v1, odir, nv.vup); |
518 |
> |
if (normalize(v1) == 0.) |
519 |
> |
return(0); |
520 |
> |
spinvector(odir, odir, v1, d=MOVDEG*PI/180.*orb); |
521 |
> |
VSUM(nv.vp, qtL.wp[li], odir, -1.); |
522 |
> |
spinvector(nv.vdir, nv.vdir, v1, d); |
523 |
> |
} else if (mov) { /* move forward/backward */ |
524 |
> |
d = MOVPCT/100. * mov; |
525 |
> |
VSUM(nv.vp, nv.vp, odir, d); |
526 |
|
} |
527 |
+ |
if (!mov ^ !orb && headlocked) { /* restore head height */ |
528 |
+ |
VSUM(v1, odev.v.vp, nv.vp, -1.); |
529 |
+ |
d = DOT(v1, odev.v.vup); |
530 |
+ |
VSUM(nv.vp, nv.vp, odev.v.vup, d); |
531 |
+ |
} |
532 |
|
if (setview(&nv) != NULL) |
533 |
|
return(0); /* illegal view */ |
534 |
|
dev_view(&nv); |
535 |
< |
inpresflags |= DEV_NEWVIEW; |
535 |
> |
inpresflags |= DFL(DC_SETVIEW); |
536 |
|
return(1); |
537 |
|
} |
538 |
|
|
541 |
|
getmove(ebut) /* get view change */ |
542 |
|
XButtonPressedEvent *ebut; |
543 |
|
{ |
544 |
< |
int whichbutton = ebut->button; |
544 |
> |
int movdir = MOVDIR(ebut->button); |
545 |
> |
int movorb = MOVORB(ebut->state); |
546 |
|
int oldnodesiz = qtMinNodesiz; |
547 |
|
Window rootw, childw; |
548 |
|
int rootx, rooty, wx, wy; |
558 |
|
&rootx, &rooty, &wx, &wy, &statemask)) |
559 |
|
break; /* on another screen */ |
560 |
|
|
561 |
< |
if (!moveview(wx, odev.vres-1-wy, MOVDIR(whichbutton))) { |
561 |
> |
if (!moveview(wx, odev.vres-1-wy, movdir, movorb)) { |
562 |
|
sleep(1); |
563 |
|
continue; |
564 |
|
} |
566 |
|
qtUpdate(); |
567 |
|
draw_grids(); |
568 |
|
} |
569 |
< |
if (!(inpresflags & DEV_NEWVIEW)) { /* do final motion */ |
570 |
< |
whichbutton = levptr(XButtonReleasedEvent)->button; |
569 |
> |
if (!(inpresflags & DFL(DC_SETVIEW))) { /* do final motion */ |
570 |
> |
movdir = MOVDIR(levptr(XButtonReleasedEvent)->button); |
571 |
|
wx = levptr(XButtonReleasedEvent)->x; |
572 |
|
wy = levptr(XButtonReleasedEvent)->y; |
573 |
< |
moveview(wx, odev.vres-1-wy, MOVDIR(whichbutton)); |
573 |
> |
moveview(wx, odev.vres-1-wy, movdir, movorb); |
574 |
|
} |
575 |
|
dev_flush(); |
576 |
|
|
595 |
|
case 'H': /* turn off height motion lock */ |
596 |
|
headlocked = 0; |
597 |
|
return; |
598 |
< |
case CTRL('S'): |
598 |
> |
case 'l': /* retrieve last view */ |
599 |
> |
inpresflags |= DFL(DC_LASTVIEW); |
600 |
> |
return; |
601 |
|
case 'p': /* pause computation */ |
602 |
< |
inpresflags |= DEV_WAIT; |
602 |
> |
inpresflags |= DFL(DC_PAUSE); |
603 |
|
return; |
604 |
|
case 'v': /* spit out view */ |
605 |
< |
inpresflags |= DEV_PUTVIEW; |
605 |
> |
inpresflags |= DFL(DC_GETVIEW); |
606 |
|
return; |
548 |
– |
case CTRL('Q'): |
607 |
|
case '\n': |
608 |
|
case '\r': /* resume computation */ |
609 |
< |
inpresflags |= DEV_RESUME; |
609 |
> |
inpresflags |= DFL(DC_RESUME); |
610 |
|
return; |
611 |
|
case CTRL('R'): /* redraw screen */ |
612 |
|
if (ncolors > 0) |
614 |
|
qtRedraw(0, 0, odev.hres, odev.vres); |
615 |
|
return; |
616 |
|
case CTRL('L'): /* refresh from server */ |
617 |
< |
if (inpresflags & DEV_REDRAW) |
617 |
> |
if (inpresflags & DFL(DC_REDRAW)) |
618 |
|
return; |
619 |
|
XClearWindow(ourdisplay, gwind); |
620 |
|
draw_grids(); |
622 |
|
qtCompost(100); /* unload the old tree */ |
623 |
|
if (ncolors > 0) |
624 |
|
new_ctab(ncolors); |
625 |
< |
inpresflags |= DEV_REDRAW; /* resend values from server */ |
625 |
> |
inpresflags |= DFL(DC_REDRAW); /* resend values from server */ |
626 |
> |
rayqleft = 0; /* hold off update */ |
627 |
|
return; |
628 |
< |
case CTRL('D'): |
629 |
< |
case 'Q': |
628 |
> |
case 'K': /* kill rtrace process(es) */ |
629 |
> |
inpresflags |= DFL(DC_KILL); |
630 |
> |
break; |
631 |
> |
case 'R': /* restart rtrace */ |
632 |
> |
inpresflags |= DFL(DC_RESTART); |
633 |
> |
break; |
634 |
> |
case 'C': /* clobber holodeck */ |
635 |
> |
inpresflags |= DFL(DC_CLOBBER); |
636 |
> |
break; |
637 |
|
case 'q': /* quit the program */ |
638 |
< |
inpresflags |= DEV_SHUTDOWN; |
638 |
> |
inpresflags |= DFL(DC_QUIT); |
639 |
|
return; |
640 |
|
default: |
641 |
|
XBell(ourdisplay, 0); |
651 |
|
if (odev.hres == 0 || odev.vres == 0) { /* first exposure */ |
652 |
|
odev.hres = eexp->width; |
653 |
|
odev.vres = eexp->height; |
588 |
– |
inpresflags |= DEV_NEWSIZE; |
654 |
|
} |
655 |
|
qtRedraw(eexp->x, odev.vres - eexp->y - eexp->height, |
656 |
|
eexp->x + eexp->width, odev.vres - eexp->y); |
664 |
|
if (ersz->width == odev.hres && ersz->height == odev.vres) |
665 |
|
return; |
666 |
|
|
602 |
– |
if (odev.hres != 0 && odev.vres != 0) { |
603 |
– |
odev.v.horiz = 2.*180./PI * atan(0.5/VIEWDIST*pwidth*odev.hres); |
604 |
– |
odev.v.vert = 2.*180./PI * atan(0.5/VIEWDIST*pheight*odev.vres); |
605 |
– |
inpresflags |= DEV_NEWVIEW; |
606 |
– |
} |
667 |
|
odev.hres = ersz->width; |
668 |
|
odev.vres = ersz->height; |
669 |
|
|
670 |
< |
inpresflags |= DEV_NEWSIZE; |
670 |
> |
odev.v.horiz = 2.*180./PI * atan(0.5/VIEWDIST*pwidth*odev.hres); |
671 |
> |
odev.v.vert = 2.*180./PI * atan(0.5/VIEWDIST*pheight*odev.vres); |
672 |
> |
|
673 |
> |
inpresflags |= DFL(DC_SETVIEW); |
674 |
|
} |