コード例 #1
0
ファイル: glrad.c プロジェクト: germolinal/Schedules
static void
zoomview(			/* zoom in or out around (dx,dy) */
	int	pct,
	int	dx,
	int	dy
)
{
	double	h, v;

	if ((pct == 100) | (pct <= 0))
		return;
	copylastv("zooming");
	h = (dx+.5)/hres - 0.5;
	v = (dy+.5)/vres - 0.5;
	h *= (1. - 100./pct);
	v *= (1. - 100./pct);
	thisview.vdir[0] += h*thisview.hvec[0] + v*thisview.vvec[0];
	thisview.vdir[1] += h*thisview.hvec[1] + v*thisview.vvec[1];
	thisview.vdir[2] += h*thisview.hvec[2] + v*thisview.vvec[2];
	thisview.horiz = 2.*180./PI * atan( 100./pct *
					tan(PI/180./2.*thisview.horiz) );
	thisview.vert = 2.*180./PI * atan( 100./pct *
					tan(PI/180./2.*thisview.vert) );
	setview(&thisview);
	dev_view(&thisview);
}
コード例 #2
0
ファイル: glrad.c プロジェクト: germolinal/Schedules
static void
resizewindow(			/* resize window */
	register XConfigureEvent  *ersz
)
{
	static char	resizing[] = "resizing window";
	double	wa, va;

	glViewport(0, 0, hres=ersz->width, vres=ersz->height);
	if (hres > maxhres) maxhres = hres;
	if (vres > maxvres) maxvres = vres;
	if (no_render)
		return;
	wa = (vres*pheight)/(hres*pwidth);
	va = viewaspect(&thisview);
	if (va > wa+.05) {
		copylastv(resizing);
		thisview.vert = 2.*180./PI *
				atan( tan(PI/180./2. * thisview.horiz) * wa );
	} else if (va < wa-.05) {
		copylastv(resizing);
		thisview.horiz = 2.*180./PI *
				atan( tan(PI/180./2. * thisview.vert) / wa );
	} else
		return;
	setview(&thisview);
	dev_view(&thisview);
}
コード例 #3
0
ファイル: tiles.c プロジェクト: Ellorah/chocolate_duke3D
void setviewtotile(short tilenume, int32_t tileWidth, int32_t tileHeight)
{
    int32_t i, j;
    
    /* DRAWROOMS TO TILE BACKUP&SET CODE */
    tiles[tilenume].dim.width = tileWidth;
    tiles[tilenume].dim.height = tileHeight;
    bakxsiz[setviewcnt] = tileWidth;
    bakysiz[setviewcnt] = tileHeight;
    bakvidoption[setviewcnt] = vidoption;
    vidoption = 2;
    bakframeplace[setviewcnt] = frameplace;
    frameplace = tiles[tilenume].data;
    bakwindowx1[setviewcnt] = windowx1;
    bakwindowy1[setviewcnt] = windowy1;
    bakwindowx2[setviewcnt] = windowx2;
    bakwindowy2[setviewcnt] = windowy2;
    copybufbyte(&startumost[windowx1],&bakumost[windowx1],(windowx2-windowx1+1)*sizeof(bakumost[0]));
    copybufbyte(&startdmost[windowx1],&bakdmost[windowx1],(windowx2-windowx1+1)*sizeof(bakdmost[0]));
    setview(0,0,tileHeight-1,tileWidth-1);
    setaspect(65536,65536);
    j = 0;
    for(i=0; i<=tileWidth; i++) {
        ylookup[i] = j;
        j += tileWidth;
    }
    setBytesPerLine(tileHeight);
    setviewcnt++;
}
コード例 #4
0
ファイル: snapview.c プロジェクト: joshuabarnes/zeno
void display(void)
{
    setview();
    render();
    annotate();
    glFlush();
    glutSwapBuffers();
}
コード例 #5
0
ファイル: def.c プロジェクト: mattjakob/s3d
void lookat(View *v, Real vx, Real vy, Real vz,
	    Real px, Real py, Real pz, Real ux, Real uy, Real uz)
{
  setview(v);
  setviewpoint(vx, vy, vz);
  setviewnormal(px - vx ,py - vy, pz - vz);
  setviewup(ux, uy, uz);
  makeviewV();
}
コード例 #6
0
ファイル: def.c プロジェクト: mattjakob/s3d
void orthographic(View *v, Real l, Real b, Real r, Real t, Real near, Real far)
{
  setview(v);
  setprojection(ORTHOGRAPHIC);
  setviewdistance(near);
  setviewdepth(near,far);
  setwindow((l+r)/2, (b+t)/2, (r-l)/2, (t-b)/2);
  makeviewC();
  makeviewO();
}
コード例 #7
0
ファイル: def.c プロジェクト: mattjakob/s3d
void frustrum(View *v, Real l, Real b, Real r, Real t, Real near, Real far)
{
  setview(v);
  setprojection(PERSPECTIVE);
  setviewdistance(near);
  setviewdepth(near,far);
  setwindow((l+r)/2, (b+t)/2, (r-l)/2, (t-b)/2);
  makeviewC();
  makeviewP();
}
コード例 #8
0
ファイル: def.c プロジェクト: mattjakob/s3d
View* initview(void)
{
  setview(NEWSTRUCT(View));
  setviewdefaults();
  makeviewV();
  makeviewC();
  makeviewP();
  makeviewS();
  return getview();
}
コード例 #9
0
ファイル: rhdisp.c プロジェクト: Pizookies/Radiance
static void
new_view(			/* change view parameters */
	register VIEW	*v
)
{
	static VIEW	viewhist[VIEWHISTLEN];
	static unsigned	nhist;
	VIEW	*dv;
	int	i, res[2];
	int16	*slist;
	char	*err;
				/* restore previous view? */
	if (v == NULL) {
		if (nhist > 1)		/* get one before last setting */
			nhist--;
		else			/* else go to end of list */
			while (nhist < VIEWHISTLEN && viewhist[nhist].type)
				nhist++;
		v = viewhist + ((nhist-1)%VIEWHISTLEN);
	} else
again:
	if ((err = setview(v)) != NULL) {
		error(COMMAND, err);
		return;
	}
	if (!dev_view(v))	/* notify display driver */
		goto again;
	if (v->type == VT_PAR) {
		error(COMMAND, "cannot handle parallel views");
		return;
	}
	beam_init(odev.firstuse);	/* compute new beam set */
	for (i = 0; (dv = dev_auxview(i, res)) != NULL; i++) {
		if ((slist = beam_view(dv, res[0], res[1])) == NULL) {
			if (!nhist) {
				error(COMMAND, "invalid starting view");
				return;
			}
			*v = *(viewhist + ((nhist-1)%VIEWHISTLEN));
			goto again;	/* XXX overloading dev_section()? */
		}
		DCHECK(*slist < 0, WARNING, "no visible sections in new_view");
		for ( ; *slist >= 0; slist++)
			dev_section(hdgfn[*slist], hdpfn[*slist]);
	}
	dev_section(NULL,NULL);	/* end section list */
	dev_flush();		/* update display */
				/* update server */
	imm_mode = beam_sync(odev.firstuse) > 0;
				/* record new view */
	if (v < viewhist || v >= viewhist+VIEWHISTLEN) {
		*(viewhist + (nhist%VIEWHISTLEN)) = *v;
		nhist++;
	}
}
コード例 #10
0
ファイル: def.c プロジェクト: mattjakob/s3d
void camera(View *v, Real rx, Real ry, Real rz, Real nx, Real ny, Real nz
     , Real ux, Real uy, Real uz, Real deye)
{
  setview(v);
  setviewup(ux, uy, uz);
  setviewnormal(nx, ny, nz);
  setviewpoint(rx - (v->normal.x*deye),
	       ry - (v->normal.y*deye),
	       rz - (v->normal.z*deye));
  makeviewV();
}
コード例 #11
0
ファイル: def.c プロジェクト: mattjakob/s3d
void polarview(View *v, Real dist, Real azimuth, Real pich, Real roll)
{
  setview(v);
  setviewnormal(sin(azimuth)*cos(pich),	cos(azimuth)*cos(pich), sin(pich));
  setviewpoint(-dist * v->normal.x,-dist * v->normal.y, -dist * v->normal.z );
  if (fabs(v->normal.x) < ROUNDOFF && fabs(v->normal.y) < ROUNDOFF)
    setviewup(sin(roll)*v->normal.z, -cos(roll)*v->normal.z,0.0);
  else
    setviewup(sin(roll)*v->normal.y, -sin(roll)*v->normal.x,
	      cos(roll)*hypot(v->normal.x,v->normal.y));
  makeviewV();
}
コード例 #12
0
ファイル: def.c プロジェクト: mattjakob/s3d
void perspective(View *v, Real fov, Real ar, Real near, Real far)
{
  setview(v);
  setprojection(PERSPECTIVE);
  setviewdistance(near);
  setviewdepth(near,far);
  if (ar < ROUNDOFF)
    error("illegal aspect ratio");
  setwindow(0, 0, tan(fov/2) * near, (tan(fov/2) * near)/ar);
  makeviewC();
  makeviewP();
}
コード例 #13
0
ファイル: xshowtrace.c プロジェクト: Pizookies/Radiance
int
main(		/* takes both the octree and the image */
	int	argc,
	char	*argv[]
)
{
	int	i;
	char	combuf[PATH_MAX];

	progname = argv[0];
	for (i = 1; i < argc-2; i++)
		if (!strcmp(argv[i], "-s"))
			slow++;
		else if (!strcmp(argv[i], "-T"))
			strcat(rtcom, " -oTp");
		else
			break;
	if (i > argc-2) {
		fprintf(stderr, "Usage: %s [-s][-T] [rtrace args] octree picture\n",
				progname);
		exit(1);
	}
	picture = argv[argc-1];
					/* get the viewing parameters */
	if (viewfile(picture, &ourview, &ourres) <= 0 ||
			setview(&ourview) != NULL) {
		fprintf(stderr, "%s: cannot get view from \"%s\"\n",
				progname, picture);
		exit(1);
	}
					/* open the display */
	if ((theDisplay = XOpenDisplay(NULL)) == NULL) {
		fprintf(stderr,
		"%s: cannot open display; DISPLAY variable set?\n",
				progname);
		exit(1);
	}
					/* build input command */
	sprintf(combuf, "%s \"%s\" | %s", xicom, picture, rtcom);
	for ( ; i < argc-1; i++) {
		strcat(combuf, " ");
		strcat(combuf, argv[i]);
	}
					/* start the damn thing */
	if ((pin = popen(combuf, "r")) == NULL)
		exit(1);
					/* loop on input */
	mainloop();
					/* close pipe and exit */
	pclose(pin);
	exit(0);
}
コード例 #14
0
static int
moveview(	/* move our view */
	int	dx,
	int	dy,
	int	mov,
	int	orb
)
{
	VIEW	nv;
	FVECT	odir, v1;
	double	d;
	int	li;
				/* start with old view */
	nv = odev.v;
				/* change view direction */
	if (mov | orb) {
		if ((li = qtFindLeaf(dx, dy)) < 0)
			return(0);	/* not on window */
		VSUM(odir, qtL.wp[li], nv.vp, -1.);
	} else {
		if (viewray(nv.vp, nv.vdir, &odev.v,
				(dx+.5)/odev.hres, (dy+.5)/odev.vres) < -FTINY)
			return(0);	/* outside view */
	}
	if (orb && mov) {		/* orbit left/right */
		spinvector(odir, odir, nv.vup, d=MOVDEG*PI/180.*mov);
		VSUM(nv.vp, qtL.wp[li], odir, -1.);
		spinvector(nv.vdir, nv.vdir, nv.vup, d);
	} else if (orb) {		/* orbit up/down */
		if (geodesic(odir, odir, nv.vup,
				d=MOVDEG*PI/180.*orb, GEOD_RAD) == 0.0)
			return(0);
		VSUM(nv.vp, qtL.wp[li], odir, -1.);
		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);
	}
	if (!mov ^ !orb && headlocked) {	/* restore head height */
		VSUM(v1, odev.v.vp, nv.vp, -1.);
		d = DOT(v1, odev.v.vup);
		VSUM(nv.vp, nv.vp, odev.v.vup, d);
	}
	if (setview(&nv) != NULL)
		return(0);	/* illegal view */
	dev_view(&nv);
	inpresflags |= DFL(DC_SETVIEW);
	return(1);
}
コード例 #15
0
ファイル: rv3.c プロジェクト: Pizookies/Radiance
void
newview(					/* change viewing parameters */
	VIEW  *vp
)
{
	char  *err;

	if ((err = setview(vp)) != NULL) {
		sprintf(errmsg, "view not set - %s", err);
		error(COMMAND, errmsg);
	} else if (memcmp((char *)vp, (char *)&ourview, sizeof(VIEW))) {
		oldview = ourview;
		ourview = *vp;
		newimage(NULL);
	}
}
コード例 #16
0
ファイル: glrad.c プロジェクト: germolinal/Schedules
static int
moveview(	/* move our view */
	int	dx,
	int	dy,
	int	mov,
	int	orb
)
{
	VIEW	nv;
	FVECT	odir, v1, wp;
	double	d;
				/* start with old view */
	nv = thisview;
				/* change view direction */
	if ((d = viewray(v1, odir, &thisview,
			(dx+.5)/hres, (dy+.5)/vres)) < -FTINY)
		return(0);		/* outside view */
	if (mov | orb) {
		if (!getintersect(wp, v1, odir, d))
			return(0);
		VSUM(odir, wp, nv.vp, -1.);
	} else
		VCOPY(nv.vdir, odir);
	if (orb && mov) {		/* orbit left/right */
		spinvector(odir, odir, nv.vup, d=MOVDEG*PI/180.*mov);
		VSUM(nv.vp, wp, odir, -1.);
		spinvector(nv.vdir, nv.vdir, nv.vup, d);
	} else if (orb) {		/* orbit up/down */
		if (geodesic(odir, odir, nv.vup,
				d=MOVDEG*PI/180.*orb, GEOD_RAD) == 0.0)
			return(0);
		VSUM(nv.vp, wp, odir, -1.);
		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);
	}
	if (!mov ^ !orb && headlocked) {	/* restore head height */
		VSUM(v1, thisview.vp, nv.vp, -1.);
		d = DOT(v1, thisview.vup);
		VSUM(nv.vp, nv.vp, thisview.vup, d);
	}
	if (setview(&nv) != NULL)
		return(0);	/* illegal view */
	dev_view(&nv);
	return(1);
}
コード例 #17
0
ファイル: pcomb.c プロジェクト: germolinal/Schedules
static void
checkfile(void)			/* ready a file */
{
	register int	i;
					/* process header */
	gotview = 0;
	if (echoheader) {
		fputs(input[nfiles].name, stdout);
		fputs(":\n", stdout);
	}
	getheader(input[nfiles].fp, headline, NULL);
	if (wrongformat < 0) {
		eputs(input[nfiles].name);
		eputs(": not a Radiance picture\n");
		quit(1);
	}
	if (wrongformat > 0) {
		wputs(input[nfiles].name);
		wputs(": warning -- incompatible picture format\n");
	}
	if (!gotview || setview(&input[nfiles].vw) != NULL)
		input[nfiles].vw.type = 0;
	if (!fgetsresolu(&input[nfiles].rs, input[nfiles].fp)) {
		eputs(input[nfiles].name);
		eputs(": bad picture size\n");
		quit(1);
	}
	if (xmax == 0 && ymax == 0) {
		xmax = scanlen(&input[nfiles].rs);
		ymax = numscans(&input[nfiles].rs);
	} else if (scanlen(&input[nfiles].rs) != xmax ||
			numscans(&input[nfiles].rs) != ymax) {
		eputs(input[nfiles].name);
		eputs(": resolution mismatch\n");
		quit(1);
	}
					/* allocate scanlines */
	for (i = 0; i < WINSIZ; i++)
		input[nfiles].scan[i] = (COLOR *)emalloc(xmax*sizeof(COLOR));
}
コード例 #18
0
ファイル: pcond.c プロジェクト: Pizookies/Radiance
static void
getahead(void)			/* load picture header */
{
	char	*err;

	getheader(infp, headline, NULL);
	if (lumf == NULL || !fgetsresolu(&inpres, infp)) {
		fprintf(stderr, "%s: %s: not a Radiance picture\n",
			progname, infn);
		exit(1);
	}
	if (lumf == rgblum)
		comprgb2xyzWBmat(inrgb2xyz, inprims);
	else if (mbcalfile != NULL) {
		fprintf(stderr, "%s: macbethcal only works with RGB pictures\n",
				progname);
		exit(1);
	}
	if (!gotview || ourview.type == VT_PAR ||
			(ourview.horiz <= 5.) | (ourview.vert <= 5.)) {
		ourview = stdview;
		ourview.type = VT_PER;
		if (pixaspect*inpres.yr < inpres.xr) {
			ourview.horiz = 40.0;
			ourview.vert = 2.*180./PI *
				atan(.3639702*pixaspect*inpres.yr/inpres.xr);
		} else {
			ourview.vert = 40.0;
			ourview.horiz = 2.*180./PI *
				atan(.3639702*inpres.xr/pixaspect/inpres.yr);
		}
	}
	if ((err = setview(&ourview)) != NULL) {
		fprintf(stderr, "%s: view error in picture \"%s\": %s\n",
			progname, infn, err);
		exit(1);
	}
}
コード例 #19
0
ファイル: xglaresrc.c プロジェクト: germolinal/Schedules
static void
init(		/* get view and find window */
    char	*pname,
    char	*wname
)
{
    extern Window	xfindwind();
    XWindowAttributes	wa;
    XColor	xc;
    XGCValues	gcv;
    register int	i;
    /* get the viewing parameters */
    if (viewfile(pname, &ourview, &pres) <= 0 ||
            setview(&ourview) != NULL) {
        fprintf(stderr, "%s: cannot get view from \"%s\"\n",
                progname, pname);
        exit(1);
    }
    /* open the display */
    if ((theDisplay = XOpenDisplay(NULL)) == NULL) {
        fprintf(stderr,
                "%s: cannot open display; DISPLAY variable set?\n",
                progname);
        exit(1);
    }
    /* find our window */
    if (wname == NULL) {
        /* remove directory prefix from name */
        for (i = strlen(pname); i-- > 0; )
            if (pname[i] == '/')
                break;
        wname = pname+i+1;
        i = 0;
    } else
        i = 1;
    gwind = xfindwind(theDisplay, rwind, wname, 4);
    if (gwind == None) {
        if (i) {
            fprintf(stderr, "%s: cannot find \"%s\" window\n",
                    progname, wname);
            exit(2);
        }
        /* start ximage */
        if (fork() == 0) {
            execlp(XIM, XIM, "-c", "256", pname, 0);
            perror(XIM);
            fprintf(stderr, "%s: cannot start %s\n",
                    progname, XIM);
            kill(getppid(), SIGPIPE);
            _exit(1);
        }
        do
            sleep(8);
        while ((gwind=xfindwind(theDisplay,rwind,wname,4)) == None);
    } else
        XMapRaised(theDisplay, gwind);
    do {
        XGetWindowAttributes(theDisplay, gwind, &wa);
        sleep(6);
    } while (wa.map_state != IsViewable);
    if (wa.width != scanlen(&pres) || wa.height != numscans(&pres)) {
        fprintf(stderr,
                "%s: warning -- window seems to be the wrong size!\n",
                progname);
        if (pres.rt & YMAJOR) {
            pres.xr = wa.width;
            pres.yr = wa.height;
        } else {
            pres.xr = wa.height;
            pres.yr = wa.width;
        }
    }
    /* set graphics context */
    gcv.font = XLoadFont(theDisplay, FONTNAME);
    if (gcv.font == 0) {
        fprintf(stderr, "%s: cannot load font \"%s\"\n",
                progname, FONTNAME);
        exit(1);
    }
    xc.red = col[0] >= 1.0 ? 65535 : (unsigned)(65536*col[0]);
    xc.green = col[1] >= 1.0 ? 65535 : (unsigned)(65536*col[1]);
    xc.blue = col[2] >= 1.0 ? 65535 : (unsigned)(65536*col[2]);
    xc.flags = DoRed|DoGreen|DoBlue;
    gcv.background = xc.green >= 32768 ?
                     BlackPixel(theDisplay,DefaultScreen(theDisplay)) :
                     WhitePixel(theDisplay,DefaultScreen(theDisplay)) ;
    if (XAllocColor(theDisplay, wa.colormap, &xc)) {
        gcv.foreground = xc.pixel;
        vecGC = XCreateGC(theDisplay,gwind,
                          GCForeground|GCBackground|GCFont,&gcv);
        strGC = vecGC;
    } else {
        gcv.function = GXinvert;
        vecGC = XCreateGC(theDisplay,gwind,GCFunction,&gcv);
        gcv.foreground = xc.green < 32768 ?
                         BlackPixel(theDisplay,DefaultScreen(theDisplay)) :
                         WhitePixel(theDisplay,DefaultScreen(theDisplay)) ;
        strGC = XCreateGC(theDisplay,gwind,
                          GCForeground|GCBackground|GCFont,&gcv);
    }
}
コード例 #20
0
ファイル: rhdisp.c プロジェクト: Pizookies/Radiance
static void
set_focus(			/* set focus frame */
	char	*args
)
{
	double	hcent, vcent, hsiz, vsiz;
	VIEW	*dv, vwfocus;
	int	i, res[2];

	i = sscanf(args, "%lf %lf %lf %lf", &hcent, &vcent, &hsiz, &vsiz);
	if (i < 2 || hcent < 0 || hcent > 1 || vcent < 0 || vcent > 1) {
		beam_init(0);				/* restore view */
		for (i = 0; (dv = dev_auxview(i, res)) != NULL; i++)
			beam_view(dv, res[0], res[1]);
		beam_sync(0);				/* update server */
		return;
	}
	if (i < 4 || hsiz <= hcent || hsiz > 1 || vsiz <= vcent || vsiz > 1)
		hsiz = vsiz = FSIZDEF;			/* gave center only */
	else {
		hsiz -= hcent; hcent += 0.5*hsiz;	/* gave min and max */
		vsiz -= vcent; vcent += 0.5*vsiz;
	}
	beam_init(0);					/* add basic views */
	for (i = 0; (dv = dev_auxview(i, res)) != NULL; i++)
		beam_view(dv, res[0]>>4, res[1]>>4);
	vwfocus = odev.v;			/* add focus view */
	switch (odev.v.type) {
	case VT_PER:
		vwfocus.horiz = 2.*180./PI*atan(
				hsiz * tan(PI/180./2.*odev.v.horiz) );
		vwfocus.vert = 2.*180./PI*atan(
				vsiz * tan(PI/180./2.*odev.v.vert) );
		break;
	case VT_PAR:
	case VT_ANG:
		vwfocus.horiz = hsiz * odev.v.horiz;
		vwfocus.vert = vsiz * odev.v.vert;
		break;
	case VT_PLS:
		vwfocus.horiz = hsiz * sin((PI/180./2.)*odev.v.horiz) /
				(1.0 + cos((PI/180./2.)*odev.v.horiz));
		vwfocus.horiz *= vwfocus.horiz;
		vwfocus.horiz = (2.*180./PI)*acos((1. - vwfocus.horiz) /
						(1. + vwfocus.horiz));
		vwfocus.vert = vsiz * sin((PI/180./2.)*odev.v.vert) /
				(1.0 + cos((PI/180./2.)*odev.v.vert));
		vwfocus.vert *= vwfocus.vert;
		vwfocus.vert = (2.*180./PI)*acos((1. - vwfocus.vert) /
						(1. + vwfocus.vert));
		break;
	case VT_HEM:
		vwfocus.horiz = 2.*180./PI*asin(
				hsiz * sin(PI/180./2.*odev.v.horiz) );
		vwfocus.vert = 2.*180./PI*asin(
				vsiz * sin(PI/180./2.*odev.v.vert) );
		break;
	case VT_CYL:
		vwfocus.horiz = hsiz * odev.v.horiz;
		vwfocus.vert = 2.*180./PI*atan(
				vsiz * tan(PI/180./2.*odev.v.vert) );
		break;
	default:
		error(INTERNAL, "bad view type in set_focus");
	}
	vwfocus.hoff = (odev.v.hoff + hcent - 0.5)/hsiz;
	vwfocus.voff = (odev.v.voff + vcent - 0.5)/vsiz;
	setview(&vwfocus);
	beam_view(&vwfocus, (int)(3*odev.hres*hsiz)+100,
			(int)(3*odev.vres*vsiz)+100);
	beam_sync(0);					/* update server */
}
コード例 #21
0
ファイル: glwidget.cpp プロジェクト: cheque/s3d
void GLWidget::keyPressEvent(QKeyEvent *event)
{
    Matrix4 M;
    Vector3 Dir;
    switch (event->key()) {
    case Qt::Key_Q:
    case Qt::Key_A:
        M = m4_rotate('y', 0.5);
        scene->view->center = v3_m4mult(scene->view->center,M);
        scene->view->normal = v3_m4mult(scene->view->normal,M);
        makeviewV();
        setview(scene->view);
        break;
    case Qt::Key_D:
        M = m4_rotate('y', -0.5);
        scene->view->center = v3_m4mult(scene->view->center,M);
        scene->view->normal = v3_m4mult(scene->view->normal,M);
        makeviewV();
        setview(scene->view);
        break;
    case Qt::Key_W:
        M = m4_rotate('x', 0.5);
        scene->view->center = v3_m4mult(scene->view->center,M);
        scene->view->up = v3_m4mult(scene->view->up,M);
        scene->view->normal = v3_m4mult(scene->view->normal,M);
        makeviewV();
        setview(scene->view);
        break;
    case Qt::Key_S:
        M = m4_rotate('x', -0.5);
        scene->view->center = v3_m4mult(scene->view->center,M);
        scene->view->up = v3_m4mult(scene->view->up,M);
        scene->view->normal = v3_m4mult(scene->view->normal,M);
        makeviewV();
        setview(scene->view);
        break;
    case Qt::Key_Left:
        Dir = v3_cross(scene->view->up,scene->view->normal);
        scene->view->center = v3_add(scene->view->center,v3_scale(0.5,Dir));
        makeviewV();
        setview(scene->view);
        break;
    case Qt::Key_Right:
        Dir = v3_cross(scene->view->up,scene->view->normal);
        scene->view->center = v3_sub(scene->view->center,v3_scale(0.5,Dir));
        makeviewV();
        setview(scene->view);
        break;
    case Qt::Key_Up:
        scene->view->center = v3_add(scene->view->center,v3_scale(0.5,scene->view->up));
        makeviewV();
        setview(scene->view);
        break;
    case Qt::Key_Down:
        scene->view->center = v3_sub(scene->view->center,v3_scale(0.5,scene->view->up));
        makeviewV();
        setview(scene->view);
        break;

    case Qt::Key_Escape:
           exit(0);
           break;
    case Qt::Key_R:
        if (!lastfile.isEmpty())
            load_scene_file(lastfile.toLatin1().data());
        break;
    }
    update();
}
コード例 #22
0
ファイル: rpmain.c プロジェクト: germolinal/Schedules
int
main(int  argc, char  *argv[])
{
#define	 check(ol,al)		if (argv[i][ol] || \
				badarg(argc-i-1,argv+i+1,al)) \
				goto badopt
#define	 bool(olen,var)		switch (argv[i][olen]) { \
				case '\0': var = !var; break; \
				case 'y': case 'Y': case 't': case 'T': \
				case '+': case '1': var = 1; break; \
				case 'n': case 'N': case 'f': case 'F': \
				case '-': case '0': var = 0; break; \
				default: goto badopt; }
	char  *err;
	char  *recover = NULL;
	char  *outfile = NULL;
	char  *zfile = NULL;
	int  loadflags = ~IO_FILES;
	int  seqstart = 0;
	int  persist = 0;
	int  duped1 = -1;
	int  rval;
	int  i;
					/* record start time */
	tstart = time((time_t *)NULL);
					/* global program name */
	progname = argv[0] = fixargv0(argv[0]);
					/* option city */
	for (i = 1; i < argc; i++) {
						/* expand arguments */
		while ((rval = expandarg(&argc, &argv, i)) > 0)
			;
		if (rval < 0) {
			sprintf(errmsg, "cannot expand '%s'", argv[i]);
			error(SYSTEM, errmsg);
		}
		if (argv[i] == NULL || argv[i][0] != '-')
			break;			/* break from options */
		if (!strcmp(argv[i], "-version")) {
			puts(VersionID);
			quit(0);
		}
		if (!strcmp(argv[i], "-defaults") ||
				!strcmp(argv[i], "-help")) {
			printdefaults();
			quit(0);
		}
		rval = getrenderopt(argc-i, argv+i);
		if (rval >= 0) {
			i += rval;
			continue;
		}
		rval = getviewopt(&ourview, argc-i, argv+i);
		if (rval >= 0) {
			i += rval;
			continue;
		}
						/* rpict options */
		switch (argv[i][1]) {
		case 'v':				/* view file */
			if (argv[i][2] != 'f')
				goto badopt;
			check(3,"s");
			rval = viewfile(argv[++i], &ourview, NULL);
			if (rval < 0) {
				sprintf(errmsg,
				"cannot open view file \"%s\"",
						argv[i]);
				error(SYSTEM, errmsg);
			} else if (rval == 0) {
				sprintf(errmsg,
					"bad view file \"%s\"",
						argv[i]);
				error(USER, errmsg);
			}
			break;
		case 'p':				/* pixel */
			switch (argv[i][2]) {
			case 's':				/* sample */
				check(3,"i");
				psample = atoi(argv[++i]);
				break;
			case 't':				/* threshold */
				check(3,"f");
				maxdiff = atof(argv[++i]);
				break;
			case 'j':				/* jitter */
				check(3,"f");
				dstrpix = atof(argv[++i]);
				break;
			case 'a':				/* aspect */
				check(3,"f");
				pixaspect = atof(argv[++i]);
				break;
			case 'm':				/* motion */
				check(3,"f");
				mblur = atof(argv[++i]);
				break;
			case 'd':				/* aperture */
				check(3,"f");
				dblur = atof(argv[++i]);
				break;
			default:
				goto badopt;
			}
			break;
		case 'x':				/* x resolution */
			check(2,"i");
			hresolu = atoi(argv[++i]);
			break;
		case 'y':				/* y resolution */
			check(2,"i");
			vresolu = atoi(argv[++i]);
			break;
		case 'S':				/* slave index */
			check(2,"i");
			seqstart = atoi(argv[++i]);
			break;
		case 'o':				/* output file */
			check(2,"s");
			outfile = argv[++i];
			break;
		case 'z':				/* z file */
			check(2,"s");
			zfile = argv[++i];
			break;
		case 'r':				/* recover file */
			if (argv[i][2] == 'o') {		/* +output */
				check(3,"s");
				outfile = argv[i+1];
			} else
				check(2,"s");
			recover = argv[++i];
			break;
		case 't':				/* timer */
			check(2,"i");
			ralrm = atoi(argv[++i]);
			break;
#ifdef  PERSIST
		case 'P':				/* persist file */
			if (argv[i][2] == 'P') {
				check(3,"s");
				persist = PARALLEL;
			} else {
				check(2,"s");
				persist = PERSIST;
			}
			persistfile(argv[++i]);
			break;
#endif
		case 'w':				/* warnings */
			rval = erract[WARNING].pf != NULL;
			bool(2,rval);
			if (rval) erract[WARNING].pf = wputs;
			else erract[WARNING].pf = NULL;
			break;
		case 'e':				/* error file */
			check(2,"s");
			errfile = argv[++i];
			break;
		default:
			goto badopt;
		}
	}
	err = setview(&ourview);	/* set viewing parameters */
	if (err != NULL)
		error(USER, err);
					/* initialize object types */
	initotypes();
					/* initialize urand */
	if (rand_samp) {
		srandom((long)time(0));
		initurand(0);
	} else {
		srandom(0L);
		initurand(2048);
	}
					/* set up signal handling */
	sigdie(SIGINT, "Interrupt");
#ifdef SIGHUP
	sigdie(SIGHUP, "Hangup");
#endif
	sigdie(SIGTERM, "Terminate");
#ifdef SIGPIPE
	sigdie(SIGPIPE, "Broken pipe");
#endif
#ifdef SIGALRM
	sigdie(SIGALRM, "Alarm clock");
#endif
#ifdef	SIGXCPU
	sigdie(SIGXCPU, "CPU limit exceeded");
	sigdie(SIGXFSZ, "File size exceeded");
#endif
					/* open error file */
	if (errfile != NULL) {
		if (freopen(errfile, "a", stderr) == NULL)
			quit(2);
		fprintf(stderr, "**************\n*** PID %5d: ",
				getpid());
		printargs(argc, argv, stderr);
		putc('\n', stderr);
		fflush(stderr);
	}
#ifdef	NICE
	nice(NICE);			/* lower priority */
#endif
					/* get octree */
	if (i == argc)
		octname = NULL;
	else if (i == argc-1)
		octname = argv[i];
	else
		goto badopt;
	if (seqstart > 0 && octname == NULL)
		error(USER, "missing octree argument");
					/* set up output */
#ifdef  PERSIST
	if (persist) {
		if (recover != NULL)
			error(USER, "persist option used with recover file");
		if (seqstart <= 0)
			error(USER, "persist option only for sequences");
		if (outfile == NULL)
		duped1 = dup(fileno(stdout));	/* don't lose our output */
		openheader();
	} else
#endif
	if (outfile != NULL)
		openheader();
#ifdef	_WIN32
	SET_FILE_BINARY(stdout);
	if (octname == NULL)
		SET_FILE_BINARY(stdin);
#endif
	readoct(octname, loadflags, &thescene, NULL);
	nsceneobjs = nobjects;

	if (loadflags & IO_INFO) {	/* print header */
		printargs(i, argv, stdout);
		printf("SOFTWARE= %s\n", VersionID);
	}

	marksources();			/* find and mark sources */

	setambient();			/* initialize ambient calculation */

#ifdef  PERSIST
	if (persist) {
		fflush(stdout);
		if (outfile == NULL) {		/* reconnect stdout */
			dup2(duped1, fileno(stdout));
			close(duped1);
		}
		if (persist == PARALLEL) {	/* multiprocessing */
			preload_objs();		/* preload scene */
			shm_boundary = (char *)malloc(16);
			strcpy(shm_boundary, "SHM_BOUNDARY");
			while ((rval=fork()) == 0) {	/* keep on forkin' */
				pflock(1);
				pfhold();
				tstart = time((time_t *)NULL);
				ambsync();		/* load new values */
			}
			if (rval < 0)
				error(SYSTEM, "cannot fork child for persist function");
			pfdetach();		/* parent will run then exit */
		}
	}
runagain:
	if (persist) {
		if (outfile == NULL)			/* if out to stdout */
			dupheader();			/* send header */
		else					/* if out to file */
			duped1 = dup(fileno(stdout));	/* hang onto pipe */
	}
#endif
					/* batch render picture(s) */
	rpict(seqstart, outfile, zfile, recover);
					/* flush ambient file */
	ambsync();
#ifdef  PERSIST
	if (persist == PERSIST) {	/* first run-through */
		if ((rval=fork()) == 0) {	/* child loops until killed */
			pflock(1);
			persist = PCHILD;
		} else {			/* original process exits */
			if (rval < 0)
				error(SYSTEM, "cannot fork child for persist function");
			pfdetach();		/* parent exits */
		}
	}
	if (persist == PCHILD) {	/* wait for a signal then go again */
		if (outfile != NULL)
			close(duped1);		/* release output handle */
		pfhold();
		tstart = time((time_t *)NULL);	/* reinitialize */
		raynum = nrays = 0;
		goto runagain;
	}
#endif
	quit(0);

badopt:
	sprintf(errmsg, "command line error at '%s'", argv[i]);
	error(USER, errmsg);
	return 1; /* pro forma return */

#undef	check
#undef	bool
}
コード例 #23
0
ファイル: rhcopy.c プロジェクト: Pizookies/Radiance
void
addpicz(		/* add a picture + depth-buffer */
	char	*pcf,
	char	*zbf
)
{
	FILE	*pfp;
	int	zfd;
	COLR	*cscn;
	float	*zscn;
	struct phead	phd;
	int	eshft;
	double	emult;
	RESOLU	prs;
	RREAL	vl[2];
	FVECT	ro, rd;
	double	aftd;
	COLOR	ctmp;
	int	j;
	register int	i;
				/* open files */
	if ((pfp = fopen(pcf, "r")) == NULL) {
		sprintf(errmsg, "cannot open picture file \"%s\"", pcf);
		error(SYSTEM, pcf);
	}
	if ((zfd = open(zbf, O_RDONLY)) < 0) {
		sprintf(errmsg, "cannot open depth file \"%s\"", zbf);
		error(SYSTEM, pcf);
	}
				/* load picture header */
	phd.vw = stdview;
	phd.expos = 1.0;
	phd.badfmt = phd.gotview = phd.altprims = 0;
	if (getheader(pfp, picheadline, &phd) < 0 ||
			phd.badfmt || !fgetsresolu(&prs, pfp)) {
		sprintf(errmsg, "bad format for picture file \"%s\"", pcf);
		error(USER, errmsg);
	}
	if (!phd.gotview || setview(&phd.vw) != NULL) {
		sprintf(errmsg, "missing/illegal view in picture \"%s\"",
				pcf);
		error(USER, errmsg);
	}
	if (phd.altprims) {
		sprintf(errmsg, "ignoring primary values in picture \"%s\"",
				pcf);
		error(WARNING, errmsg);
	}
				/* figure out what to do about exposure */
	if ((phd.expos < 0.99) | (phd.expos > 1.01)) {
		emult = -log(phd.expos)/log(2.);
		eshft = emult >= 0. ? emult+.5 : emult-.5;
		emult -= (double)eshft;
		if ((emult <= 0.01) & (emult >= -0.01))
			emult = -1.;
		else {
			emult = 1./phd.expos;
			eshft = 0;
		}
	} else {
		emult = -1.;
		eshft = 0;
	}
				/* allocate buffers */
	cscn = (COLR *)malloc(scanlen(&prs)*sizeof(COLR));
	zscn = (float *)malloc(scanlen(&prs)*sizeof(float));
	if ((cscn == NULL) | (zscn == NULL))
		error(SYSTEM, "out of memory in addpicz");
				/* read and process each scanline */
	for (j = 0; j < numscans(&prs); j++) {
		i = scanlen(&prs);			/* read colrs */
		if (freadcolrs(cscn, i, pfp) < 0) {
			sprintf(errmsg, "error reading picture \"%s\"", pcf);
			error(USER, errmsg);
		}
		if (eshft)				/* shift exposure */
			shiftcolrs(cscn, i, eshft);
		i *= sizeof(float);			/* read depth */
		if (read(zfd, (char *)zscn, i) != i) {
			sprintf(errmsg, "error reading depth file \"%s\"", zbf);
			error(USER, errmsg);
		}
		for (i = scanlen(&prs); i--; ) {	/* do each pixel */
			pix2loc(vl, &prs, i, j);
			aftd = viewray(ro, rd, &phd.vw, vl[0], vl[1]);
			if (aftd < -FTINY)
				continue;		/* off view */
			if (aftd > FTINY && zscn[i] > aftd)
				continue;		/* aft clipped */
			if (emult > 0.) {		/* whatta pain */
				colr_color(ctmp, cscn[i]);
				scalecolor(ctmp, emult);
				setcolr(cscn[i], colval(ctmp,RED),
					colval(ctmp,GRN), colval(ctmp,BLU));
			}
			addray(ro, rd, (double)zscn[i], cscn[i]);
		}
	}
				/* write output and free beams */
	hdflush(NULL);
				/* clean up */
	free((void *)cscn);
	free((void *)zscn);
	fclose(pfp);
	close(zfd);
}
コード例 #24
0
ファイル: def.c プロジェクト: mattjakob/s3d
void viewport(View *v, Real l, Real b, Real w, Real h)
{
  setview(v);
  setviewport(l,b,l+w,b+h,-32767.,32767.);
  makeviewS();
}
コード例 #25
0
ファイル: main.cpp プロジェクト: 3deggi/roadtrac
void setviewfromhomography(CvMat* h**o)
{
	CvMat* intrinsic = cvCreateMat(3,3, MAT_TYPE);
	cvZero(intrinsic);

	double fx = 531.398682;
	double fy = 531.806702;
	double cx = 308.162262;
	double cy = 231.762756;

	cvmSet(intrinsic, 0,0, fx);
	cvmSet(intrinsic, 1,1, fy);
	cvmSet(intrinsic, 0,2, cx);
	cvmSet(intrinsic, 1,2, cy);
	cvmSet(intrinsic, 2,2, 1);			
	
	CvMat* inv =  cvCreateMat(3,3, MAT_TYPE);
	cvInvert(intrinsic, inv);
	
	CvMat* rdt0 =  cvCreateMat(3,3, MAT_TYPE);

	cvMatMul(inv, h**o, rdt0);
	
	CvMat* rdt =  cvCreateMat(3,3, MAT_TYPE);
	
	double dvd = sqrt(cvmGet(rdt0,0, 0)*cvmGet(rdt0,0, 0)+cvmGet(rdt0,1, 0)*cvmGet(rdt0,1, 0)+cvmGet(rdt0,2, 0)*cvmGet(rdt0,2, 0));
	if (dvd==0)
		return;

	double norm = (double) ((double) 1.0/dvd);

	for(int i=0;i<3;i++){
		for(int j=0;j<3;j++){
			cvmSet(rdt, i,j, cvmGet(rdt0,i,j)*norm);
		}
	}
	
	CvMat *r1 = cvCreateMat(3,1, MAT_TYPE);
	CvMat *r2 = cvCreateMat(3,1, MAT_TYPE);
	CvMat *r1xr2 = cvCreateMat(3,1, MAT_TYPE);	
	
	for (int i=0;i<3;i++)
	{
		cvmSet(r1, i, 0, cvmGet(rdt,i, 0));
		cvmSet(r2, i, 0, cvmGet(rdt,i, 1));
	}
	
	cvCrossProduct(r1, r2, r1xr2);
	
	CvMat* R = cvCreateMat(3,3, MAT_TYPE);
	CvMat* t = cvCreateMat(3,1, MAT_TYPE);

	cvZero(R);
	cvZero(t);

	for(int y=0;y<2;y++){
		for(int x=0;x<3;x++){
			cvmSet(R, x,y, cvmGet(rdt,x,y));
		}
	}

	for(int x=0;x<3;x++){
		cvmSet(R, x,2,-cvmGet(r1xr2,x,0));
		cvmSet(t, 0,x,cvmGet(rdt,x,2));
	}
	
	setview(R, t, view);
	
	cvReleaseMat(&R);
	cvReleaseMat(&t);
	cvReleaseMat(&r1);
	cvReleaseMat(&r2);
	cvReleaseMat(&rdt);
	cvReleaseMat(&r1xr2);
	cvReleaseMat(&rdt0);
	cvReleaseMat(&inv);
	cvReleaseMat(&intrinsic);
}
コード例 #26
0
ファイル: glrad.c プロジェクト: germolinal/Schedules
int
main(
	int	argc,
	char	*argv[]
)
{
	char	*viewsel = NULL;
	long	vwintvl = 0;
	int	i;

	progname = argv[0];
	for (i = 1; i < argc && argv[i][0] == '-'; i++)
		switch (argv[i][1]) {
		case 'v':
			viewsel = argv[++i];
			break;
		case 'w':
			nowarn = !nowarn;
			break;
		case 's':
			silent = !silent;
			break;
		case 'S':
			stereo = !stereo;
			break;
		case 'c':
			vwintvl = atoi(argv[++i]);
			break;
		case 'b':
			backvis = !backvis;
			break;
		default:
			goto userr;
		}
	if (i >= argc)
		goto userr;
#ifdef NOSTEREO
	if (stereo)
		error(INTERNAL, "stereo not supported in this version");
#endif
					/* run rad and get views */
	runrad(argc-i, argv+i);
					/* check view */
	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 */
	if (octree != NULL) {
		displist = rgl_octlist(octree, NULL, NULL, NULL);
		startrtrace(octree);
	} else
		displist = rgl_filelist(nscenef, scene, NULL);
					/* set initial view */
	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][-s][-b][-S][-v view] rfile [VAR=value]..\n",
			argv[0]);
	quit(1);
	return 1; /* pro forma return */
}
コード例 #27
0
ファイル: glrad.c プロジェクト: germolinal/Schedules
static void
runrad(				/* run rad and load variables */
	int	ac,
	char	**av
)
{
	static char	optfile[] = TEMPLATE;
	int	nvn = 0, nvv = 0;
	FILE	*fp;
	register char	*cp;
	char	radcomm[256], buf[128], nam[32];
					/* set rad commmand */
	strcpy(radcomm, "rad -w -v 0        ");	/* look out below! */
	cp = radcomm + 19;
	if (silent) {
		strcpy(cp, "-s ");
		cp += 3;
	}
	while (ac--) {
		strcpy(cp, *av++);
		while (*cp) cp++;
		*cp++ = ' ';
	}
	strcpy(cp, "OPTFILE=");		/* create temporary options file */
	strcpy(cp+8, mktemp(optfile));
	if (system(radcomm))		/* update octree */
		error(USER, "error executing rad command");
					/* replace "-v 0" with "-n -e -s -V" */
	strcpy(radcomm+7, "-n -e -s -V");
	radcomm[18] = ' ';
	if ((fp = popen(radcomm, "r")) == NULL)
		error(SYSTEM, "cannot start rad command");
	buf[0] = '\0';			/* read variables alphabetically */
						/* get exposure */
	if ((cp = scan4var(buf, sizeof(buf), "EXPOSURE", fp)) != NULL) {
		expval = atof(cp);
		if ((*cp == '-') | (*cp == '+'))
			expval = pow(2., expval);
		expval *= 0.5;		/* compensate for local shading */
	}
						/* look for eye separation */
	if ((cp = scan4var(buf, sizeof(buf), "EYESEP", fp)) != NULL)
		eyedist = atof(cp);
						/* look for materials */
	while ((cp = scan4var(buf, sizeof(buf), "materials", fp)) != NULL) {
		nscenef += wordstring(scene+nscenef, cp);
		buf[0] = '\0';
	}
						/* look for octree */
	if ((cp = scan4var(buf, sizeof(buf), "OCTREE", fp)) != NULL)
		octree = savqstr(cp);
						/* look for scene files */
	while ((cp = scan4var(buf, sizeof(buf), "scene", fp)) != NULL) {
		nscenef += wordstring(scene+nscenef, cp);
		buf[0] = '\0';
	}
						/* load view names */
	while ((cp = scan4var(buf, sizeof(buf), "view", fp)) != NULL) {
		if (nvn >= MAXVIEW)
			error(INTERNAL, "too many views in rad file");
		vwl[nvn++].nam = *cp == '-' ? (char *)NULL :
				savqstr(atos(nam, sizeof(nam), cp));
		buf[0] = '\0';
	}
						/* load actual views */
	do
		if (isview(buf)) {
			vwl[nvv].v = (VIEW *)bmalloc(sizeof(VIEW));
			*(vwl[nvv].v) = stdview;
			sscanview(vwl[nvv].v, buf);
			if ((cp = setview(vwl[nvv++].v)) != NULL) {
				fprintf(stderr, "%s: bad view %d - %s\n",
						progname, nvv, cp);
				quit(1);
			}
		}
	while (fgets(buf, sizeof(buf), fp) != NULL);
	if (nvv != nvn)
		error(INTERNAL, "view miscount in runrad");
	pclose(fp);
						/* open options file */
	if ((fp = fopen(optfile, "r")) == NULL)
		error(SYSTEM, "cannot open options file");
						/* get relevant options */
	while (fgets(buf, sizeof(buf), fp) != NULL)
		if (!strncmp(buf, "-av ", 4))
			setcolor(ambval, atof(buf+4),
					atof(sskip2(buf+4,1)),
					atof(sskip2(buf+4,2)));
		else if (backvis && !strncmp(buf, "-bv", 3) &&
				(!buf[3] || strchr("0-FfNn \n",buf[3])!=NULL))
			backvis = 0;
	fclose(fp);
	unlink(optfile);			/* delete options file */
}
コード例 #28
0
int
main(int argc, char *argv[])
{
#define	 check(ol,al)		if (argv[i][ol] || \
				badarg(argc-i-1,argv+i+1,al)) \
				goto badopt
#define	 check_bool(olen,var)		switch (argv[i][olen]) { \
				case '\0': var = !var; break; \
				case 'y': case 'Y': case 't': case 'T': \
				case '+': case '1': var = 1; break; \
				case 'n': case 'N': case 'f': case 'F': \
				case '-': case '0': var = 0; break; \
				default: goto badopt; }
	char  *octnm = NULL;
	char  *err;
	int  rval;
	int  i;
					/* global program name */
	progname = argv[0] = fixargv0(argv[0]);
					/* set our defaults */
	shadthresh = .1;
	shadcert = .25;
	directrelay = 0;
	vspretest = 128;
	srcsizerat = 0.;
	specthresh = .3;
	specjitter = 1.;
	maxdepth = 6;
	minweight = 1e-2;
	ambacc = 0.3;
	ambres = 32;
	ambdiv = 256;
	ambssamp = 64;
					/* option city */
	for (i = 1; i < argc; i++) {
						/* expand arguments */
		while ((rval = expandarg(&argc, &argv, i)) > 0)
			;
		if (rval < 0) {
			sprintf(errmsg, "cannot expand '%s'", argv[i]);
			error(SYSTEM, errmsg);
		}
		if (argv[i] == NULL || argv[i][0] != '-')
			break;			/* break from options */
		if (!strcmp(argv[i], "-version")) {
			puts(VersionID);
			quit(0);
		}
		if (!strcmp(argv[i], "-defaults") ||
				!strcmp(argv[i], "-help")) {
			printdefaults();
			quit(0);
		}
		if (!strcmp(argv[i], "-devices")) {
			printdevices();
			quit(0);
		}
		rval = getrenderopt(argc-i, argv+i);
		if (rval >= 0) {
			i += rval;
			continue;
		}
		rval = getviewopt(&ourview, argc-i, argv+i);
		if (rval >= 0) {
			i += rval;
			continue;
		}
		switch (argv[i][1]) {
		case 'n':				/* # processes */
			check(2,"i");
			nproc = atoi(argv[++i]);
			if (nproc <= 0)
				error(USER, "bad number of processes");
			break;
		case 'v':				/* view file */
			if (argv[i][2] != 'f')
				goto badopt;
			check(3,"s");
			rval = viewfile(argv[++i], &ourview, NULL);
			if (rval < 0) {
				sprintf(errmsg,
				"cannot open view file \"%s\"",
						argv[i]);
				error(SYSTEM, errmsg);
			} else if (rval == 0) {
				sprintf(errmsg,
					"bad view file \"%s\"",
						argv[i]);
				error(USER, errmsg);
			}
			break;
		case 'b':				/* grayscale */
			check_bool(2,greyscale);
			break;
		case 'p':				/* pixel */
			switch (argv[i][2]) {
			case 's':				/* sample */
				check(3,"i");
				psample = atoi(argv[++i]);
				break;
			case 't':				/* threshold */
				check(3,"f");
				maxdiff = atof(argv[++i]);
				break;
			case 'e':				/* exposure */
				check(3,"f");
				exposure = atof(argv[++i]);
				if (argv[i][0] == '+' || argv[i][0] == '-')
					exposure = pow(2.0, exposure);
				break;
			default:
				goto badopt;
			}
			break;
		case 'w':				/* warnings */
			rval = erract[WARNING].pf != NULL;
			check_bool(2,rval);
			if (rval) erract[WARNING].pf = wputs;
			else erract[WARNING].pf = NULL;
			break;
		case 'e':				/* error file */
			check(2,"s");
			errfile = argv[++i];
			break;
		case 'o':				/* output device */
			check(2,"s");
			dvcname = argv[++i];
			break;
		case 'R':				/* render input file */
			check(2,"s");
			strcpy(rifname, argv[++i]);
			break;
		default:
			goto badopt;
		}
	}
	err = setview(&ourview);	/* set viewing parameters */
	if (err != NULL)
		error(USER, err);
						/* set up signal handling */
	sigdie(SIGINT, "Interrupt");
	sigdie(SIGTERM, "Terminate");
#if !defined(_WIN32) && !defined(_WIN64)
	sigdie(SIGHUP, "Hangup");
	sigdie(SIGPIPE, "Broken pipe");
	sigdie(SIGALRM, "Alarm clock");
#endif
					/* open error file */
	if (errfile != NULL) {
		if (freopen(errfile, "a", stderr) == NULL)
			quit(2);
		fprintf(stderr, "**************\n*** PID %5d: ",
				getpid());
		printargs(argc, argv, stderr);
		putc('\n', stderr);
		fflush(stderr);
	}
#ifdef	NICE
	nice(NICE);			/* lower priority */
#endif
					/* get octree */
	if (i == argc)
		octnm = NULL;
	else if (i == argc-1)
		octnm = argv[i];
	else
		goto badopt;
	if (octnm == NULL)
		error(USER, "missing octree argument");
					/* set up output & start process(es) */
	SET_FILE_BINARY(stdout);
	
	ray_init(octnm);		/* also calls ray_init_pmap() */
	
/* temporary shortcut, until winrview is refactored into a "device" */
#ifndef WIN_RVIEW
	rview();			/* run interactive viewer */


	devclose();			/* close output device */
#endif

	/* PMAP: free photon maps */
	ray_done_pmap();
	
#ifdef WIN_RVIEW
	return 1;
#endif
	quit(0);

badopt:
	sprintf(errmsg, "command line error at '%s'", argv[i]);
	error(USER, errmsg);
	return 1; /* pro forma return */

#undef	check
#undef	check_bool
}