--- ray/src/rt/rtrace.c 1992/03/12 09:46:19 2.5 +++ ray/src/rt/rtrace.c 1992/11/06 16:48:32 2.9 @@ -1,4 +1,4 @@ -/* Copyright (c) 1986 Regents of the University of California */ +/* Copyright (c) 1992 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; @@ -30,6 +30,8 @@ static char SCCSid[] = "$SunId$ LBL"; #include "otypes.h" +#include "resolu.h" + int dimlist[MAXDIM]; /* sampling dimensions */ int ndims = 0; /* number of sampling dimensions */ int samplendx = 0; /* index for this sample */ @@ -71,7 +73,7 @@ extern OBJREC Lamb; /* a Lambertian surface */ static RAY thisray; /* for our convenience */ static int oputo(), oputd(), oputv(), oputl(), oputL(), - oputp(), oputn(), oputs(), oputw(), oputm(); + oputp(), oputn(), oputN(), oputs(), oputw(), oputm(); static int (*ray_out[10])(), (*every_out[10])(); static int castonly; @@ -88,6 +90,20 @@ int code; } +char * +formstr(f) /* return format identifier */ +int f; +{ + switch (f) { + case 'a': return("ascii"); + case 'f': return("float"); + case 'd': return("double"); + case 'c': return(COLRFMT); + } + return("unknown"); +} + + rtrace(fname) /* trace rays from file */ char *fname; { @@ -102,13 +118,25 @@ char *fname; sprintf(errmsg, "cannot open input file \"%s\"", fname); error(SYSTEM, errmsg); } +#ifdef MSDOS + if (inform != 'a') + setmode(fileno(fp), O_BINARY); +#endif /* set up output */ setoutput(outvals); switch (outform) { case 'a': putreal = puta; break; case 'f': putreal = putf; break; case 'd': putreal = putd; break; + case 'c': + if (strcmp(outvals, "v")) + error(USER, "color format with value output only"); + break; + default: + error(CONSISTENCY, "botched output format"); } + if (hresolu > 0 && vresolu > 0) + fprtresolu(hresolu, vresolu, stdout); /* process file */ while (getvec(orig, inform, fp) == 0 && getvec(direc, inform, fp) == 0) { @@ -174,9 +202,13 @@ register char *vs; case 'p': /* point */ *table++ = oputp; break; - case 'n': /* normal */ + case 'n': /* perturbed normal */ *table++ = oputn; + castonly = 0; break; + case 'N': /* unperturbed normal */ + *table++ = oputN; + break; case 's': /* surface */ *table++ = oputs; break; @@ -267,6 +299,8 @@ FILE *fp; return(-1); vec[0] = vd[0]; vec[1] = vd[1]; vec[2] = vd[2]; break; + default: + error(CONSISTENCY, "botched input format"); } return(0); } @@ -322,6 +356,15 @@ static oputv(r) /* print value */ register RAY *r; { + COLR cout; + + if (outform == 'c') { + setcolr(cout, colval(r->rcol,RED), + colval(r->rcol,GRN), + colval(r->rcol,BLU)); + fwrite((char *)cout, sizeof(cout), 1, stdout); + return; + } (*putreal)(colval(r->rcol,RED)); (*putreal)(colval(r->rcol,GRN)); (*putreal)(colval(r->rcol,BLU)); @@ -361,7 +404,7 @@ register RAY *r; static -oputn(r) /* print normal */ +oputN(r) /* print unperturbed normal */ register RAY *r; { if (r->rot < FHUGE) { @@ -373,6 +416,25 @@ register RAY *r; (*putreal)(0.0); (*putreal)(0.0); } +} + + +static +oputn(r) /* print perturbed normal */ +RAY *r; +{ + FVECT pnorm; + + if (r->rot >= FHUGE) { + (*putreal)(0.0); + (*putreal)(0.0); + (*putreal)(0.0); + return; + } + raynormal(pnorm, r); + (*putreal)(pnorm[0]); + (*putreal)(pnorm[1]); + (*putreal)(pnorm[2]); }