--- ray/src/rt/lookamb.c 1989/02/02 10:41:25 1.1 +++ ray/src/rt/lookamb.c 1992/07/13 16:17:42 2.2 @@ -1,4 +1,4 @@ -/* Copyright (c) 1986 Regents of the University of California */ +/* Copyright (c) 1991 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; @@ -14,19 +14,9 @@ static char SCCSid[] = "$SunId$ LBL"; #include "color.h" +#include "ambient.h" -typedef double FVECT[3]; -typedef struct ambval { - FVECT pos; /* position in space */ - FVECT dir; /* normal direction */ - int lvl; /* recursion level of parent ray */ - float weight; /* weight of parent ray */ - COLOR val; /* computed ambient value */ - float rad; /* validity radius */ - struct ambval *next; /* next in list */ -} AMBVAL; /* ambient value */ - int dataonly = 0; int reverse = 0; @@ -75,14 +65,18 @@ char *argv[]; lookamb(fp) /* get ambient values from a file */ FILE *fp; { - while (fread(&av, sizeof(AMBVAL), 1, fp) == 1) { + while (readambval(&av, fp)) { if (dataonly) { printf("%f\t%f\t%f\t", av.pos[0], av.pos[1], av.pos[2]); printf("%f\t%f\t%f\t", av.dir[0], av.dir[1], av.dir[2]); printf("%d\t%f\t%f\t", av.lvl, av.weight, av.rad); - printf("%e\t%e\t%e\n", colval(av.val,RED), + printf("%e\t%e\t%e\t", colval(av.val,RED), colval(av.val,GRN), colval(av.val,BLU)); + printf("%f\t%f\t%f\t", av.gpos[0], + av.gpos[1], av.gpos[2]); + printf("%f\t%f\t%f\n", av.gdir[0], + av.gdir[1], av.gdir[2]); } else { printf("\nPosition:\t%f\t%f\t%f\n", av.pos[0], av.pos[1], av.pos[2]); @@ -92,6 +86,10 @@ FILE *fp; av.weight, av.rad); printf("Value:\t\t%e\t%e\t%e\n", colval(av.val,RED), colval(av.val,GRN), colval(av.val,BLU)); + printf("Pos.Grad:\t%f\t%f\t%f\n", av.gpos[0], + av.gpos[1], av.gpos[2]); + printf("Dir.Grad:\t%f\t%f\t%f\n", av.gdir[0], + av.gdir[1], av.gdir[2]); } if (ferror(stdout)) exit(1); @@ -105,12 +103,12 @@ FILE *fp; for ( ; ; ) { if (!dataonly) fscanf(fp, "%*s"); - if (fscanf(fp, "%lf %lf %lf", + if (fscanf(fp, "%f %f %f", &av.pos[0], &av.pos[1], &av.pos[2]) != 3) return; if (!dataonly) fscanf(fp, "%*s"); - if (fscanf(fp, "%lf %lf %lf", + if (fscanf(fp, "%f %f %f", &av.dir[0], &av.dir[1], &av.dir[2]) != 3) return; if (!dataonly) @@ -123,7 +121,18 @@ FILE *fp; if (fscanf(fp, "%f %f %f", &av.val[RED], &av.val[GRN], &av.val[BLU]) != 3) return; - fwrite(&av, sizeof(AMBVAL), 1, stdout); + if (!dataonly) + fscanf(fp, "%*s"); + if (fscanf(fp, "%f %f %f", + &av.gpos[0], &av.gpos[1], &av.gpos[2]) != 3) + return; + if (!dataonly) + fscanf(fp, "%*s"); + if (fscanf(fp, "%f %f %f", + &av.gdir[0], &av.gdir[1], &av.gdir[2]) != 3) + return; + av.next = NULL; + writambval(&av, stdout); if (ferror(stdout)) exit(1); }