--- ray/src/hd/rhd_x11.c 1997/11/20 18:04:28 3.2 +++ ray/src/hd/rhd_x11.c 1997/11/25 16:52:51 3.9 @@ -49,13 +49,9 @@ static unsigned long *pixval = NULL; /* allocated pix static unsigned long ourblack=0, ourwhite=1; static Display *ourdisplay = NULL; /* our display */ - static XVisualInfo ourvinfo; /* our visual information */ - static Window gwind = 0; /* our graphics window */ - static GC ourgc = 0; /* our graphics context for drawing */ - static Colormap ourmap = 0; /* our color map */ static double pwidth, pheight; /* pixel dimensions (mm) */ @@ -100,7 +96,7 @@ char *id; XSizeHints oursizhints; /* set quadtree globals */ qtDepthEps = 0.02; - qtMinNodesiz = 1; + qtMinNodesiz = 2; /* open display server */ ourdisplay = XOpenDisplay(NULL); if (ourdisplay == NULL) @@ -212,6 +208,7 @@ int dev_input() /* get X11 input */ { inpresflags = 0; + do getevent(); @@ -379,21 +376,72 @@ getevent() /* get next event */ static +ilclip(dp, wp) /* clip world coordinates to device */ +int dp[2][2]; +FVECT wp[2]; +{ + static FVECT vmin = {0.,0.,0.}, vmax = {1.,1.,FHUGE}; + FVECT ip[2]; + /* not exactly right, but who cares? */ + viewloc(ip[0], &odev.v, wp[0]); + viewloc(ip[1], &odev.v, wp[1]); + if (!clip(ip[0], ip[1], vmin, vmax)) + return(0); + dp[0][0] = ip[0][0]*odev.hres; + dp[0][1] = ip[0][1]*odev.vres; + dp[1][0] = ip[1][0]*odev.hres; + dp[1][1] = ip[1][1]*odev.vres; + return(1); +} + + +static +draw3dline(wp) /* draw 3d line in world coordinates */ +FVECT wp[2]; +{ + int dp[2][2]; + + if (!ilclip(dp, wp)) + return; + XDrawLine(ourdisplay, gwind, ourgc, + dp[0][0], odev.vres-1 - dp[0][1], + dp[1][0], odev.vres-1 - dp[1][1]); +} + + +static +draw_grids() /* draw holodeck section grids */ +{ + static BYTE gridrgb[3] = {0x0, 0xff, 0xff}; + unsigned long pixel; + + if (!mapped || odev.v.type != VT_PER) + return; + if (ncolors > 0) + pixel = pixval[get_pixel(gridrgb, xnewcolr)]; + else + pixel = true_pixel(gridrgb); + XSetForeground(ourdisplay, ourgc, pixel); + /* draw each grid line */ + gridlines(draw3dline); +} + + +static moveview(dx, dy, move) /* move our view */ int dx, dy, move; { VIEW nv; double d; - register int i; + register int i, li; /* start with old view */ copystruct(&nv, &odev.v); /* change view direction */ if (move) { - register RLEAF *lp; - if ((lp = qtFindLeaf(dx, dy)) == NULL) + if ((li = qtFindLeaf(dx, dy)) < 0) return(0); /* not on window */ for (i = 0; i < 3; i++) - nv.vdir[i] = lp->wp[i] - nv.vp[i]; + nv.vdir[i] = qtL.wp[li][i] - nv.vp[i]; } else { if (viewray(nv.vp, nv.vdir, &odev.v, (dx+.5)/odev.hres, (dy+.5)/odev.vres) < -FTINY) @@ -432,24 +480,30 @@ XButtonPressedEvent *ebut; unsigned int statemask; qtMinNodesiz = 16; /* for quicker update */ + XNoOp(ourdisplay); - do { + while (!XCheckMaskEvent(ourdisplay, + ButtonReleaseMask, levptr(XEvent))) { + if (!XQueryPointer(ourdisplay, gwind, &rootw, &childw, &rootx, &rooty, &wx, &wy, &statemask)) break; /* on another screen */ - if (!moveview(wx, odev.vres-1-wy, MOVDIR(whichbutton))) + if (!moveview(wx, odev.vres-1-wy, MOVDIR(whichbutton))) { sleep(1); - - } while (!XCheckMaskEvent(ourdisplay, - ButtonReleaseMask, levptr(XEvent))); - + continue; + } + XClearWindow(ourdisplay, gwind); + qtUpdate(); + draw_grids(); + } if (!(inpresflags & DEV_NEWVIEW)) { /* do final motion */ whichbutton = levptr(XButtonReleasedEvent)->button; wx = levptr(XButtonReleasedEvent)->x; wy = levptr(XButtonReleasedEvent)->y; moveview(wx, odev.vres-1-wy, MOVDIR(whichbutton)); } + dev_flush(); qtMinNodesiz = oldnodesiz; /* restore quadtree resolution */ } @@ -472,12 +526,35 @@ register XKeyPressedEvent *ekey; case 'H': /* turn off height motion lock */ headlocked = 0; return; - case CTRL('Z'): + case CTRL('S'): case 'p': /* pause computation */ inpresflags |= DEV_WAIT; return; + case 'v': /* spit out view */ + fputs(VIEWSTR, stderr); + fprintview(&odev.v, stderr); + fputc('\n', stderr); + return; + case CTRL('Q'): case '\n': - case '\r': /* release */ + case '\r': /* resume computation */ + inpresflags |= DEV_RESUME; + return; + case CTRL('R'): /* redraw screen */ + if (ncolors > 0) + new_ctab(ncolors); + qtRedraw(0, 0, odev.hres, odev.vres); + return; + case CTRL('L'): /* refresh from server */ + if (inpresflags & DEV_REDRAW) + return; + XClearWindow(ourdisplay, gwind); + draw_grids(); + XFlush(ourdisplay); + qtCompost(100); /* unload the old tree */ + if (ncolors > 0) + new_ctab(ncolors); + inpresflags |= DEV_REDRAW; /* resend values from server */ return; case CTRL('D'): case 'Q':