--- ray/src/hd/rhd_ogl.c 2004/01/01 11:21:55 3.24 +++ ray/src/hd/rhd_ogl.c 2012/09/06 00:07:43 3.31 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: rhd_ogl.c,v 3.24 2004/01/01 11:21:55 schorsch Exp $"; +static const char RCSid[] = "$Id: rhd_ogl.c,v 3.31 2012/09/06 00:07:43 greg Exp $"; #endif /* * OpenGL driver for holodeck display. @@ -28,6 +28,7 @@ static const char RCSid[] = "$Id: rhd_ogl.c,v 3.24 200 #include "standard.h" #include "rhd_odraw.h" #include "rhdisp.h" +#include "paths.h" #ifdef DOBJ #include "rhdobj.h" #endif @@ -81,6 +82,8 @@ static const char RCSid[] = "$Id: rhd_ogl.c,v 3.24 200 struct driver odev; /* global device driver structure */ +TMstruct *tmGlobal; /* global tone-mapping structure */ + char odev_args[64]; /* command arguments */ static GLfloat *depthbuffer = NULL; /* depth buffer */ @@ -208,7 +211,8 @@ char *id; &myprims[BLU][CIEX],&myprims[BLU][CIEY], &myprims[WHT][CIEX],&myprims[WHT][CIEY]) >= 6) dpri = myprims; - if (tmInit(mytmflags(), dpri, gamval) == NULL) + tmGlobal = tmInit(mytmflags(), dpri, gamval); + if (tmGlobal == NULL) error(SYSTEM, "not enough memory in dev_open"); /* open window */ ourwinattr.background_pixel = ourblack; @@ -231,8 +235,8 @@ char *id; /* set window manager hints */ ourxwmhints.flags = InputHint|IconPixmapHint; ourxwmhints.input = True; - ourxwmhints.icon_pixmap = XCreateBitmapFromData(ourdisplay, - gwind, x11icon_bits, x11icon_width, x11icon_height); + ourxwmhints.icon_pixmap = XCreateBitmapFromData(ourdisplay, gwind, + (char *)x11icon_bits, x11icon_width, x11icon_height); XSetWMHints(ourdisplay, gwind, &ourxwmhints); oursizhints.min_width = MINWIDTH; #ifdef STEREO @@ -298,7 +302,7 @@ dev_close(void) /* close our display and free resour gwind = 0; XCloseDisplay(ourdisplay); ourdisplay = NULL; - tmDone(NULL); + tmDone(tmGlobal); odev.v.type = 0; odev.hres = odev.vres = 0; odev.ifd = -1; @@ -320,6 +324,9 @@ dev_view( /* assign new driver view */ register VIEW *nv ) { +#ifdef STEREO + double d; +#endif if (nv->type != VT_PER || /* check view legality */ nv->horiz > 160. || nv->vert > 160.) { error(COMMAND, "illegal view type/angle"); @@ -761,7 +768,10 @@ moveview( /* move our view */ { VIEW nv; FVECT odir, v1, wip; - double d, d1; + double d; +#ifdef DOBJ + double d1; +#endif /* start with old view */ nv = odev.v; /* orient our motion */ @@ -786,12 +796,11 @@ moveview( /* move our view */ VSUM(nv.vp, wip, odir, -1.); spinvector(nv.vdir, nv.vdir, nv.vup, d); } else if (orb) { /* orbit up/down */ - fcross(v1, odir, nv.vup); - if (normalize(v1) == 0.) + if (geodesic(odir, odir, nv.vup, + d=MOVDEG*PI/180.*orb, GEOD_RAD) == 0.0) return(0); - spinvector(odir, odir, v1, d=MOVDEG*PI/180.*orb); VSUM(nv.vp, wip, odir, -1.); - spinvector(nv.vdir, nv.vdir, v1, d); + geodesic(nv.vdir, nv.vdir, nv.vup, d, GEOD_RAD); } else if (mov) { /* move forward/backward */ d = MOVPCT/100. * mov; VSUM(nv.vp, nv.vp, odir, d); @@ -815,15 +824,33 @@ getframe( /* get focus frame */ ) { int startx = ebut->x, starty = ebut->y; - int endx, endy; - + int endx, endy, midx, midy; + FVECT odir, v1; + double d; +#ifdef DOBJ + double d1; +#endif + /* get mouse drag */ XMaskEvent(ourdisplay, ButtonReleaseMask, levptr(XEvent)); endx = levptr(XButtonReleasedEvent)->x; endy = levptr(XButtonReleasedEvent)->y; - if ((endx == startx) | (endy == starty)) { - XBell(ourdisplay, 0); + midx = (startx + endx) >> 1; + midy = (starty + endy) >> 1; + /* set focus distance */ + if (viewray(v1, odir, &odev.v, + (midx+.5)/odev.hres, (midy+.5)/odev.vres) < -FTINY) return; - } + d = getdistance(midx, midy, odir); /* distance from front plane */ +#ifdef DOBJ + d1 = dobj_trace(NULL, v1, odir); + if (d1 < d) + d = d1; +#endif + if (d < .99*FHUGE) + odev.v.vdist = d + sqrt(dist2(v1, odev.v.vp)); + /* set frame for rendering */ + if ((endx == startx) | (endy == starty)) + 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",