1 |
– |
/* Copyright (c) 1997 Silicon Graphics, Inc. */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ SGI"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* Compute rays corresponding to a given picture or view. |
6 |
|
*/ |
10 |
|
|
11 |
|
#include "view.h" |
12 |
|
|
16 |
– |
#include "resolu.h" |
17 |
– |
|
13 |
|
extern int putf(), putd(), puta(); |
14 |
|
|
15 |
|
int (*putr)() = puta; |
22 |
|
|
23 |
|
int zfd = -1; |
24 |
|
|
25 |
+ |
int fromstdin = 0; |
26 |
+ |
|
27 |
|
char *progname; |
28 |
|
|
29 |
|
|
93 |
|
case 'p': /* pixel aspect ratio */ |
94 |
|
pa = atof(argv[++i]); |
95 |
|
break; |
96 |
+ |
case 'i': /* get pixels from stdin */ |
97 |
+ |
fromstdin = 1; |
98 |
+ |
break; |
99 |
|
default: |
100 |
|
goto userr; |
101 |
|
} |
128 |
|
vw.vaft > FTINY ? '+' : '-'); |
129 |
|
exit(0); |
130 |
|
} |
131 |
< |
putrays(); |
131 |
> |
if (fromstdin) |
132 |
> |
pix2rays(stdin); |
133 |
> |
else |
134 |
> |
putrays(); |
135 |
|
exit(0); |
136 |
|
userr: |
137 |
|
fprintf(stderr, |
138 |
< |
"Usage: %s [ -f{a|f|d} | -d ] { view opts .. | picture [zbuf] }\n", |
138 |
> |
"Usage: %s [ -i -f{a|f|d} | -d ] { view opts .. | picture [zbuf] }\n", |
139 |
|
progname); |
140 |
|
exit(1); |
141 |
|
} |
142 |
|
|
143 |
|
|
144 |
+ |
pix2rays(FILE *fp) |
145 |
+ |
{ |
146 |
+ |
static FVECT rorg, rdir; |
147 |
+ |
float zval; |
148 |
+ |
double px, py; |
149 |
+ |
int pp[2]; |
150 |
+ |
double d; |
151 |
+ |
register int i; |
152 |
+ |
|
153 |
+ |
while (fscanf(fp, "%lf %lf", &px, &py) == 2) { |
154 |
+ |
if (px < 0 || px >= rs.xr || |
155 |
+ |
py < 0 || py >= rs.yr) { |
156 |
+ |
fprintf(stderr, |
157 |
+ |
"%s: (x,y) pair (%.0f,%.0f) out of range\n", |
158 |
+ |
progname, px, py); |
159 |
+ |
exit(1); |
160 |
+ |
} |
161 |
+ |
if (zfd >= 0) { |
162 |
+ |
loc2pix(pp, &rs, px/rs.xr, py/rs.yr); |
163 |
+ |
if (lseek(zfd, |
164 |
+ |
(pp[1]*scanlen(&rs)+pp[0])*sizeof(float), 0) |
165 |
+ |
< 0 || |
166 |
+ |
read(zfd, &zval, sizeof(float)) |
167 |
+ |
< sizeof(float)) { |
168 |
+ |
fprintf(stderr, "%s: depth buffer read error\n", |
169 |
+ |
progname); |
170 |
+ |
exit(1); |
171 |
+ |
} |
172 |
+ |
} |
173 |
+ |
d = viewray(rorg, rdir, &vw, px/rs.xr, py/rs.yr); |
174 |
+ |
if (d < -FTINY) |
175 |
+ |
rorg[0] = rorg[1] = rorg[2] = |
176 |
+ |
rdir[0] = rdir[1] = rdir[2] = 0.; |
177 |
+ |
else if (zfd >= 0) |
178 |
+ |
for (i = 0; i < 3; i++) { |
179 |
+ |
rorg[i] += rdir[i]*zval; |
180 |
+ |
rdir[i] = -rdir[i]; |
181 |
+ |
} |
182 |
+ |
else if (d > FTINY) { |
183 |
+ |
rdir[0] *= d; rdir[1] *= d; rdir[2] *= d; |
184 |
+ |
} |
185 |
+ |
(*putr)(rorg, rdir); |
186 |
+ |
} |
187 |
+ |
if (!feof(fp)) { |
188 |
+ |
fprintf(stderr, "%s: expected px py on input\n", progname); |
189 |
+ |
exit(1); |
190 |
+ |
} |
191 |
+ |
} |
192 |
+ |
|
193 |
+ |
|
194 |
|
putrays() |
195 |
|
{ |
196 |
|
static FLOAT loc[2]; |
234 |
|
} |
235 |
|
} |
236 |
|
if (zfd >= 0) |
237 |
< |
free((char *)zbuf); |
237 |
> |
free((void *)zbuf); |
238 |
|
} |
239 |
|
|
240 |
|
|