--- ray/src/hd/rhd_x11.c 1998/06/17 15:44:07 3.26 +++ ray/src/hd/rhd_x11.c 2003/04/14 16:56:19 3.33 @@ -1,21 +1,17 @@ -/* Copyright (c) 1998 Silicon Graphics, Inc. */ - #ifndef lint -static char SCCSid[] = "$SunId$ SGI"; +static const char RCSid[] = "$Id: rhd_x11.c,v 3.33 2003/04/14 16:56:19 greg Exp $"; #endif - /* * X11 driver for holodeck display. * Based on rview driver. */ #include "standard.h" -#include "rhd_qtree.h" - #include #include #include - +#include +#include "rhd_qtree.h" #include "x11icon.h" #ifndef RAYQLEN @@ -28,6 +24,8 @@ static char SCCSid[] = "$SunId$ SGI"; #define GAMMA 2.2 /* default gamma correction */ +#define FRAMESTATE(s) (((s)&(ShiftMask|ControlMask))==(ShiftMask|ControlMask)) + #define MOVPCT 7 /* percent distance to move /frame */ #define MOVDIR(b) ((b)==Button1 ? 1 : (b)==Button2 ? 0 : -1) #define MOVDEG (-5) /* degrees to orbit CW/down /frame */ @@ -49,6 +47,8 @@ static char SCCSid[] = "$SunId$ SGI"; struct driver odev; /* global device driver structure */ +char odev_args[64]; /* command arguments */ + static XEvent currentevent; /* current event */ static int ncolors = 0; /* color table size */ @@ -68,7 +68,7 @@ static int inpresflags; /* input result flags */ static int headlocked = 0; /* lock vertical motion */ -static int getpixels(), xnewcolr(), freepixels(), resizewindow(), +static int getpixels(), xnewcolr(), freepixels(), resizewindow(), getframe(), getevent(), getkey(), moveview(), getmove(), fixwindow(); static unsigned long true_pixel(); @@ -265,6 +265,13 @@ VIEW *nv; } +dev_section(ofn) /* add octree for geometry rendering */ +char *ofn; +{ + /* unimplemented */ +} + + dev_auxcom(cmd, args) /* process an auxiliary command */ char *cmd, *args; { @@ -293,8 +300,10 @@ dev_input() /* get X11 input */ do getevent(); - while (XQLength(ourdisplay) > 0); + while (XPending(ourdisplay) > 0); + odev.inpready = 0; + return(inpresflags); } @@ -322,7 +331,7 @@ dev_flush() /* flush output */ { qtUpdate(); rayqleft = RAYQLEN; - return(XPending(ourdisplay)); + return(odev.inpready = XPending(ourdisplay)); } @@ -366,7 +375,7 @@ loop: return(ncolors = 0); if (XAllocColorCells(ourdisplay,ourmap,0,NULL,0,pixval,ncolors)) break; - free((char *)pixval); + free((void *)pixval); pixval = NULL; } if (pixval == NULL) { @@ -401,7 +410,7 @@ freepixels() /* free our pixels */ if (ncolors == 0) return; XFreeColors(ourdisplay,ourmap,pixval,ncolors,0L); - free((char *)pixval); + free((void *)pixval); pixval = NULL; ncolors = 0; if (ourmap != DefaultColormap(ourdisplay,ourscreen)) @@ -451,7 +460,10 @@ getevent() /* get next event */ getkey(levptr(XKeyPressedEvent)); break; case ButtonPress: - getmove(levptr(XButtonPressedEvent)); + if (FRAMESTATE(levptr(XButtonPressedEvent)->state)) + getframe(levptr(XButtonPressedEvent)); + else + getmove(levptr(XButtonPressedEvent)); break; } } @@ -462,11 +474,29 @@ 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]); + static FVECT vmin = {0.,0.,0.}, vmax = {1.-FTINY,1.-FTINY,FHUGE}; + FVECT wpc[2], ip[2]; + double d, d0, d1; + /* check for points behind view */ + d = DOT(odev.v.vp, odev.v.vdir); + d0 = DOT(wp[0], odev.v.vdir) - d; + d1 = DOT(wp[1], odev.v.vdir) - d; + /* work on copy of world points */ + if (d0 <= d1) { + VCOPY(wpc[0], wp[0]); VCOPY(wpc[1], wp[1]); + } else { + d = d0; d0 = d1; d1 = d; + VCOPY(wpc[1], wp[0]); VCOPY(wpc[0], wp[1]); + } + if (d0 <= FTINY) { + if (d1 <= FTINY) return(0); + VSUB(wpc[0], wpc[0], wpc[1]); + d = .99*d1/(d1-d0); + VSUM(wpc[0], wpc[1], wpc[0], d); + } + /* get view coordinates and clip to window */ + viewloc(ip[0], &odev.v, wpc[0]); + viewloc(ip[1], &odev.v, wpc[1]); if (!clip(ip[0], ip[1], vmin, vmax)) return(0); dp[0][0] = ip[0][0]*odev.hres; @@ -497,8 +527,6 @@ draw_grids() /* draw holodeck section grids */ static BYTE gridrgb[3] = {0x0, 0xff, 0xff}; unsigned long pixel; - if (!mapped) - return; if (ncolors > 0) pixel = pixval[get_pixel(gridrgb, xnewcolr)]; else @@ -558,6 +586,39 @@ int dx, dy, mov, orb; static +getframe(ebut) /* get focus frame */ +XButtonPressedEvent *ebut; +{ + int startx = ebut->x, starty = ebut->y; + int endx, endy; + + XMaskEvent(ourdisplay, ButtonReleaseMask, levptr(XEvent)); + endx = levptr(XButtonReleasedEvent)->x; + endy = levptr(XButtonReleasedEvent)->y; + if (endx == startx | endy == starty) { + XBell(ourdisplay, 0); + return; + } + if (endx < startx) {register int c = endx; endx = startx; startx = c;} + if (endy < starty) {register int c = endy; endy = starty; starty = c;} + sprintf(odev_args, "%.3f %.3f %.3f %.3f", + (startx+.5)/odev.hres, 1.-(endy+.5)/odev.vres, + (endx+.5)/odev.hres, 1.-(starty+.5)/odev.vres); + inpresflags |= DFL(DC_FOCUS); +} + + +static +waitabit() /* pause a moment */ +{ + struct timespec ts; + ts.tv_sec = 0; + ts.tv_nsec = 50000000; + nanosleep(&ts, NULL); +} + + +static getmove(ebut) /* get view change */ XButtonPressedEvent *ebut; { @@ -573,7 +634,7 @@ XButtonPressedEvent *ebut; while (!XCheckMaskEvent(ourdisplay, ButtonReleaseMask, levptr(XEvent))) { - + waitabit(); if (!XQueryPointer(ourdisplay, gwind, &rootw, &childw, &rootx, &rooty, &wx, &wy, &statemask)) break; /* on another screen */ @@ -602,6 +663,9 @@ static getkey(ekey) /* get input key */ register XKeyPressedEvent *ekey; { + Window rootw, childw; + int rootx, rooty, wx, wy; + unsigned int statemask; int n; char buf[8]; @@ -617,6 +681,18 @@ register XKeyPressedEvent *ekey; return; case 'l': /* retrieve last view */ inpresflags |= DFL(DC_LASTVIEW); + return; + case 'f': /* frame view position */ + if (!XQueryPointer(ourdisplay, gwind, &rootw, &childw, + &rootx, &rooty, &wx, &wy, &statemask)) + return; /* on another screen */ + sprintf(odev_args, "%.4f %.4f", (wx+.5)/odev.hres, + 1.-(wy+.5)/odev.vres); + inpresflags |= DFL(DC_FOCUS); + return; + case 'F': /* unfocus */ + odev_args[0] = '\0'; + inpresflags |= DFL(DC_FOCUS); return; case 'p': /* pause computation */ inpresflags |= DFL(DC_PAUSE);