--- ray/src/common/image.c 2003/06/26 00:58:09 2.18 +++ ray/src/common/image.c 2006/11/19 01:14:31 2.33 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: image.c,v 2.18 2003/06/26 00:58:09 schorsch Exp $"; +static const char RCSid[] = "$Id: image.c,v 2.33 2006/11/19 01:14:31 greg Exp $"; #endif /* * image.c - routines for image generation. @@ -9,11 +9,12 @@ static const char RCSid[] = "$Id: image.c,v 2.18 2003/ #include "copyright.h" -#include "standard.h" - +#include +#include "rtio.h" +#include "rtmath.h" +#include "paths.h" #include "view.h" -#include "paths.h" #define FEQ(x,y) (fabs((x)-(y)) <= FTINY) #define VEQ(v,w) (FEQ((v)[0],(w)[0]) && FEQ((v)[1],(w)[1]) \ @@ -21,7 +22,9 @@ static const char RCSid[] = "$Id: image.c,v 2.18 2003/ VIEW stdview = STDVIEW; /* default view parameters */ +static gethfunc gethview; + char * setview(v) /* set hvec and vvec, return message on error */ register VIEW *v; @@ -32,7 +35,10 @@ register VIEW *v; if (v->vaft < -FTINY || (v->vaft > FTINY && v->vaft <= v->vfore)) return("illegal fore/aft clipping plane"); - if (normalize(v->vdir) == 0.0) /* normalize direction */ + if (v->vdist <= FTINY) + return("illegal view distance"); + v->vdist *= normalize(v->vdir); /* normalize direction */ + if (v->vdist == 0.0) return("zero view direction"); if (normalize(v->vup) == 0.0) /* normalize view up */ @@ -346,6 +352,7 @@ register char *av[]; v->vdir[0] = atof(av[1]); v->vdir[1] = atof(av[2]); v->vdir[2] = atof(av[3]); + v->vdist = 1.; return(3); case 'u': /* up */ check(3,"fff"); @@ -394,15 +401,17 @@ register char *s; int na; int nvopts = 0; - if (*s != '-') - s = sskip2(s,1); + while (isspace(*s)) + if (!*s++) + return(0); while (*s) { ac = 0; do { - av[ac++] = s; - while (*s && *s != ' ') + if (ac || *s == '-') + av[ac++] = s; + while (*s && !isspace(*s)) s++; - while (*s == ' ') + while (isspace(*s)) s++; } while (*s && ac < 4); if ((na = getviewopt(vp, ac, av)) >= 0) { @@ -423,7 +432,9 @@ FILE *fp; { fprintf(fp, " -vt%c", vp->type); fprintf(fp, " -vp %.6g %.6g %.6g", vp->vp[0], vp->vp[1], vp->vp[2]); - fprintf(fp, " -vd %.6g %.6g %.6g", vp->vdir[0], vp->vdir[1], vp->vdir[2]); + fprintf(fp, " -vd %.6g %.6g %.6g", vp->vdir[0]*vp->vdist, + vp->vdir[1]*vp->vdist, + vp->vdir[2]*vp->vdist); fprintf(fp, " -vu %.6g %.6g %.6g", vp->vup[0], vp->vup[1], vp->vup[2]); fprintf(fp, " -vh %.6g -vv %.6g", vp->horiz, vp->vert); fprintf(fp, " -vo %.6g -va %.6g", vp->vfore, vp->vaft); @@ -438,6 +449,7 @@ register VIEW *vp; static char vwstr[128]; register char *cp = vwstr; + *cp = '\0'; if (vp->type != stdview.type) { sprintf(cp, " -vt%c", vp->type); cp += strlen(cp); @@ -447,9 +459,11 @@ register VIEW *vp; vp->vp[0], vp->vp[1], vp->vp[2]); cp += strlen(cp); } - if (!VEQ(vp->vdir,stdview.vdir)) { + if (!FEQ(vp->vdist,stdview.vdist) || !VEQ(vp->vdir,stdview.vdir)) { sprintf(cp, " -vd %.6g %.6g %.6g", - vp->vdir[0], vp->vdir[1], vp->vdir[2]); + vp->vdir[0]*vp->vdist, + vp->vdir[1]*vp->vdist, + vp->vdir[2]*vp->vdist); cp += strlen(cp); } if (!VEQ(vp->vup,stdview.vup)) { @@ -489,7 +503,7 @@ int isview(s) /* is this a view string? */ char *s; { - static char *altname[]={NULL,VIEWSTR,"rpict","rview","pinterp",NULL}; + static char *altname[]={NULL,VIEWSTR,"rpict","rview","rvu","rpiece","pinterp",NULL}; extern char *progname; register char *cp; register char **an; @@ -521,12 +535,13 @@ struct myview { static int -gethview(s, v) /* get view from header */ -char *s; -register struct myview *v; +gethview( /* get view from header */ + char *s, + void *v +) { - if (isview(s) && sscanview(v->hv, s) > 0) - v->ok++; + if (isview(s) && sscanview(((struct myview*)v)->hv, s) > 0) + ((struct myview*)v)->ok++; return(0); } @@ -548,7 +563,7 @@ RESOLU *rp; mvs.hv = vp; mvs.ok = 0; - getheader(fp, (int (*)(char *, char *))&gethview, (char *)&mvs); + getheader(fp, gethview, &mvs); if (rp != NULL && !fgetsresolu(rp, fp)) mvs.ok = 0;