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