ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/rhd_glx1.c
Revision: 3.9
Committed: Thu Apr 28 16:28:20 2016 UTC (8 years ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad5R1
Changes since 3.8: +9 -2 lines
Log Message:
Added listening for mouse wheel

File Contents

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