49 |
|
static unsigned long ourblack=0, ourwhite=1; |
50 |
|
|
51 |
|
static Display *ourdisplay = NULL; /* our display */ |
52 |
– |
|
52 |
|
static XVisualInfo ourvinfo; /* our visual information */ |
54 |
– |
|
53 |
|
static Window gwind = 0; /* our graphics window */ |
56 |
– |
|
54 |
|
static GC ourgc = 0; /* our graphics context for drawing */ |
58 |
– |
|
55 |
|
static Colormap ourmap = 0; /* our color map */ |
56 |
|
|
57 |
|
static double pwidth, pheight; /* pixel dimensions (mm) */ |
95 |
|
XWMHints ourxwmhints; |
96 |
|
XSizeHints oursizhints; |
97 |
|
/* set quadtree globals */ |
102 |
– |
qtDepthEps = 0.02; |
98 |
|
qtMinNodesiz = 2; |
99 |
|
/* open display server */ |
100 |
|
ourdisplay = XOpenDisplay(NULL); |
375 |
|
|
376 |
|
|
377 |
|
static |
378 |
+ |
ilclip(dp, wp) /* clip world coordinates to device */ |
379 |
+ |
int dp[2][2]; |
380 |
+ |
FVECT wp[2]; |
381 |
+ |
{ |
382 |
+ |
static FVECT vmin = {0.,0.,0.}, vmax = {1.,1.,FHUGE}; |
383 |
+ |
FVECT ip[2]; |
384 |
+ |
/* not exactly right, but who cares? */ |
385 |
+ |
viewloc(ip[0], &odev.v, wp[0]); |
386 |
+ |
viewloc(ip[1], &odev.v, wp[1]); |
387 |
+ |
if (!clip(ip[0], ip[1], vmin, vmax)) |
388 |
+ |
return(0); |
389 |
+ |
dp[0][0] = ip[0][0]*odev.hres; |
390 |
+ |
dp[0][1] = ip[0][1]*odev.vres; |
391 |
+ |
dp[1][0] = ip[1][0]*odev.hres; |
392 |
+ |
dp[1][1] = ip[1][1]*odev.vres; |
393 |
+ |
return(1); |
394 |
+ |
} |
395 |
+ |
|
396 |
+ |
|
397 |
+ |
static |
398 |
+ |
draw3dline(wp) /* draw 3d line in world coordinates */ |
399 |
+ |
FVECT wp[2]; |
400 |
+ |
{ |
401 |
+ |
int dp[2][2]; |
402 |
+ |
|
403 |
+ |
if (!ilclip(dp, wp)) |
404 |
+ |
return; |
405 |
+ |
XDrawLine(ourdisplay, gwind, ourgc, |
406 |
+ |
dp[0][0], odev.vres-1 - dp[0][1], |
407 |
+ |
dp[1][0], odev.vres-1 - dp[1][1]); |
408 |
+ |
} |
409 |
+ |
|
410 |
+ |
|
411 |
+ |
static |
412 |
+ |
draw_grids() /* draw holodeck section grids */ |
413 |
+ |
{ |
414 |
+ |
static BYTE gridrgb[3] = {0x0, 0xff, 0xff}; |
415 |
+ |
unsigned long pixel; |
416 |
+ |
|
417 |
+ |
if (!mapped || odev.v.type != VT_PER) |
418 |
+ |
return; |
419 |
+ |
if (ncolors > 0) |
420 |
+ |
pixel = pixval[get_pixel(gridrgb, xnewcolr)]; |
421 |
+ |
else |
422 |
+ |
pixel = true_pixel(gridrgb); |
423 |
+ |
XSetForeground(ourdisplay, ourgc, pixel); |
424 |
+ |
/* draw each grid line */ |
425 |
+ |
gridlines(draw3dline); |
426 |
+ |
} |
427 |
+ |
|
428 |
+ |
|
429 |
+ |
static |
430 |
|
moveview(dx, dy, move) /* move our view */ |
431 |
|
int dx, dy, move; |
432 |
|
{ |
479 |
|
unsigned int statemask; |
480 |
|
|
481 |
|
qtMinNodesiz = 16; /* for quicker update */ |
482 |
< |
qtCompost(50); |
482 |
> |
XNoOp(ourdisplay); |
483 |
|
|
484 |
< |
do { |
484 |
> |
while (!XCheckMaskEvent(ourdisplay, |
485 |
> |
ButtonReleaseMask, levptr(XEvent))) { |
486 |
> |
|
487 |
|
if (!XQueryPointer(ourdisplay, gwind, &rootw, &childw, |
488 |
|
&rootx, &rooty, &wx, &wy, &statemask)) |
489 |
|
break; /* on another screen */ |
490 |
|
|
491 |
< |
if (!moveview(wx, odev.vres-1-wy, MOVDIR(whichbutton))) |
491 |
> |
if (!moveview(wx, odev.vres-1-wy, MOVDIR(whichbutton))) { |
492 |
|
sleep(1); |
493 |
< |
else |
494 |
< |
qtUpdate(); |
495 |
< |
|
496 |
< |
} while (!XCheckMaskEvent(ourdisplay, |
497 |
< |
ButtonReleaseMask, levptr(XEvent))); |
498 |
< |
|
493 |
> |
continue; |
494 |
> |
} |
495 |
> |
XClearWindow(ourdisplay, gwind); |
496 |
> |
qtUpdate(); |
497 |
> |
draw_grids(); |
498 |
> |
} |
499 |
|
if (!(inpresflags & DEV_NEWVIEW)) { /* do final motion */ |
500 |
|
whichbutton = levptr(XButtonReleasedEvent)->button; |
501 |
|
wx = levptr(XButtonReleasedEvent)->x; |
502 |
|
wy = levptr(XButtonReleasedEvent)->y; |
503 |
|
moveview(wx, odev.vres-1-wy, MOVDIR(whichbutton)); |
504 |
|
} |
505 |
+ |
dev_flush(); |
506 |
|
|
507 |
|
qtMinNodesiz = oldnodesiz; /* restore quadtree resolution */ |
508 |
|
} |
529 |
|
case 'p': /* pause computation */ |
530 |
|
inpresflags |= DEV_WAIT; |
531 |
|
return; |
532 |
+ |
case 'v': /* spit out view */ |
533 |
+ |
fputs(VIEWSTR, stderr); |
534 |
+ |
fprintview(&odev.v, stderr); |
535 |
+ |
fputc('\n', stderr); |
536 |
+ |
return; |
537 |
|
case CTRL('Q'): |
538 |
|
case '\n': |
539 |
|
case '\r': /* resume computation */ |
540 |
|
inpresflags |= DEV_RESUME; |
541 |
|
return; |
542 |
< |
case CTRL('R'): /* redraw */ |
542 |
> |
case CTRL('R'): /* redraw screen */ |
543 |
|
if (ncolors > 0) |
544 |
|
new_ctab(ncolors); |
545 |
|
qtRedraw(0, 0, odev.hres, odev.vres); |
546 |
+ |
return; |
547 |
+ |
case CTRL('L'): /* refresh from server */ |
548 |
+ |
if (inpresflags & DEV_REDRAW) |
549 |
+ |
return; |
550 |
+ |
XClearWindow(ourdisplay, gwind); |
551 |
+ |
draw_grids(); |
552 |
+ |
XFlush(ourdisplay); |
553 |
+ |
qtCompost(100); /* unload the old tree */ |
554 |
+ |
if (ncolors > 0) |
555 |
+ |
new_ctab(ncolors); |
556 |
+ |
inpresflags |= DEV_REDRAW; /* resend values from server */ |
557 |
|
return; |
558 |
|
case CTRL('D'): |
559 |
|
case 'Q': |