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