ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/rhd_glx.c
Revision: 3.17
Committed: Thu May 14 13:06:33 1998 UTC (25 years, 11 months ago) by gwlarson
Content type: text/plain
Branch: MAIN
Changes since 3.16: +12 -0 lines
Log Message:
added multiple device view capability

File Contents

# User Rev Content
1 gregl 3.1 /* Copyright (c) 1997 Silicon Graphics, Inc. */
2    
3     #ifndef lint
4     static char SCCSid[] = "$SunId$ SGI";
5     #endif
6    
7     /*
8     * OpenGL GLX driver for holodeck display.
9 gregl 3.2 * Based on x11 driver.
10 gregl 3.1 */
11    
12     #include "standard.h"
13 gregl 3.4 #include "rhd_qtree.h"
14 gregl 3.1
15     #include <GL/glx.h>
16    
17     #include "x11icon.h"
18    
19 gregl 3.10 #ifndef RAYQLEN
20     #define RAYQLEN 50000 /* max. rays to queue before flush */
21     #endif
22    
23 gregl 3.1 #ifndef FEQ
24     #define FEQ(a,b) ((a)-(b) <= FTINY && (a)-(b) >= -FTINY)
25     #endif
26    
27 gregl 3.4 #ifndef MAXCONE
28     #define MAXCONE 16 /* number of different cone sizes */
29 gregl 3.1 #endif
30 gregl 3.4 #ifndef MAXVERT
31 gregl 3.16 #define MAXVERT 64 /* maximum number of cone vertices */
32 gregl 3.1 #endif
33 gregl 3.4 #ifndef MINVERT
34     #define MINVERT 4 /* minimum number of cone vertices */
35 gregl 3.1 #endif
36 gregl 3.4 #ifndef DEPTHFACT
37     #define DEPTHFACT 16. /* multiplier for depth tests */
38 gregl 3.1 #endif
39    
40 gregl 3.2 #define GAMMA 1.4 /* default gamma correction */
41 gregl 3.1
42     #define MOVPCT 7 /* percent distance to move /frame */
43     #define MOVDIR(b) ((b)==Button1 ? 1 : (b)==Button2 ? 0 : -1)
44     #define MOVDEG (-5) /* degrees to orbit CW/down /frame */
45     #define MOVORB(s) ((s)&ShiftMask ? 1 : (s)&ControlMask ? -1 : 0)
46    
47     #define MINWIDTH 480 /* minimum graphics window width */
48     #define MINHEIGHT 400 /* minimum graphics window height */
49    
50     #define VIEWDIST 356 /* assumed viewing distance (mm) */
51    
52     #define BORWIDTH 5 /* border width */
53    
54     #define ourscreen DefaultScreen(ourdisplay)
55     #define ourroot RootWindow(ourdisplay,ourscreen)
56     #define ourmask (StructureNotifyMask|ExposureMask|KeyPressMask|\
57     ButtonPressMask|ButtonReleaseMask)
58    
59     #define levptr(etype) ((etype *)&currentevent)
60    
61     struct driver odev; /* global device driver structure */
62    
63     static XEvent currentevent; /* current event */
64    
65     static int mapped = 0; /* window is mapped? */
66     static unsigned long ourblack=0, ourwhite=~0;
67    
68     static Display *ourdisplay = NULL; /* our display */
69     static XVisualInfo *ourvinf; /* our visual information */
70     static Window gwind = 0; /* our graphics window */
71     static GLXContext gctx; /* our GLX context */
72    
73     static double pwidth, pheight; /* pixel dimensions (mm) */
74    
75 gregl 3.4 static double curzmax = 1e4; /* current depth upper limit */
76     static double nxtzmax = 0.; /* maximum (finite) depth so far */
77 gregl 3.1
78 gregl 3.4 static struct {
79     double rad; /* cone radius */
80     int nverts; /* number of vertices */
81     FVECT *va; /* allocated vertex array */
82     } cone[MAXCONE]; /* precomputed cones for drawing */
83    
84 gregl 3.1 static int inpresflags; /* input result flags */
85    
86     static int headlocked = 0; /* lock vertical motion */
87    
88     static int resizewindow(), getevent(), getkey(), moveview(),
89 gregl 3.4 initcones(), freecones(),
90     getmove(), fixwindow(), mytmflags();
91 gregl 3.1
92    
93     dev_open(id) /* initialize X11 driver */
94     char *id;
95     {
96     extern char *getenv();
97 gregl 3.15 static RGBPRIMS myprims = STDPRIMS;
98 gregl 3.1 static int atlBest[] = {GLX_RGBA, GLX_RED_SIZE,8,
99     GLX_GREEN_SIZE,8, GLX_BLUE_SIZE,8,
100 gregl 3.4 GLX_DEPTH_SIZE,15, None};
101 gregl 3.15 char *ev;
102 gregl 3.1 double gamval = GAMMA;
103 gregl 3.15 RGBPRIMP dpri = stdprims;
104 gregl 3.1 XSetWindowAttributes ourwinattr;
105     XWMHints ourxwmhints;
106     XSizeHints oursizhints;
107 gregl 3.4 /* set quadtree globals */
108     qtMinNodesiz = 3;
109 gregl 3.9 qtDepthEps = 0.07;
110 gregl 3.1 /* open display server */
111     ourdisplay = XOpenDisplay(NULL);
112     if (ourdisplay == NULL)
113     error(USER, "cannot open X-windows; DISPLAY variable set?\n");
114     /* find a usable visual */
115     ourvinf = glXChooseVisual(ourdisplay, ourscreen, atlBest);
116     if (ourvinf == NULL)
117     error(USER, "no suitable visuals available");
118     /* get a context */
119     gctx = glXCreateContext(ourdisplay, ourvinf, NULL, GL_TRUE);
120     /* set gamma and tone mapping */
121 gregl 3.15 if ((ev = XGetDefault(ourdisplay, "radiance", "gamma")) != NULL
122     || (ev = getenv("DISPLAY_GAMMA")) != NULL)
123     gamval = atof(ev);
124     if ((ev = getenv("DISPLAY_PRIMARIES")) != NULL &&
125     sscanf(ev, "%f %f %f %f %f %f %f %f",
126     &myprims[RED][CIEX],&myprims[RED][CIEY],
127     &myprims[GRN][CIEX],&myprims[GRN][CIEY],
128     &myprims[BLU][CIEX],&myprims[BLU][CIEY],
129     &myprims[WHT][CIEX],&myprims[WHT][CIEY]) >= 6)
130     dpri = myprims;
131     if (tmInit(mytmflags(), dpri, gamval) == NULL)
132 gregl 3.1 error(SYSTEM, "not enough memory in dev_open");
133     /* open window */
134     ourwinattr.background_pixel = ourblack;
135     ourwinattr.border_pixel = ourblack;
136     ourwinattr.event_mask = ourmask;
137     /* this is stupid */
138     ourwinattr.colormap = XCreateColormap(ourdisplay, ourroot,
139     ourvinf->visual, AllocNone);
140     gwind = XCreateWindow(ourdisplay, ourroot, 0, 0,
141     DisplayWidth(ourdisplay,ourscreen)-2*BORWIDTH,
142     DisplayHeight(ourdisplay,ourscreen)-2*BORWIDTH,
143     BORWIDTH, ourvinf->depth, InputOutput, ourvinf->visual,
144     CWBackPixel|CWBorderPixel|CWColormap|CWEventMask, &ourwinattr);
145     if (gwind == 0)
146     error(SYSTEM, "cannot create window\n");
147     XStoreName(ourdisplay, gwind, id);
148     /* set window manager hints */
149     ourxwmhints.flags = InputHint|IconPixmapHint;
150     ourxwmhints.input = True;
151     ourxwmhints.icon_pixmap = XCreateBitmapFromData(ourdisplay,
152     gwind, x11icon_bits, x11icon_width, x11icon_height);
153     XSetWMHints(ourdisplay, gwind, &ourxwmhints);
154     oursizhints.min_width = MINWIDTH;
155     oursizhints.min_height = MINHEIGHT;
156     oursizhints.flags = PMinSize;
157     XSetNormalHints(ourdisplay, gwind, &oursizhints);
158 gregl 3.2 /* set GLX context */
159     glXMakeCurrent(ourdisplay, gwind, gctx);
160     glEnable(GL_DEPTH_TEST);
161     glDepthFunc(GL_LEQUAL);
162     glShadeModel(GL_FLAT);
163     glDisable(GL_DITHER);
164 gregl 3.4 glDisable(GL_CULL_FACE);
165     glMatrixMode(GL_PROJECTION);
166     glOrtho(0., 1., 0., 1., -.01, 1.01);
167     glTranslated(0., 0., -1.01);
168 gregl 3.1 /* figure out sensible view */
169     pwidth = (double)DisplayWidthMM(ourdisplay, ourscreen) /
170     DisplayWidth(ourdisplay, ourscreen);
171     pheight = (double)DisplayHeightMM(ourdisplay, ourscreen) /
172     DisplayHeight(ourdisplay, ourscreen);
173     copystruct(&odev.v, &stdview);
174     odev.v.type = VT_PER;
175 gregl 3.2 /* map the window */
176     XMapWindow(ourdisplay, gwind);
177     dev_input(); /* sets size and view angles */
178 gregl 3.4 /* allocate our leaf pile */
179 gregl 3.9 if (!qtAllocLeaves(DisplayWidth(ourdisplay,ourscreen) *
180 gregl 3.11 DisplayHeight(ourdisplay,ourscreen) * 3 /
181     (qtMinNodesiz*qtMinNodesiz*2)))
182 gregl 3.2 error(SYSTEM, "insufficient memory for value storage");
183 gregl 3.1 odev.name = id;
184     odev.ifd = ConnectionNumber(ourdisplay);
185 gregl 3.4 /* initialize cone array */
186     initcones();
187 gregl 3.1 }
188    
189    
190     dev_close() /* close our display and free resources */
191     {
192     glXMakeCurrent(ourdisplay, None, NULL);
193     glXDestroyContext(ourdisplay, gctx);
194     XDestroyWindow(ourdisplay, gwind);
195     gwind = 0;
196     XCloseDisplay(ourdisplay);
197     ourdisplay = NULL;
198 gregl 3.4 qtFreeLeaves();
199 gregl 3.1 tmDone(NULL);
200 gregl 3.4 freecones();
201 gregl 3.1 odev.v.type = 0;
202     odev.hres = odev.vres = 0;
203     odev.ifd = -1;
204     }
205    
206    
207 gregl 3.14 dev_clear() /* clear our quadtree */
208     {
209     qtCompost(100);
210     glClear(GL_DEPTH_BUFFER_BIT);
211     rayqleft = 0; /* hold off update */
212     }
213    
214    
215 gregl 3.1 int
216     dev_view(nv) /* assign new driver view */
217     register VIEW *nv;
218     {
219 gregl 3.4 if (nv->type == VT_PAR || /* check view legality */
220     nv->horiz > 160. || nv->vert > 160.) {
221 gregl 3.1 error(COMMAND, "illegal view type/angle");
222 gregl 3.4 nv->type = odev.v.type;
223 gregl 3.1 nv->horiz = odev.v.horiz;
224     nv->vert = odev.v.vert;
225     return(0);
226     }
227 gregl 3.4 if (nv->vfore > FTINY) {
228     error(COMMAND, "cannot handle fore clipping");
229     nv->vfore = 0.;
230     return(0);
231     }
232 gregl 3.1 if (nv != &odev.v) {
233     if (!FEQ(nv->horiz,odev.v.horiz) || /* resize window? */
234     !FEQ(nv->vert,odev.v.vert)) {
235     int dw = DisplayWidth(ourdisplay,ourscreen);
236     int dh = DisplayHeight(ourdisplay,ourscreen);
237    
238     dw -= 25; /* for window frame */
239     dh -= 50;
240     odev.hres = 2.*VIEWDIST/pwidth *
241     tan(PI/180./2.*nv->horiz);
242     odev.vres = 2.*VIEWDIST/pheight *
243     tan(PI/180./2.*nv->vert);
244     if (odev.hres > dw) {
245     odev.vres = dw * odev.vres / odev.hres;
246     odev.hres = dw;
247     }
248     if (odev.vres > dh) {
249     odev.hres = dh * odev.hres / odev.vres;
250     odev.vres = dh;
251     }
252     XResizeWindow(ourdisplay, gwind, odev.hres, odev.vres);
253 gregl 3.2 dev_input(); /* get resize event */
254 gregl 3.1 }
255     copystruct(&odev.v, nv);
256     }
257 gregl 3.4 if (nxtzmax > FTINY) {
258     curzmax = nxtzmax;
259     nxtzmax = 0.;
260     }
261     glClear(GL_DEPTH_BUFFER_BIT);
262     qtReplant();
263 gregl 3.1 return(1);
264     }
265    
266    
267 gwlarson 3.17 VIEW *
268     dev_auxview(n, hvres) /* return nth auxiliary view */
269     int n;
270     int hvres[2];
271     {
272     if (n)
273     return(NULL);
274     hvres[0] = odev.hres; hvres[1] = odev.vres;
275     return(&odev.v);
276     }
277    
278    
279 gregl 3.1 int
280     dev_input() /* get X11 input */
281     {
282     inpresflags = 0;
283    
284     do
285     getevent();
286    
287     while (XQLength(ourdisplay) > 0);
288    
289     return(inpresflags);
290     }
291    
292    
293 gregl 3.4 int
294     dev_flush() /* flush output */
295 gregl 3.1 {
296 gregl 3.4 qtUpdate();
297     glFlush();
298 gregl 3.10 rayqleft = RAYQLEN;
299 gregl 3.4 return(XPending(ourdisplay));
300 gregl 3.1 }
301    
302    
303 gregl 3.4 dev_cone(rgb, ip, rad) /* render a cone in view coordinates */
304     BYTE rgb[3];
305     FVECT ip;
306     double rad;
307 gregl 3.1 {
308 gregl 3.4 register int ci, j;
309     double apexh, basez;
310 gregl 3.12 /* is window mapped? */
311     if (!mapped)
312     return;
313 gregl 3.4 /* compute apex height (0. to 1.) */
314     if (ip[2] > 1e6)
315     apexh = 1. - 1./DEPTHFACT;
316     else {
317     if (ip[2] > nxtzmax)
318     nxtzmax = ip[2];
319     if (ip[2] >= curzmax)
320     apexh = 1. - 1./DEPTHFACT;
321     else
322     apexh = 1. - ip[2]/(curzmax*DEPTHFACT);
323 gregl 3.1 }
324 gregl 3.5 rad *= 1.25; /* find conservative cone match */
325 gregl 3.4 for (ci = 0; ci < MAXCONE-1; ci++)
326     if (cone[ci].rad >= rad)
327     break;
328     /* draw it */
329     glColor3ub(rgb[0], rgb[1], rgb[2]);
330     glBegin(GL_TRIANGLE_FAN);
331     glVertex3d(ip[0], ip[1], apexh); /* start with apex */
332     basez = apexh*cone[ci].va[0][2]; /* base z's all the same */
333     for (j = 0; j < cone[ci].nverts; j++) /* draw each face */
334     glVertex3d(ip[0]+cone[ci].va[j][0], ip[1]+cone[ci].va[j][1],
335     basez);
336     /* connect last to first */
337     glVertex3d(ip[0]+cone[ci].va[0][0], ip[1]+cone[ci].va[0][1], basez);
338     glEnd(); /* all done */
339 gregl 3.1 }
340    
341    
342     static int
343     mytmflags() /* figure out tone mapping flags */
344     {
345     extern char *progname;
346     register char *cp, *tail;
347     /* find basic name */
348     for (cp = tail = progname; *cp; cp++)
349     if (*cp == '/')
350     tail = cp+1;
351     for (cp = tail; *cp && *cp != '.'; cp++)
352     ;
353     if (cp-tail == 3 && !strncmp(tail, "glx", 3))
354 gregl 3.10 return(TM_F_CAMERA|TM_F_NOSTDERR);
355 gregl 3.1 if (cp-tail == 4 && !strncmp(tail, "glxh", 4))
356 gregl 3.10 return(TM_F_HUMAN|TM_F_NOSTDERR);
357 gregl 3.1 error(USER, "illegal driver name");
358     }
359    
360    
361     static
362 gregl 3.4 initcones() /* initialize cone vertices */
363 gregl 3.1 {
364     register int i, j;
365 gregl 3.4 double minrad, d;
366 gregl 3.1
367 gregl 3.4 if (cone[0].nverts)
368     freecones();
369     minrad = 2.*qtMinNodesiz/(double)(DisplayWidth(ourdisplay,ourscreen) +
370     DisplayHeight(ourdisplay,ourscreen));
371     for (i = 0; i < MAXCONE; i++) {
372     d = (double)i/(MAXCONE-1); d *= d; /* x^2 distribution */
373     cone[i].rad = minrad + (1.-minrad)*d;
374 gregl 3.16 cone[i].nverts = MINVERT + 0.5 + (MAXVERT-MINVERT)*d;
375 gregl 3.4 cone[i].va = (FVECT *)malloc(cone[i].nverts*sizeof(FVECT));
376     if (cone[i].va == NULL)
377     error(SYSTEM, "out of memory in initcones");
378     for (j = cone[i].nverts; j--; ) {
379     d = 2.*PI * (j+.5) / (cone[i].nverts);
380     cone[i].va[j][0] = cos(d) * cone[i].rad;
381     cone[i].va[j][1] = sin(d) * cone[i].rad;
382     cone[i].va[j][2] = 1. - cone[i].rad;
383 gregl 3.2 }
384     }
385     }
386    
387    
388     static
389 gregl 3.4 freecones() /* free cone vertices */
390 gregl 3.2 {
391 gregl 3.4 register int i;
392 gregl 3.2
393 gregl 3.4 for (i = MAXCONE; i--; )
394     if (cone[i].nverts) {
395     free((char *)cone[i].va);
396     cone[i].va = NULL;
397     cone[i].nverts = 0;
398 gregl 3.2 }
399     }
400    
401    
402     static
403 gregl 3.1 getevent() /* get next event */
404     {
405     XNextEvent(ourdisplay, levptr(XEvent));
406     switch (levptr(XEvent)->type) {
407     case ConfigureNotify:
408     resizewindow(levptr(XConfigureEvent));
409     break;
410     case UnmapNotify:
411     mapped = 0;
412     break;
413     case MapNotify:
414     mapped = 1;
415     break;
416     case Expose:
417     fixwindow(levptr(XExposeEvent));
418     break;
419     case KeyPress:
420     getkey(levptr(XKeyPressedEvent));
421     break;
422     case ButtonPress:
423     getmove(levptr(XButtonPressedEvent));
424     break;
425     }
426     }
427    
428    
429     static
430     draw3dline(wp) /* draw 3d line in world coordinates */
431     register FVECT wp[2];
432     {
433     glVertex3d(wp[0][0], wp[0][1], wp[0][2]);
434     glVertex3d(wp[1][0], wp[1][1], wp[1][2]);
435     }
436    
437    
438     static
439     draw_grids() /* draw holodeck section grids */
440     {
441 gregl 3.2 static BYTE gridrgba[4] = {0x0, 0xff, 0xff, 0x00};
442 gregl 3.4 double xmin, xmax, ymin, ymax, zmin, zmax;
443     double d, cx, sx, crad;
444     FVECT vx, vy;
445     register int i, j;
446     /* can we even do it? */
447     if (!mapped || odev.v.type != VT_PER)
448 gregl 3.1 return;
449 gregl 3.4 /* compute view frustum */
450     if (normalize(odev.v.vdir) == 0.0)
451     return;
452     zmin = 0.01;
453     zmax = 10000.;
454     if (odev.v.vfore > FTINY)
455     zmin = odev.v.vfore;
456     if (odev.v.vaft > FTINY)
457     zmax = odev.v.vaft;
458     xmax = zmin * tan(PI/180./2. * odev.v.horiz);
459     xmin = -xmax;
460     d = odev.v.hoff * (xmax - xmin);
461     xmin += d; xmax += d;
462     ymax = zmin * tan(PI/180./2. * odev.v.vert);
463     ymin = -ymax;
464     d = odev.v.voff * (ymax - ymin);
465     ymin += d; ymax += d;
466     /* set view matrix */
467     glMatrixMode(GL_PROJECTION);
468     glPushMatrix();
469     glLoadIdentity();
470     glFrustum(xmin, xmax, ymin, ymax, zmin, zmax);
471     gluLookAt(odev.v.vp[0], odev.v.vp[1], odev.v.vp[2],
472     odev.v.vp[0] + odev.v.vdir[0],
473     odev.v.vp[1] + odev.v.vdir[1],
474     odev.v.vp[2] + odev.v.vdir[2],
475     odev.v.vup[0], odev.v.vup[1], odev.v.vup[2]);
476     glDisable(GL_DEPTH_TEST); /* write no depth values */
477 gregl 3.1 glColor4ub(gridrgba[0], gridrgba[1], gridrgba[2], gridrgba[3]);
478 gregl 3.4 glBegin(GL_LINES); /* draw each grid line */
479 gregl 3.1 gridlines(draw3dline);
480     glEnd();
481 gregl 3.4 glEnable(GL_DEPTH_TEST); /* restore rendering params */
482     glPopMatrix();
483 gregl 3.1 }
484    
485    
486     static
487     moveview(dx, dy, mov, orb) /* move our view */
488     int dx, dy, mov, orb;
489     {
490     VIEW nv;
491     FVECT odir, v1;
492     double d;
493     register int li;
494     /* start with old view */
495     copystruct(&nv, &odev.v);
496     /* change view direction */
497     if (mov | orb) {
498 gregl 3.4 if ((li = qtFindLeaf(dx, dy)) < 0)
499 gregl 3.1 return(0); /* not on window */
500 gregl 3.4 VSUM(odir, qtL.wp[li], nv.vp, -1.);
501 gregl 3.1 } else {
502     if (viewray(nv.vp, nv.vdir, &odev.v,
503     (dx+.5)/odev.hres, (dy+.5)/odev.vres) < -FTINY)
504     return(0); /* outside view */
505     }
506     if (orb && mov) { /* orbit left/right */
507     spinvector(odir, odir, nv.vup, d=MOVDEG*PI/180.*mov);
508 gregl 3.4 VSUM(nv.vp, qtL.wp[li], odir, -1.);
509 gregl 3.1 spinvector(nv.vdir, nv.vdir, nv.vup, d);
510     } else if (orb) { /* orbit up/down */
511     fcross(v1, odir, nv.vup);
512     if (normalize(v1) == 0.)
513     return(0);
514     spinvector(odir, odir, v1, d=MOVDEG*PI/180.*orb);
515 gregl 3.4 VSUM(nv.vp, qtL.wp[li], odir, -1.);
516 gregl 3.1 spinvector(nv.vdir, nv.vdir, v1, d);
517     } else if (mov) { /* move forward/backward */
518     d = MOVPCT/100. * mov;
519     VSUM(nv.vp, nv.vp, odir, d);
520     }
521     if (!mov ^ !orb && headlocked) { /* restore head height */
522     VSUM(v1, odev.v.vp, nv.vp, -1.);
523     d = DOT(v1, odev.v.vup);
524     VSUM(nv.vp, nv.vp, odev.v.vup, d);
525     }
526     if (setview(&nv) != NULL)
527     return(0); /* illegal view */
528     dev_view(&nv);
529     inpresflags |= DFL(DC_SETVIEW);
530     return(1);
531     }
532    
533    
534     static
535     getmove(ebut) /* get view change */
536     XButtonPressedEvent *ebut;
537     {
538     int movdir = MOVDIR(ebut->button);
539     int movorb = MOVORB(ebut->state);
540 gregl 3.4 int oldnodesiz = qtMinNodesiz;
541 gregl 3.1 Window rootw, childw;
542     int rootx, rooty, wx, wy;
543     unsigned int statemask;
544    
545 gregl 3.4 qtMinNodesiz = 24; /* accelerate update rate */
546 gregl 3.1 XNoOp(ourdisplay);
547    
548     while (!XCheckMaskEvent(ourdisplay,
549     ButtonReleaseMask, levptr(XEvent))) {
550    
551     if (!XQueryPointer(ourdisplay, gwind, &rootw, &childw,
552     &rootx, &rooty, &wx, &wy, &statemask))
553     break; /* on another screen */
554    
555     if (!moveview(wx, odev.vres-1-wy, movdir, movorb)) {
556     sleep(1);
557     continue;
558     }
559 gregl 3.4 glClear(GL_COLOR_BUFFER_BIT);
560     qtUpdate();
561 gregl 3.1 draw_grids();
562 gregl 3.4 glFlush();
563 gregl 3.1 }
564     if (!(inpresflags & DFL(DC_SETVIEW))) { /* do final motion */
565     movdir = MOVDIR(levptr(XButtonReleasedEvent)->button);
566     wx = levptr(XButtonReleasedEvent)->x;
567     wy = levptr(XButtonReleasedEvent)->y;
568     moveview(wx, odev.vres-1-wy, movdir, movorb);
569     }
570     dev_flush();
571 gregl 3.4
572     qtMinNodesiz = oldnodesiz; /* restore quadtree resolution */
573 gregl 3.1 }
574    
575    
576     static
577     getkey(ekey) /* get input key */
578     register XKeyPressedEvent *ekey;
579     {
580     int n;
581     char buf[8];
582    
583     n = XLookupString(ekey, buf, sizeof(buf), NULL, NULL);
584     if (n != 1)
585     return;
586     switch (buf[0]) {
587     case 'h': /* turn on height motion lock */
588     headlocked = 1;
589     return;
590     case 'H': /* turn off height motion lock */
591     headlocked = 0;
592     return;
593     case 'l': /* retrieve last view */
594     inpresflags |= DFL(DC_LASTVIEW);
595     return;
596     case 'p': /* pause computation */
597     inpresflags |= DFL(DC_PAUSE);
598     return;
599     case 'v': /* spit out view */
600     inpresflags |= DFL(DC_GETVIEW);
601     return;
602     case '\n':
603     case '\r': /* resume computation */
604     inpresflags |= DFL(DC_RESUME);
605     return;
606     case CTRL('R'): /* redraw screen */
607 gregl 3.8 if (nxtzmax > FTINY) {
608     curzmax = nxtzmax;
609     nxtzmax = 0.;
610     }
611 gregl 3.2 glClear(GL_DEPTH_BUFFER_BIT);
612 gregl 3.4 qtRedraw(0, 0, odev.hres, odev.vres);
613 gregl 3.1 return;
614     case CTRL('L'): /* refresh from server */
615     if (inpresflags & DFL(DC_REDRAW))
616     return;
617 gregl 3.8 if (nxtzmax > FTINY) {
618     curzmax = nxtzmax;
619     nxtzmax = 0.;
620     }
621 gregl 3.1 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
622     draw_grids();
623     glFlush();
624 gregl 3.4 qtCompost(100); /* get rid of old values */
625 gregl 3.1 inpresflags |= DFL(DC_REDRAW); /* resend values from server */
626 gregl 3.13 rayqleft = 0; /* hold off update */
627 gregl 3.1 return;
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 |= DFL(DC_QUIT);
639     return;
640     default:
641     XBell(ourdisplay, 0);
642     return;
643     }
644     }
645    
646    
647     static
648     fixwindow(eexp) /* repair damage to window */
649     register XExposeEvent *eexp;
650     {
651 gregl 3.4 int xmin, xmax, ymin, ymax;
652    
653 gregl 3.2 if (odev.hres == 0 || odev.vres == 0) /* first exposure */
654     resizewindow((XConfigureEvent *)eexp);
655 gregl 3.4 xmin = eexp->x; xmax = eexp->x + eexp->width;
656     ymin = odev.vres - eexp->y - eexp->height; ymax = odev.vres - eexp->y;
657     /* clear portion of depth */
658     glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
659     glDepthFunc(GL_ALWAYS);
660     glBegin(GL_POLYGON);
661     glVertex3d((double)xmin/odev.hres, (double)ymin/odev.vres, 0.);
662     glVertex3d((double)xmax/odev.hres, (double)ymin/odev.vres, 0.);
663     glVertex3d((double)xmax/odev.hres, (double)ymax/odev.vres, 0.);
664     glVertex3d((double)xmin/odev.hres, (double)ymax/odev.vres, 0.);
665     glEnd();
666     glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
667     glDepthFunc(GL_LEQUAL);
668     qtRedraw(xmin, ymin, xmax, ymax);
669 gregl 3.1 }
670    
671    
672     static
673     resizewindow(ersz) /* resize window */
674     register XConfigureEvent *ersz;
675     {
676 gregl 3.6 glViewport(0, 0, ersz->width, ersz->height);
677    
678 gregl 3.1 if (ersz->width == odev.hres && ersz->height == odev.vres)
679     return;
680    
681     odev.hres = ersz->width;
682     odev.vres = ersz->height;
683    
684     odev.v.horiz = 2.*180./PI * atan(0.5/VIEWDIST*pwidth*odev.hres);
685     odev.v.vert = 2.*180./PI * atan(0.5/VIEWDIST*pheight*odev.vres);
686    
687     inpresflags |= DFL(DC_SETVIEW);
688     }