--- ray/src/hd/rhd_x11.c 1997/11/21 16:10:17 3.6 +++ ray/src/hd/rhd_x11.c 1997/12/08 19:03:18 3.11 @@ -18,6 +18,10 @@ static char SCCSid[] = "$SunId$ SGI"; #include "x11icon.h" +#ifndef FEQ +#define FEQ(a,b) ((a)-(b) <= FTINY && (a)-(b) >= -FTINY) +#endif + #define CTRL(c) ((c)-'@') #define GAMMA 2.2 /* default gamma correction */ @@ -49,13 +53,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) */ @@ -99,7 +99,6 @@ char *id; XWMHints ourxwmhints; XSizeHints oursizhints; /* set quadtree globals */ - qtDepthEps = 0.02; qtMinNodesiz = 2; /* open display server */ ourdisplay = XOpenDisplay(NULL); @@ -202,8 +201,17 @@ dev_close() /* close our display */ dev_view(nv) /* assign new driver view */ VIEW *nv; { - if (nv != &odev.v) + if (nv != &odev.v) { + if (!FEQ(nv->horiz,odev.v.horiz) || /* resize window? */ + !FEQ(nv->vert,odev.v.vert)) { + odev.hres = 2.*VIEWDIST*tan(PI/180./2.*nv->horiz) / + pwidth; + odev.vres = 2.*VIEWDIST*tan(PI/180./2.*nv->vert) / + pheight; + XResizeWindow(ourdisplay, gwind, odev.hres, odev.vres); + } copystruct(&odev.v, nv); + } qtReplant(); } @@ -380,6 +388,58 @@ 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; { @@ -432,27 +492,30 @@ XButtonPressedEvent *ebut; unsigned int statemask; qtMinNodesiz = 16; /* for quicker update */ - qtCompost(50); + 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); - else - qtUpdate(); - - } 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 */ } @@ -479,12 +542,25 @@ register XKeyPressedEvent *ekey; case 'p': /* pause computation */ inpresflags |= DEV_WAIT; return; + case 'v': /* spit out view */ + inpresflags |= DEV_PUTVIEW; + return; case CTRL('Q'): case '\n': case '\r': /* resume computation */ inpresflags |= DEV_RESUME; return; - case CTRL('R'): /* redraw */ + 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); @@ -524,10 +600,8 @@ register XConfigureEvent *ersz; return; if (odev.hres != 0 && odev.vres != 0) { - odev.v.horiz = 2.*180./PI * atan( - tan(PI/180./2.*odev.v.horiz) * ersz->width/odev.hres ); - odev.v.vert = 2.*180./PI * atan( - tan(PI/180./2.*odev.v.vert) * ersz->height/odev.vres ); + odev.v.horiz = 2.*180./PI * atan(0.5/VIEWDIST*pwidth*odev.hres); + odev.v.vert = 2.*180./PI * atan(0.5/VIEWDIST*pheight*odev.vres); inpresflags |= DEV_NEWVIEW; } odev.hres = ersz->width;