--- ray/src/util/glrad.c 1998/06/09 11:43:18 3.1 +++ ray/src/util/glrad.c 1998/06/09 15:16:55 3.3 @@ -66,7 +66,6 @@ struct { int currentview = 0; /* current view number */ VIEW thisview = STDVIEW; /* displayed view */ VIEW lastview; /* last recorded view */ -char *lastvc = NULL; /* cause of last view change */ char *progname; /* global argv[0] */ char *radfile; /* rad input file */ @@ -80,6 +79,8 @@ int backvis = 1; /* back faces visible? */ int displist; /* our scene display list */ +int in_dev_view = 0; /* currently in dev_view() */ + extern char *fgets(), *fgetline(), *atos(), *scan4var(); extern int nowarn; /* turn warnings off? */ extern time_t time(); @@ -116,10 +117,21 @@ char *argv[]; /* run rad and get views */ runrad(argc-i, argv+i); /* check view */ - if (viewsel != NULL && (currentview = findvw(viewsel)) < 0) { - fprintf(stderr, "%s: no such view\n", viewsel); - quit(1); - } + if (viewsel != NULL) + if (viewsel[0] == '-') { + char *ve = viewsel; + if (!sscanview(&thisview, viewsel) || + (ve = setview(&thisview)) != NULL) { + fprintf(stderr, "%s: bad view: %s\n", + progname, ve); + quit(1); + } + currentview = -1; + } else if ((currentview = findvw(viewsel)) < 0) { + fprintf(stderr, "%s: no such view: %s\n", + progname, viewsel); + quit(1); + } /* open GL */ dev_open(radfile = argv[i]); /* load octree or scene files */ @@ -129,14 +141,14 @@ char *argv[]; } else displist = rgl_filelist(nscenef, scene); /* set initial view */ - dev_view(vwl[currentview].v); + dev_view(currentview < 0 ? &thisview : vwl[currentview].v); /* input/render loop */ while (dev_input(vwintvl)) ; /* all done */ quit(0); userr: - fprintf(stderr, "Usage: %s [-w][-c #secs][-v view] rfile [VAR=value]..\n", + fprintf(stderr, "Usage: %s [-w][-b][-v view] rfile [VAR=value]..\n", argv[0]); quit(1); } @@ -204,6 +216,7 @@ char **av; expval = atof(cp); if (*cp == '-' | *cp == '+') expval = pow(2., expval); + expval *= 0.5; /* compensate for local shading */ } /* look for materials */ while ((cp = scan4var(buf, sizeof(buf), "materials", fp)) != NULL) { @@ -384,6 +397,9 @@ char *id; DisplayHeight(ourdisplay, ourscreen); /* map the window */ XMapWindow(ourdisplay, gwind); + do + dev_input(0); /* get resize event */ + while (hres == 0 & vres == 0); rgl_checkerr("initializing GLX"); } @@ -419,7 +435,7 @@ register VIEW *nv; } if (hres != 0 & vres != 0) { wa = (vres*pheight)/(hres*pwidth); - va = viewaspect(&thisview); + va = viewaspect(nv); if (va > wa+.05) { newvres = (pwidth/pheight)*va*newhres + .5; if (newvres > maxvres) { @@ -434,10 +450,12 @@ register VIEW *nv; } } if (newhres != hres | newvres != vres) { + in_dev_view++; XResizeWindow(ourdisplay, gwind, newhres, newvres); do dev_input(0); /* get resize event */ while (newhres != hres | newvres != vres); + in_dev_view--; } } copystruct(&thisview, nv); @@ -554,7 +572,8 @@ XButtonPressedEvent *ebut; int rootx, rooty, wx, wy; unsigned int statemask; - copylastv("moving"); + copylastv( movorb ? (movdir ? "left/right" : "up/down") : + (movdir ? "fore/back" : "rotate") ); XNoOp(ourdisplay); while (!XCheckMaskEvent(ourdisplay, @@ -609,8 +628,8 @@ register VIEW *vp; { double d, xmin, xmax, ymin, ymax, zmin, zmax; - zmin = 0.05; - zmax = 5000.; + zmin = 0.1; + zmax = 1000.; if (thisview.vfore > FTINY) zmin = thisview.vfore; if (thisview.vaft > FTINY) @@ -654,7 +673,7 @@ register XKeyPressedEvent *ekey; headlocked = 0; break; case 'l': /* retrieve last (premouse) view */ - if (lastvc != NULL) { + if (lastview.type) { VIEW vtmp; copystruct(&vtmp, &thisview); dev_view(&lastview); @@ -728,6 +747,7 @@ int vwnum; vwnum = 0; if (vwnum == currentview) return; + /* copylastv("change view"); */ dev_view(vwl[currentview=vwnum].v); } @@ -768,6 +788,8 @@ VIEW *vp; copylastv(cause) /* copy last view position */ char *cause; { + static char *lastvc; + if (cause == lastvc) return; /* only record one view per cause */ lastvc = cause; @@ -798,6 +820,8 @@ register XConfigureEvent *ersz; glViewport(0, 0, hres=ersz->width, vres=ersz->height); if (hres > maxhres) maxhres = hres; if (vres > maxvres) maxvres = vres; + if (in_dev_view) + return; wa = (vres*pheight)/(hres*pwidth); va = viewaspect(&thisview); if (va > wa+.05) {