18 |
|
|
19 |
|
#include "x11icon.h" |
20 |
|
|
21 |
+ |
#ifndef FEQ |
22 |
+ |
#define FEQ(a,b) ((a)-(b) <= FTINY && (a)-(b) >= -FTINY) |
23 |
+ |
#endif |
24 |
+ |
|
25 |
|
#define CTRL(c) ((c)-'@') |
26 |
|
|
27 |
|
#define GAMMA 2.2 /* default gamma correction */ |
53 |
|
static unsigned long ourblack=0, ourwhite=1; |
54 |
|
|
55 |
|
static Display *ourdisplay = NULL; /* our display */ |
52 |
– |
|
56 |
|
static XVisualInfo ourvinfo; /* our visual information */ |
54 |
– |
|
57 |
|
static Window gwind = 0; /* our graphics window */ |
56 |
– |
|
58 |
|
static GC ourgc = 0; /* our graphics context for drawing */ |
58 |
– |
|
59 |
|
static Colormap ourmap = 0; /* our color map */ |
60 |
|
|
61 |
|
static double pwidth, pheight; /* pixel dimensions (mm) */ |
99 |
|
XWMHints ourxwmhints; |
100 |
|
XSizeHints oursizhints; |
101 |
|
/* set quadtree globals */ |
102 |
– |
qtDepthEps = 0.02; |
102 |
|
qtMinNodesiz = 2; |
103 |
|
/* open display server */ |
104 |
|
ourdisplay = XOpenDisplay(NULL); |
201 |
|
dev_view(nv) /* assign new driver view */ |
202 |
|
VIEW *nv; |
203 |
|
{ |
204 |
< |
if (nv != &odev.v) |
204 |
> |
if (nv != &odev.v) { |
205 |
> |
if (!FEQ(nv->horiz,odev.v.horiz) || /* resize window? */ |
206 |
> |
!FEQ(nv->vert,odev.v.vert)) { |
207 |
> |
odev.hres = 2.*VIEWDIST*tan(PI/180./2.*nv->horiz) / |
208 |
> |
pwidth; |
209 |
> |
odev.vres = 2.*VIEWDIST*tan(PI/180./2.*nv->vert) / |
210 |
> |
pheight; |
211 |
> |
XResizeWindow(ourdisplay, gwind, odev.hres, odev.vres); |
212 |
> |
} |
213 |
|
copystruct(&odev.v, nv); |
214 |
+ |
} |
215 |
|
qtReplant(); |
216 |
|
} |
217 |
|
|
220 |
|
dev_input() /* get X11 input */ |
221 |
|
{ |
222 |
|
inpresflags = 0; |
223 |
+ |
|
224 |
|
do |
225 |
|
getevent(); |
226 |
|
|
388 |
|
|
389 |
|
|
390 |
|
static |
391 |
+ |
ilclip(dp, wp) /* clip world coordinates to device */ |
392 |
+ |
int dp[2][2]; |
393 |
+ |
FVECT wp[2]; |
394 |
+ |
{ |
395 |
+ |
static FVECT vmin = {0.,0.,0.}, vmax = {1.,1.,FHUGE}; |
396 |
+ |
FVECT ip[2]; |
397 |
+ |
/* not exactly right, but who cares? */ |
398 |
+ |
viewloc(ip[0], &odev.v, wp[0]); |
399 |
+ |
viewloc(ip[1], &odev.v, wp[1]); |
400 |
+ |
if (!clip(ip[0], ip[1], vmin, vmax)) |
401 |
+ |
return(0); |
402 |
+ |
dp[0][0] = ip[0][0]*odev.hres; |
403 |
+ |
dp[0][1] = ip[0][1]*odev.vres; |
404 |
+ |
dp[1][0] = ip[1][0]*odev.hres; |
405 |
+ |
dp[1][1] = ip[1][1]*odev.vres; |
406 |
+ |
return(1); |
407 |
+ |
} |
408 |
+ |
|
409 |
+ |
|
410 |
+ |
static |
411 |
+ |
draw3dline(wp) /* draw 3d line in world coordinates */ |
412 |
+ |
FVECT wp[2]; |
413 |
+ |
{ |
414 |
+ |
int dp[2][2]; |
415 |
+ |
|
416 |
+ |
if (!ilclip(dp, wp)) |
417 |
+ |
return; |
418 |
+ |
XDrawLine(ourdisplay, gwind, ourgc, |
419 |
+ |
dp[0][0], odev.vres-1 - dp[0][1], |
420 |
+ |
dp[1][0], odev.vres-1 - dp[1][1]); |
421 |
+ |
} |
422 |
+ |
|
423 |
+ |
|
424 |
+ |
static |
425 |
+ |
draw_grids() /* draw holodeck section grids */ |
426 |
+ |
{ |
427 |
+ |
static BYTE gridrgb[3] = {0x0, 0xff, 0xff}; |
428 |
+ |
unsigned long pixel; |
429 |
+ |
|
430 |
+ |
if (!mapped || odev.v.type != VT_PER) |
431 |
+ |
return; |
432 |
+ |
if (ncolors > 0) |
433 |
+ |
pixel = pixval[get_pixel(gridrgb, xnewcolr)]; |
434 |
+ |
else |
435 |
+ |
pixel = true_pixel(gridrgb); |
436 |
+ |
XSetForeground(ourdisplay, ourgc, pixel); |
437 |
+ |
/* draw each grid line */ |
438 |
+ |
gridlines(draw3dline); |
439 |
+ |
} |
440 |
+ |
|
441 |
+ |
|
442 |
+ |
static |
443 |
|
moveview(dx, dy, move) /* move our view */ |
444 |
|
int dx, dy, move; |
445 |
|
{ |
492 |
|
unsigned int statemask; |
493 |
|
|
494 |
|
qtMinNodesiz = 16; /* for quicker update */ |
495 |
< |
qtCompost(50); |
495 |
> |
XNoOp(ourdisplay); |
496 |
|
|
497 |
< |
do { |
497 |
> |
while (!XCheckMaskEvent(ourdisplay, |
498 |
> |
ButtonReleaseMask, levptr(XEvent))) { |
499 |
> |
|
500 |
|
if (!XQueryPointer(ourdisplay, gwind, &rootw, &childw, |
501 |
|
&rootx, &rooty, &wx, &wy, &statemask)) |
502 |
|
break; /* on another screen */ |
503 |
|
|
504 |
< |
if (!moveview(wx, odev.vres-1-wy, MOVDIR(whichbutton))) |
504 |
> |
if (!moveview(wx, odev.vres-1-wy, MOVDIR(whichbutton))) { |
505 |
|
sleep(1); |
506 |
< |
else |
507 |
< |
qtUpdate(); |
508 |
< |
|
509 |
< |
} while (!XCheckMaskEvent(ourdisplay, |
510 |
< |
ButtonReleaseMask, levptr(XEvent))); |
511 |
< |
|
506 |
> |
continue; |
507 |
> |
} |
508 |
> |
XClearWindow(ourdisplay, gwind); |
509 |
> |
qtUpdate(); |
510 |
> |
draw_grids(); |
511 |
> |
} |
512 |
|
if (!(inpresflags & DEV_NEWVIEW)) { /* do final motion */ |
513 |
|
whichbutton = levptr(XButtonReleasedEvent)->button; |
514 |
|
wx = levptr(XButtonReleasedEvent)->x; |
515 |
|
wy = levptr(XButtonReleasedEvent)->y; |
516 |
|
moveview(wx, odev.vres-1-wy, MOVDIR(whichbutton)); |
517 |
|
} |
518 |
+ |
dev_flush(); |
519 |
|
|
520 |
|
qtMinNodesiz = oldnodesiz; /* restore quadtree resolution */ |
521 |
|
} |
538 |
|
case 'H': /* turn off height motion lock */ |
539 |
|
headlocked = 0; |
540 |
|
return; |
541 |
< |
case CTRL('Z'): |
541 |
> |
case CTRL('S'): |
542 |
|
case 'p': /* pause computation */ |
543 |
|
inpresflags |= DEV_WAIT; |
544 |
|
return; |
545 |
+ |
case 'v': /* spit out view */ |
546 |
+ |
inpresflags |= DEV_PUTVIEW; |
547 |
+ |
return; |
548 |
+ |
case CTRL('Q'): |
549 |
|
case '\n': |
550 |
< |
case '\r': /* release */ |
550 |
> |
case '\r': /* resume computation */ |
551 |
> |
inpresflags |= DEV_RESUME; |
552 |
|
return; |
553 |
< |
case CTRL('R'): /* redraw */ |
553 |
> |
case CTRL('R'): /* redraw screen */ |
554 |
|
if (ncolors > 0) |
555 |
|
new_ctab(ncolors); |
556 |
|
qtRedraw(0, 0, odev.hres, odev.vres); |
557 |
|
return; |
558 |
+ |
case CTRL('L'): /* refresh from server */ |
559 |
+ |
if (inpresflags & DEV_REDRAW) |
560 |
+ |
return; |
561 |
+ |
XClearWindow(ourdisplay, gwind); |
562 |
+ |
draw_grids(); |
563 |
+ |
XFlush(ourdisplay); |
564 |
+ |
qtCompost(100); /* unload the old tree */ |
565 |
+ |
if (ncolors > 0) |
566 |
+ |
new_ctab(ncolors); |
567 |
+ |
inpresflags |= DEV_REDRAW; /* resend values from server */ |
568 |
+ |
return; |
569 |
|
case CTRL('D'): |
570 |
|
case 'Q': |
571 |
|
case 'q': /* quit the program */ |
600 |
|
return; |
601 |
|
|
602 |
|
if (odev.hres != 0 && odev.vres != 0) { |
603 |
< |
odev.v.horiz = 2.*180./PI * atan( |
604 |
< |
tan(PI/180./2.*odev.v.horiz) * ersz->width/odev.hres ); |
525 |
< |
odev.v.vert = 2.*180./PI * atan( |
526 |
< |
tan(PI/180./2.*odev.v.vert) * ersz->height/odev.vres ); |
603 |
> |
odev.v.horiz = 2.*180./PI * atan(0.5/VIEWDIST*pwidth*odev.hres); |
604 |
> |
odev.v.vert = 2.*180./PI * atan(0.5/VIEWDIST*pheight*odev.vres); |
605 |
|
inpresflags |= DEV_NEWVIEW; |
606 |
|
} |
607 |
|
odev.hres = ersz->width; |