| 12 |
|
#include "view.h" |
| 13 |
|
#include "resolu.h" |
| 14 |
|
|
| 15 |
+ |
#ifndef BLOADSIZE |
| 16 |
+ |
#define BLOADSIZE 1024 /* number of input beams to load at a time */ |
| 17 |
+ |
#endif |
| 18 |
+ |
|
| 19 |
+ |
int checkdepth = 1; /* check depth (!-f option)? */ |
| 20 |
+ |
int checkrepeats = 0; /* check for repeats (-c option)? */ |
| 21 |
|
int frompicz; /* input from pictures & depth-buffers? */ |
| 22 |
|
int noutsects; /* number of output sections */ |
| 23 |
|
char obstr, unobstr; /* flag pointer values */ |
| 32 |
|
int i; |
| 33 |
|
|
| 34 |
|
progname = argv[0]; |
| 35 |
< |
if (argc < 4) |
| 35 |
> |
frompicz = -1; |
| 36 |
> |
for (i = 2; i < argc && argv[i][0] == '-'; i++) |
| 37 |
> |
switch (argv[i][1]) { |
| 38 |
> |
case 'u': |
| 39 |
> |
checkrepeats = 1; |
| 40 |
> |
break; |
| 41 |
> |
case 'd': |
| 42 |
> |
checkdepth = 0; |
| 43 |
> |
break; |
| 44 |
> |
case 'h': |
| 45 |
> |
frompicz = 0; |
| 46 |
> |
break; |
| 47 |
> |
case 'p': |
| 48 |
> |
frompicz = 1; |
| 49 |
> |
break; |
| 50 |
> |
default: |
| 51 |
> |
goto userr; |
| 52 |
> |
} |
| 53 |
> |
if (i >= argc || frompicz < 0) |
| 54 |
|
goto userr; |
| 55 |
< |
if (!strcmp(argv[2], "-h")) |
| 32 |
< |
frompicz = 0; |
| 33 |
< |
else if (!strcmp(argv[2], "-pz")) |
| 34 |
< |
frompicz = 1; |
| 35 |
< |
else |
| 55 |
> |
if (frompicz && (argc-i)%2) |
| 56 |
|
goto userr; |
| 37 |
– |
if (frompicz && (argc-3)%2) |
| 38 |
– |
goto userr; |
| 57 |
|
noutsects = openholo(argv[1], 1); |
| 58 |
|
if (frompicz) |
| 59 |
< |
for (i = 3; i < argc; i += 2) |
| 59 |
> |
for ( ; i < argc; i += 2) |
| 60 |
|
addpicz(argv[i], argv[i+1]); |
| 61 |
|
else |
| 62 |
< |
for (i = 3; i < argc; i++) |
| 62 |
> |
for ( ; i < argc; i++) |
| 63 |
|
addholo(argv[i]); |
| 64 |
|
quit(0); |
| 65 |
|
userr: |
| 66 |
< |
fprintf(stderr, "Usage: %s output.hdk -h inp1.hdk ..\n", progname); |
| 49 |
< |
fprintf(stderr, " Or: %s output.hdk -pz inp1.pic inp1.zbf ..\n", |
| 66 |
> |
fprintf(stderr, "Usage: %s output.hdk [-u][-d] -h inp1.hdk ..\n", |
| 67 |
|
progname); |
| 68 |
+ |
fprintf(stderr, " Or: %s output.hdk [-u][-d] -pz inp1.pic inp1.zbf ..\n", |
| 69 |
+ |
progname); |
| 70 |
|
exit(1); |
| 71 |
|
} |
| 72 |
|
|
| 146 |
|
double d; |
| 147 |
|
COLR cv; |
| 148 |
|
{ |
| 149 |
< |
int sn; |
| 149 |
> |
int sn, bi, n; |
| 150 |
|
register HOLO *hp; |
| 151 |
|
GCOORD gc[2]; |
| 152 |
|
BYTE rr[2][2]; |
| 153 |
+ |
BEAM *bp; |
| 154 |
|
double d0, d1; |
| 155 |
+ |
unsigned dc; |
| 156 |
|
register RAYVAL *rv; |
| 157 |
|
/* check each output section */ |
| 158 |
|
for (sn = noutsects; sn--; ) { |
| 160 |
|
d0 = hdinter(gc, rr, &d1, hp, ro, rd); |
| 161 |
|
if (d <= d0 || d1 < -0.001) |
| 162 |
|
continue; /* missed section */ |
| 163 |
< |
if (hp->priv == &obstr && d0 < -0.001) |
| 164 |
< |
continue; /* ray starts too late */ |
| 165 |
< |
if (hp->priv == &unobstr && d < 0.999*d1) |
| 166 |
< |
continue; /* ray ends too soon */ |
| 167 |
< |
/* should we check for duplicates? */ |
| 168 |
< |
rv = hdnewrays(hp, hdbindex(hp, gc), 1); |
| 163 |
> |
if (checkdepth) { /* check depth */ |
| 164 |
> |
if (hp->priv == &obstr && d0 < -0.001) |
| 165 |
> |
continue; /* ray starts too late */ |
| 166 |
> |
if (hp->priv == &unobstr && d < 0.999*d1) |
| 167 |
> |
continue; /* ray ends too soon */ |
| 168 |
> |
} |
| 169 |
> |
dc = hdcode(hp, d-d0); |
| 170 |
> |
bi = hdbindex(hp, gc); /* check for duplicates */ |
| 171 |
> |
if (checkrepeats && (bp = hdgetbeam(hp, bi)) != NULL) { |
| 172 |
> |
for (n = bp->nrm, rv = hdbray(bp); n--; rv++) |
| 173 |
> |
if (rv->d == dc && |
| 174 |
> |
rv->r[0][0] == rr[0][0] && |
| 175 |
> |
rv->r[0][1] == rr[0][1] && |
| 176 |
> |
rv->r[1][0] == rr[1][0] && |
| 177 |
> |
rv->r[1][1] == rr[1][1]) |
| 178 |
> |
break; |
| 179 |
> |
if (n >= 0) |
| 180 |
> |
continue; /* found a matching ray */ |
| 181 |
> |
} |
| 182 |
> |
rv = hdnewrays(hp, bi, 1); |
| 183 |
> |
rv->d = dc; |
| 184 |
|
rv->r[0][0] = rr[0][0]; rv->r[0][1] = rr[0][1]; |
| 185 |
|
rv->r[1][0] = rr[1][0]; rv->r[1][1] = rr[1][1]; |
| 186 |
|
copycolr(rv->v, cv); |
| 151 |
– |
rv->d = hdcode(hp, d-d0); |
| 187 |
|
} |
| 188 |
|
} |
| 189 |
|
|
| 191 |
|
addholo(hdf) /* add a holodeck file */ |
| 192 |
|
char *hdf; |
| 193 |
|
{ |
| 194 |
+ |
HDBEAMI hbl[BLOADSIZE]; |
| 195 |
|
int fd; |
| 196 |
|
register HOLO *hp; |
| 197 |
|
register BEAM *bp; |
| 198 |
|
GCOORD gc[2]; |
| 199 |
|
FVECT ro, rd; |
| 200 |
|
double d; |
| 201 |
< |
int i, j; |
| 201 |
> |
int i, j, n, li; |
| 202 |
|
register int k; |
| 203 |
< |
|
| 204 |
< |
openholo(hdf, 0); /* open the holodeck for reading */ |
| 203 |
> |
/* open the holodeck for reading */ |
| 204 |
> |
openholo(hdf, 0); |
| 205 |
|
fd = hdlist[noutsects]->fd; /* remember the file handle */ |
| 206 |
|
while ((hp = hdlist[noutsects]) != NULL) { /* load each section */ |
| 207 |
< |
for (j = nbeams(hp); j > 0; j--) /* load each beam */ |
| 208 |
< |
if ((bp = hdgetbeam(hp, j)) != NULL) { |
| 209 |
< |
hdbcoord(gc, hp, j); |
| 207 |
> |
for (j = 0; j < nbeams(hp); j++) { /* load each beam */ |
| 208 |
> |
if (!(li = j % BLOADSIZE)) { /* optimize order */ |
| 209 |
> |
if (j+BLOADSIZE > nbeams(hp)) |
| 210 |
> |
k = n = nbeams(hp) - j; |
| 211 |
> |
else |
| 212 |
> |
k = n = BLOADSIZE; |
| 213 |
> |
while (k--) { |
| 214 |
> |
hbl[k].h = hp; |
| 215 |
> |
hbl[k].b = j+k+1; |
| 216 |
> |
} |
| 217 |
> |
qsort((char *)hbl, n, |
| 218 |
> |
sizeof(HDBEAMI), hdfilord); |
| 219 |
> |
} |
| 220 |
> |
if ((bp = hdgetbeam(hp, hbl[li].b)) != NULL) { |
| 221 |
> |
hdbcoord(gc, hp, hbl[li].b); |
| 222 |
|
for (k = bp->nrm; k--; ) { |
| 223 |
|
d = hdray(ro, rd, |
| 224 |
|
hp, gc, hdbray(bp)[k].r); |
| 229 |
|
d = hddepth(hp, hdbray(bp)[k].d) - d; |
| 230 |
|
addray(ro, rd, d, hdbray(bp)[k].v); |
| 231 |
|
} |
| 232 |
< |
hdfreebeam(hp, j); /* free the beam */ |
| 232 |
> |
hdfreebeam(hp, hbl[li].b); /* free beam */ |
| 233 |
|
} |
| 234 |
+ |
} |
| 235 |
|
hddone(hp); /* free the section */ |
| 236 |
|
} |
| 237 |
|
close(fd); /* close the file */ |