1 |
/* Copyright (c) 1991 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 |
#include "ambient.h" |
18 |
|
19 |
|
20 |
int dataonly = 0; |
21 |
|
22 |
int reverse = 0; |
23 |
|
24 |
AMBVAL av; |
25 |
|
26 |
|
27 |
main(argc, argv) /* load ambient values from a file */ |
28 |
char *argv[]; |
29 |
{ |
30 |
FILE *fp; |
31 |
int i; |
32 |
|
33 |
for (i = 1; i < argc; i++) |
34 |
if (argv[i][0] == '-') |
35 |
switch (argv[i][1]) { |
36 |
case 'd': |
37 |
dataonly = 1; |
38 |
break; |
39 |
case 'r': |
40 |
reverse = 1; |
41 |
break; |
42 |
default: |
43 |
fprintf(stderr, "%s: unknown option '%s'\n", |
44 |
argv[0], argv[i]); |
45 |
return(1); |
46 |
} |
47 |
else |
48 |
break; |
49 |
|
50 |
if (i >= argc) |
51 |
fp = stdin; |
52 |
else if ((fp = fopen(argv[i], "r")) == NULL) { |
53 |
fprintf(stderr, "%s: file not found\n", argv[i]); |
54 |
return(1); |
55 |
} |
56 |
if (reverse) |
57 |
writamb(fp); |
58 |
else |
59 |
lookamb(fp); |
60 |
fclose(fp); |
61 |
return(0); |
62 |
} |
63 |
|
64 |
|
65 |
lookamb(fp) /* get ambient values from a file */ |
66 |
FILE *fp; |
67 |
{ |
68 |
while (readambval(&av, fp)) { |
69 |
if (dataonly) { |
70 |
printf("%f\t%f\t%f\t", av.pos[0], av.pos[1], av.pos[2]); |
71 |
printf("%f\t%f\t%f\t", av.dir[0], av.dir[1], av.dir[2]); |
72 |
printf("%d\t%f\t%f\t", av.lvl, av.weight, av.rad); |
73 |
printf("%e\t%e\t%e\t", colval(av.val,RED), |
74 |
colval(av.val,GRN), |
75 |
colval(av.val,BLU)); |
76 |
printf("%f\t%f\t%f\t", av.gpos[0], |
77 |
av.gpos[1], av.gpos[2]); |
78 |
printf("%f\t%f\t%f\n", av.gdir[0], |
79 |
av.gdir[1], av.gdir[2]); |
80 |
} else { |
81 |
printf("\nPosition:\t%f\t%f\t%f\n", av.pos[0], |
82 |
av.pos[1], av.pos[2]); |
83 |
printf("Direction:\t%f\t%f\t%f\n", av.dir[0], |
84 |
av.dir[1], av.dir[2]); |
85 |
printf("Lvl,Wt,Rad:\t%d\t\t%f\t%f\n", av.lvl, |
86 |
av.weight, av.rad); |
87 |
printf("Value:\t\t%e\t%e\t%e\n", colval(av.val,RED), |
88 |
colval(av.val,GRN), colval(av.val,BLU)); |
89 |
printf("Pos.Grad:\t%f\t%f\t%f\n", av.gpos[0], |
90 |
av.gpos[1], av.gpos[2]); |
91 |
printf("Dir.Grad:\t%f\t%f\t%f\n", av.gdir[0], |
92 |
av.gdir[1], av.gdir[2]); |
93 |
} |
94 |
if (ferror(stdout)) |
95 |
exit(1); |
96 |
} |
97 |
} |
98 |
|
99 |
|
100 |
writamb(fp) /* write binary ambient values */ |
101 |
FILE *fp; |
102 |
{ |
103 |
for ( ; ; ) { |
104 |
if (!dataonly) |
105 |
fscanf(fp, "%*s"); |
106 |
if (fscanf(fp, "%f %f %f", |
107 |
&av.pos[0], &av.pos[1], &av.pos[2]) != 3) |
108 |
return; |
109 |
if (!dataonly) |
110 |
fscanf(fp, "%*s"); |
111 |
if (fscanf(fp, "%f %f %f", |
112 |
&av.dir[0], &av.dir[1], &av.dir[2]) != 3) |
113 |
return; |
114 |
if (!dataonly) |
115 |
fscanf(fp, "%*s"); |
116 |
if (fscanf(fp, "%d %f %f", |
117 |
&av.lvl, &av.weight, &av.rad) != 3) |
118 |
return; |
119 |
if (!dataonly) |
120 |
fscanf(fp, "%*s"); |
121 |
if (fscanf(fp, "%f %f %f", |
122 |
&av.val[RED], &av.val[GRN], &av.val[BLU]) != 3) |
123 |
return; |
124 |
if (!dataonly) |
125 |
fscanf(fp, "%*s"); |
126 |
if (fscanf(fp, "%f %f %f", |
127 |
&av.gpos[0], &av.gpos[1], &av.gpos[2]) != 3) |
128 |
return; |
129 |
if (!dataonly) |
130 |
fscanf(fp, "%*s"); |
131 |
if (fscanf(fp, "%f %f %f", |
132 |
&av.gdir[0], &av.gdir[1], &av.gdir[2]) != 3) |
133 |
return; |
134 |
av.next = NULL; |
135 |
writambval(&av, stdout); |
136 |
if (ferror(stdout)) |
137 |
exit(1); |
138 |
} |
139 |
} |