| 1 |
greg |
1.1 |
/* Copyright (c) 1986 Regents of the University of California */ |
| 2 |
|
|
|
| 3 |
|
|
#ifndef lint |
| 4 |
|
|
static char SCCSid[] = "$SunId$ LBL"; |
| 5 |
|
|
#endif |
| 6 |
|
|
|
| 7 |
|
|
/* |
| 8 |
|
|
* lookamb.c - program to examine ambient components. |
| 9 |
|
|
* |
| 10 |
|
|
* 10/8/86 |
| 11 |
|
|
*/ |
| 12 |
|
|
|
| 13 |
|
|
#include <stdio.h> |
| 14 |
|
|
|
| 15 |
|
|
#include "color.h" |
| 16 |
|
|
|
| 17 |
|
|
|
| 18 |
|
|
typedef double FVECT[3]; |
| 19 |
|
|
|
| 20 |
|
|
typedef struct ambval { |
| 21 |
|
|
FVECT pos; /* position in space */ |
| 22 |
|
|
FVECT dir; /* normal direction */ |
| 23 |
|
|
int lvl; /* recursion level of parent ray */ |
| 24 |
|
|
float weight; /* weight of parent ray */ |
| 25 |
|
|
COLOR val; /* computed ambient value */ |
| 26 |
|
|
float rad; /* validity radius */ |
| 27 |
|
|
struct ambval *next; /* next in list */ |
| 28 |
|
|
} AMBVAL; /* ambient value */ |
| 29 |
|
|
|
| 30 |
|
|
int dataonly = 0; |
| 31 |
|
|
|
| 32 |
|
|
int reverse = 0; |
| 33 |
|
|
|
| 34 |
|
|
AMBVAL av; |
| 35 |
|
|
|
| 36 |
|
|
|
| 37 |
|
|
main(argc, argv) /* load ambient values from a file */ |
| 38 |
|
|
char *argv[]; |
| 39 |
|
|
{ |
| 40 |
|
|
FILE *fp; |
| 41 |
|
|
int i; |
| 42 |
|
|
|
| 43 |
|
|
for (i = 1; i < argc; i++) |
| 44 |
|
|
if (argv[i][0] == '-') |
| 45 |
|
|
switch (argv[i][1]) { |
| 46 |
|
|
case 'd': |
| 47 |
|
|
dataonly = 1; |
| 48 |
|
|
break; |
| 49 |
|
|
case 'r': |
| 50 |
|
|
reverse = 1; |
| 51 |
|
|
break; |
| 52 |
|
|
default: |
| 53 |
|
|
fprintf(stderr, "%s: unknown option '%s'\n", |
| 54 |
|
|
argv[0], argv[i]); |
| 55 |
|
|
return(1); |
| 56 |
|
|
} |
| 57 |
|
|
else |
| 58 |
|
|
break; |
| 59 |
|
|
|
| 60 |
|
|
if (i >= argc) |
| 61 |
|
|
fp = stdin; |
| 62 |
|
|
else if ((fp = fopen(argv[i], "r")) == NULL) { |
| 63 |
|
|
fprintf(stderr, "%s: file not found\n", argv[i]); |
| 64 |
|
|
return(1); |
| 65 |
|
|
} |
| 66 |
|
|
if (reverse) |
| 67 |
|
|
writamb(fp); |
| 68 |
|
|
else |
| 69 |
|
|
lookamb(fp); |
| 70 |
|
|
fclose(fp); |
| 71 |
|
|
return(0); |
| 72 |
|
|
} |
| 73 |
|
|
|
| 74 |
|
|
|
| 75 |
|
|
lookamb(fp) /* get ambient values from a file */ |
| 76 |
|
|
FILE *fp; |
| 77 |
|
|
{ |
| 78 |
|
|
while (fread(&av, sizeof(AMBVAL), 1, fp) == 1) { |
| 79 |
|
|
if (dataonly) { |
| 80 |
|
|
printf("%f\t%f\t%f\t", av.pos[0], av.pos[1], av.pos[2]); |
| 81 |
|
|
printf("%f\t%f\t%f\t", av.dir[0], av.dir[1], av.dir[2]); |
| 82 |
|
|
printf("%d\t%f\t%f\t", av.lvl, av.weight, av.rad); |
| 83 |
|
|
printf("%e\t%e\t%e\n", colval(av.val,RED), |
| 84 |
|
|
colval(av.val,GRN), |
| 85 |
|
|
colval(av.val,BLU)); |
| 86 |
|
|
} else { |
| 87 |
|
|
printf("\nPosition:\t%f\t%f\t%f\n", av.pos[0], |
| 88 |
|
|
av.pos[1], av.pos[2]); |
| 89 |
|
|
printf("Direction:\t%f\t%f\t%f\n", av.dir[0], |
| 90 |
|
|
av.dir[1], av.dir[2]); |
| 91 |
|
|
printf("Lvl,Wt,Rad:\t%d\t\t%f\t%f\n", av.lvl, |
| 92 |
|
|
av.weight, av.rad); |
| 93 |
|
|
printf("Value:\t\t%e\t%e\t%e\n", colval(av.val,RED), |
| 94 |
|
|
colval(av.val,GRN), colval(av.val,BLU)); |
| 95 |
|
|
} |
| 96 |
|
|
if (ferror(stdout)) |
| 97 |
|
|
exit(1); |
| 98 |
|
|
} |
| 99 |
|
|
} |
| 100 |
|
|
|
| 101 |
|
|
|
| 102 |
|
|
writamb(fp) /* write binary ambient values */ |
| 103 |
|
|
FILE *fp; |
| 104 |
|
|
{ |
| 105 |
|
|
for ( ; ; ) { |
| 106 |
|
|
if (!dataonly) |
| 107 |
|
|
fscanf(fp, "%*s"); |
| 108 |
|
|
if (fscanf(fp, "%lf %lf %lf", |
| 109 |
|
|
&av.pos[0], &av.pos[1], &av.pos[2]) != 3) |
| 110 |
|
|
return; |
| 111 |
|
|
if (!dataonly) |
| 112 |
|
|
fscanf(fp, "%*s"); |
| 113 |
|
|
if (fscanf(fp, "%lf %lf %lf", |
| 114 |
|
|
&av.dir[0], &av.dir[1], &av.dir[2]) != 3) |
| 115 |
|
|
return; |
| 116 |
|
|
if (!dataonly) |
| 117 |
|
|
fscanf(fp, "%*s"); |
| 118 |
|
|
if (fscanf(fp, "%d %f %f", |
| 119 |
|
|
&av.lvl, &av.weight, &av.rad) != 3) |
| 120 |
|
|
return; |
| 121 |
|
|
if (!dataonly) |
| 122 |
|
|
fscanf(fp, "%*s"); |
| 123 |
|
|
if (fscanf(fp, "%f %f %f", |
| 124 |
|
|
&av.val[RED], &av.val[GRN], &av.val[BLU]) != 3) |
| 125 |
|
|
return; |
| 126 |
|
|
fwrite(&av, sizeof(AMBVAL), 1, stdout); |
| 127 |
|
|
if (ferror(stdout)) |
| 128 |
|
|
exit(1); |
| 129 |
|
|
} |
| 130 |
|
|
} |