18 |
|
#else |
19 |
|
#include <signal.h> |
20 |
|
#endif |
21 |
+ |
#include <fcntl.h> |
22 |
|
|
23 |
|
#include "view.h" |
24 |
|
|
101 |
|
render(zfile, oldfile) /* render the scene */ |
102 |
|
char *zfile, *oldfile; |
103 |
|
{ |
104 |
+ |
extern long lseek(); |
105 |
|
COLOR *scanbar[MAXDIV+1]; /* scanline arrays of pixel values */ |
106 |
|
float *zbar[MAXDIV+1]; /* z values */ |
107 |
|
int ypos; /* current scanline */ |
108 |
|
int ystep; /* current y step size */ |
109 |
< |
FILE *zfp; |
109 |
> |
int zfd; |
110 |
|
COLOR *colptr; |
111 |
|
float *zptr; |
112 |
|
register int i; |
123 |
|
} |
124 |
|
/* open z file */ |
125 |
|
if (zfile != NULL) { |
126 |
< |
if ((zfp = fopen(zfile, "a+")) == NULL) { |
126 |
> |
if ((zfd = open(zfile, O_WRONLY|O_CREAT, 0666)) == -1) { |
127 |
|
sprintf(errmsg, "cannot open z file \"%s\"", zfile); |
128 |
|
error(SYSTEM, errmsg); |
129 |
|
} |
133 |
|
goto memerr; |
134 |
|
} |
135 |
|
} else { |
136 |
< |
zfp = NULL; |
136 |
> |
zfd = -1; |
137 |
|
for (i = 0; i <= psample; i++) |
138 |
|
zbar[i] = NULL; |
139 |
|
} |
141 |
|
fputresolu(YMAJOR|YDECR, hresolu, vresolu, stdout); |
142 |
|
/* recover file and compute first */ |
143 |
|
i = salvage(oldfile); |
144 |
< |
if (zfp != NULL && fseek(zfp, (long)i*hresolu*sizeof(float), 0) == EOF) |
144 |
> |
if (zfd != -1 && lseek(zfd, (long)i*hresolu*sizeof(float), 0) == -1) |
145 |
|
error(SYSTEM, "z file seek error in render"); |
146 |
|
ypos = vresolu-1 - i; |
147 |
|
fillscanline(scanbar[0], zbar[0], hresolu, ypos, psample); |
149 |
|
/* compute scanlines */ |
150 |
|
for (ypos -= ystep; ypos > -ystep; ypos -= ystep) { |
151 |
|
/* record progress */ |
152 |
< |
pctdone = 100.0*(vresolu-ypos-ystep)/vresolu; |
152 |
> |
pctdone = 100.0*(vresolu-1-ypos-ystep)/vresolu; |
153 |
|
/* bottom adjust? */ |
154 |
|
if (ypos < 0) { |
155 |
|
ystep += ypos; |
167 |
|
fillscanbar(scanbar, zbar, hresolu, ypos, ystep); |
168 |
|
/* write it out */ |
169 |
|
for (i = ystep; i > 0; i--) { |
170 |
< |
if (zfp != NULL && fwrite(zbar[i],sizeof(float),hresolu,zfp) != hresolu) |
170 |
> |
if (zfd != -1 && write(zfd, (char *)zbar[i], |
171 |
> |
hresolu*sizeof(float)) |
172 |
> |
< hresolu*sizeof(float)) |
173 |
|
goto writerr; |
174 |
< |
if (fwritescan(scanbar[i],hresolu,stdout) < 0) |
174 |
> |
if (fwritescan(scanbar[i], hresolu, stdout) < 0) |
175 |
|
goto writerr; |
176 |
|
} |
173 |
– |
if (zfp != NULL && fflush(zfp) == EOF) |
174 |
– |
goto writerr; |
177 |
|
if (fflush(stdout) == EOF) |
178 |
|
goto writerr; |
179 |
|
} |
180 |
|
/* clean up */ |
181 |
< |
if (zfp != NULL) { |
182 |
< |
fwrite(zbar[0], sizeof(float), hresolu, zfp); |
183 |
< |
if (fclose(zfp) == EOF) |
181 |
> |
if (zfd != -1) { |
182 |
> |
if (write(zfd, (char *)zbar[0], hresolu*sizeof(float)) |
183 |
> |
< hresolu*sizeof(float)) |
184 |
|
goto writerr; |
185 |
+ |
if (close(zfd) == -1) |
186 |
+ |
goto writerr; |
187 |
|
for (i = 0; i <= psample; i++) |
188 |
|
free((char *)zbar[i]); |
189 |
|
} |
235 |
|
COLOR vline[MAXDIV+1]; |
236 |
|
float zline[MAXDIV+1]; |
237 |
|
int b = ysize; |
234 |
– |
double z; |
238 |
|
register int i, j; |
239 |
|
|
240 |
|
for (i = 0; i < xres; i++) { |
320 |
|
{ |
321 |
|
static RAY thisray; /* our ray for this pixel */ |
322 |
|
|
323 |
< |
viewray(thisray.rorg, thisray.rdir, &ourview, |
324 |
< |
(x+pixjitter())/hresolu, (y+pixjitter())/vresolu); |
323 |
> |
if (viewray(thisray.rorg, thisray.rdir, &ourview, |
324 |
> |
(x+pixjitter())/hresolu, (y+pixjitter())/vresolu) < 0) { |
325 |
> |
setcolor(col, 0.0, 0.0, 0.0); |
326 |
> |
return(0.0); |
327 |
> |
} |
328 |
|
|
329 |
|
rayorigin(&thisray, NULL, PRIMARY, 1.0); |
330 |
|
|
332 |
|
|
333 |
|
copycolor(col, thisray.rcol); /* return color */ |
334 |
|
|
335 |
< |
return(thisray.rot); /* return distance */ |
335 |
> |
return(thisray.rt); /* return distance */ |
336 |
|
} |
337 |
|
|
338 |
|
|