12 |
|
#include "view.h" |
13 |
|
#include "resolu.h" |
14 |
|
|
15 |
+ |
int checkdepth = 1; /* check depth (!-f option)? */ |
16 |
+ |
int checkrepeats = 0; /* check for repeats (-c option)? */ |
17 |
|
int frompicz; /* input from pictures & depth-buffers? */ |
18 |
|
int noutsects; /* number of output sections */ |
19 |
|
char obstr, unobstr; /* flag pointer values */ |
28 |
|
int i; |
29 |
|
|
30 |
|
progname = argv[0]; |
31 |
< |
if (argc < 4) |
31 |
> |
frompicz = -1; |
32 |
> |
for (i = 2; i < argc && argv[i][0] == '-'; i++) |
33 |
> |
switch (argv[i][1]) { |
34 |
> |
case 'c': |
35 |
> |
checkrepeats = 1; |
36 |
> |
break; |
37 |
> |
case 'f': |
38 |
> |
checkdepth = 0; |
39 |
> |
break; |
40 |
> |
case 'h': |
41 |
> |
frompicz = 0; |
42 |
> |
break; |
43 |
> |
case 'p': |
44 |
> |
frompicz = 1; |
45 |
> |
break; |
46 |
> |
default: |
47 |
> |
goto userr; |
48 |
> |
} |
49 |
> |
if (i >= argc || frompicz < 0) |
50 |
|
goto userr; |
51 |
< |
if (!strcmp(argv[2], "-h")) |
32 |
< |
frompicz = 0; |
33 |
< |
else if (!strcmp(argv[2], "-pz")) |
34 |
< |
frompicz = 1; |
35 |
< |
else |
51 |
> |
if (frompicz && (argc-i)%2) |
52 |
|
goto userr; |
37 |
– |
if (frompicz && (argc-3)%2) |
38 |
– |
goto userr; |
53 |
|
noutsects = openholo(argv[1], 1); |
54 |
|
if (frompicz) |
55 |
< |
for (i = 3; i < argc; i += 2) |
55 |
> |
for ( ; i < argc; i += 2) |
56 |
|
addpicz(argv[i], argv[i+1]); |
57 |
|
else |
58 |
< |
for (i = 3; i < argc; i++) |
58 |
> |
for ( ; i < argc; i++) |
59 |
|
addholo(argv[i]); |
60 |
|
quit(0); |
61 |
|
userr: |
62 |
< |
fprintf(stderr, "Usage: %s output.hdk -h inp1.hdk ..\n", progname); |
49 |
< |
fprintf(stderr, " Or: %s output.hdk -pz inp1.pic inp1.zbf ..\n", |
62 |
> |
fprintf(stderr, "Usage: %s output.hdk [-c][-f] -h inp1.hdk ..\n", |
63 |
|
progname); |
64 |
+ |
fprintf(stderr, " Or: %s output.hdk [-c][-f] -pz inp1.pic inp1.zbf ..\n", |
65 |
+ |
progname); |
66 |
|
exit(1); |
67 |
|
} |
68 |
|
|
106 |
|
FILE *fp; |
107 |
|
int fd; |
108 |
|
int hflags = 0; |
109 |
< |
int4 nextloc; |
109 |
> |
long nextloc; |
110 |
|
int n; |
111 |
|
/* open holodeck file */ |
112 |
|
if ((fp = fopen(fname, append ? "r+" : "r")) == NULL) { |
124 |
|
nextloc = ftell(fp); /* get stdio position */ |
125 |
|
fclose(fp); /* done with stdio */ |
126 |
|
for (n = 0; nextloc > 0L; n++) { /* initialize each section */ |
127 |
< |
lseek(fd, (long)nextloc, 0); |
127 |
> |
lseek(fd, nextloc, 0); |
128 |
|
read(fd, (char *)&nextloc, sizeof(nextloc)); |
129 |
|
hdinit(fd, NULL)->priv = hflags&H_OBST ? &obstr : |
130 |
|
hflags&H_OBSF ? &unobstr : (char *)NULL; |
142 |
|
double d; |
143 |
|
COLR cv; |
144 |
|
{ |
145 |
< |
int sn; |
145 |
> |
int sn, bi, n; |
146 |
|
register HOLO *hp; |
147 |
|
GCOORD gc[2]; |
148 |
|
BYTE rr[2][2]; |
149 |
+ |
BEAM *bp; |
150 |
|
double d0, d1; |
151 |
+ |
unsigned dc; |
152 |
|
register RAYVAL *rv; |
153 |
|
/* check each output section */ |
154 |
|
for (sn = noutsects; sn--; ) { |
156 |
|
d0 = hdinter(gc, rr, &d1, hp, ro, rd); |
157 |
|
if (d <= d0 || d1 < -0.001) |
158 |
|
continue; /* missed section */ |
159 |
< |
if (hp->priv == &obstr && d0 < -0.001) |
160 |
< |
continue; /* ray starts too late */ |
161 |
< |
if (hp->priv == &unobstr && d < 0.999*d1) |
162 |
< |
continue; /* ray ends too soon */ |
163 |
< |
/* should we check for duplicates? */ |
164 |
< |
rv = hdnewrays(hp, hdbindex(hp, gc), 1); |
159 |
> |
if (checkdepth) { /* check depth */ |
160 |
> |
if (hp->priv == &obstr && d0 < -0.001) |
161 |
> |
continue; /* ray starts too late */ |
162 |
> |
if (hp->priv == &unobstr && d < 0.999*d1) |
163 |
> |
continue; /* ray ends too soon */ |
164 |
> |
} |
165 |
> |
dc = hdcode(hp, d-d0); |
166 |
> |
bi = hdbindex(hp, gc); /* check for duplicates */ |
167 |
> |
if (checkrepeats && (bp = hdgetbeam(hp, bi)) != NULL) { |
168 |
> |
for (n = bp->nrm, rv = hdbray(bp); n--; rv++) |
169 |
> |
if (rv->d == dc && |
170 |
> |
rv->r[0][0] == rr[0][0] && |
171 |
> |
rv->r[0][1] == rr[0][1] && |
172 |
> |
rv->r[1][0] == rr[1][0] && |
173 |
> |
rv->r[1][1] == rr[1][1]) |
174 |
> |
break; |
175 |
> |
if (n >= 0) |
176 |
> |
continue; /* found a matching ray */ |
177 |
> |
} |
178 |
> |
rv = hdnewrays(hp, bi, 1); |
179 |
> |
rv->d = dc; |
180 |
|
rv->r[0][0] = rr[0][0]; rv->r[0][1] = rr[0][1]; |
181 |
|
rv->r[1][0] = rr[1][0]; rv->r[1][1] = rr[1][1]; |
182 |
|
copycolr(rv->v, cv); |
151 |
– |
rv->d = hdcode(hp, d-d0); |
183 |
|
} |
184 |
|
} |
185 |
|
|
190 |
|
int fd; |
191 |
|
register HOLO *hp; |
192 |
|
register BEAM *bp; |
193 |
+ |
register HDBEAMI *hbl; |
194 |
|
GCOORD gc[2]; |
195 |
|
FVECT ro, rd; |
196 |
|
double d; |
197 |
|
int i, j; |
198 |
|
register int k; |
199 |
< |
|
200 |
< |
openholo(hdf, 0); /* open the holodeck for reading */ |
199 |
> |
/* open the holodeck for reading */ |
200 |
> |
openholo(hdf, 0); |
201 |
|
fd = hdlist[noutsects]->fd; /* remember the file handle */ |
202 |
|
while ((hp = hdlist[noutsects]) != NULL) { /* load each section */ |
203 |
< |
for (j = nbeams(hp); j > 0; j--) /* load each beam */ |
204 |
< |
if ((bp = hdgetbeam(hp, j)) != NULL) { |
205 |
< |
hdbcoord(gc, hp, j); |
203 |
> |
hbl = (HDBEAMI *)malloc(nbeams(hp)*sizeof(HDBEAMI)); |
204 |
> |
if (hbl == NULL) |
205 |
> |
error(SYSTEM, "out of memory in addholo"); |
206 |
> |
for (j = nbeams(hp); j > 0; j--) { /* sort the beams */ |
207 |
> |
hbl[j].h = hp; |
208 |
> |
hbl[j].b = j; |
209 |
> |
} |
210 |
> |
qsort((char *)hbl, nbeams(hp), sizeof(HDBEAMI), hdfilord); |
211 |
> |
for (j = 0; j < nbeams(hp); j++) /* load each beam */ |
212 |
> |
if ((bp = hdgetbeam(hp, hbl[j].b)) != NULL) { |
213 |
> |
hdbcoord(gc, hp, hbl[j].b); |
214 |
|
for (k = bp->nrm; k--; ) { |
215 |
|
d = hdray(ro, rd, |
216 |
|
hp, gc, hdbray(bp)[k].r); |
221 |
|
d = hddepth(hp, hdbray(bp)[k].d) - d; |
222 |
|
addray(ro, rd, d, hdbray(bp)[k].v); |
223 |
|
} |
224 |
< |
hdfreebeam(hp, j); /* free the beam */ |
224 |
> |
hdfreebeam(hp, hbl[j].b); /* free beam */ |
225 |
|
} |
226 |
+ |
free((char *)hbl); /* free beam list */ |
227 |
|
hddone(hp); /* free the section */ |
228 |
|
} |
229 |
|
close(fd); /* close the file */ |