ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/rhd_glx1.c
Revision: 3.11
Committed: Fri Feb 12 00:53:56 2021 UTC (3 years, 2 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad5R4, HEAD
Changes since 3.10: +3 -7 lines
Log Message:
refactor: Created comparison macros for RREAL and FVECT types

File Contents

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