| 14 |
|
|
| 15 |
|
int frompicz; /* input from pictures & depth-buffers? */ |
| 16 |
|
int noutsects; /* number of output sections */ |
| 17 |
< |
int obstructions = -1; /* interior obstructions allowed? */ |
| 17 |
> |
char obstr, unobstr; /* flag pointer values */ |
| 18 |
|
|
| 19 |
|
char *progname; /* global argv[0] */ |
| 20 |
|
|
| 52 |
|
} |
| 53 |
|
|
| 54 |
|
|
| 55 |
< |
holheadline(s, bf) /* check holodeck header line */ |
| 55 |
> |
#define H_BADF 01 |
| 56 |
> |
#define H_OBST 02 |
| 57 |
> |
#define H_OBSF 04 |
| 58 |
> |
|
| 59 |
> |
holheadline(s, hf) /* check holodeck header line */ |
| 60 |
|
register char *s; |
| 61 |
< |
int *bf; |
| 61 |
> |
int *hf; |
| 62 |
|
{ |
| 63 |
|
char fmt[32]; |
| 64 |
|
|
| 65 |
|
if (formatval(fmt, s)) { |
| 66 |
< |
*bf = strcmp(fmt, HOLOFMT); |
| 66 |
> |
if (strcmp(fmt, HOLOFMT)) |
| 67 |
> |
*hf |= H_BADF; |
| 68 |
> |
else |
| 69 |
> |
*hf &= ~H_BADF; |
| 70 |
|
return; |
| 71 |
|
} |
| 72 |
|
if (!strncmp(s, "OBSTRUCTIONS=", 13)) { |
| 73 |
|
s += 13; |
| 74 |
|
while (*s == ' ') s++; |
| 75 |
|
if (*s == 't' | *s == 'T') |
| 76 |
< |
obstructions = 1; |
| 76 |
> |
*hf |= H_OBST; |
| 77 |
|
else if (*s == 'f' | *s == 'F') |
| 78 |
< |
obstructions = 0; |
| 78 |
> |
*hf |= H_OBSF; |
| 79 |
|
else |
| 80 |
|
error(WARNING, "bad OBSTRUCTIONS value in holodeck"); |
| 81 |
|
return; |
| 82 |
|
} |
| 83 |
|
} |
| 84 |
|
|
| 78 |
– |
|
| 85 |
|
int |
| 86 |
|
openholo(fname, append) /* open existing holodeck file for i/o */ |
| 87 |
|
char *fname; |
| 90 |
|
extern long ftell(); |
| 91 |
|
FILE *fp; |
| 92 |
|
int fd; |
| 93 |
< |
int badfmt = 0; |
| 93 |
> |
int hflags = 0; |
| 94 |
|
int4 nextloc; |
| 95 |
|
int n; |
| 96 |
|
/* open holodeck file */ |
| 100 |
|
error(SYSTEM, errmsg); |
| 101 |
|
} |
| 102 |
|
/* check header and magic number */ |
| 103 |
< |
if (append) |
| 104 |
< |
badfmt |= getheader(fp, holheadline, &badfmt) < 0; |
| 99 |
< |
else |
| 100 |
< |
badfmt = checkheader(fp, HOLOFMT, NULL) < 0; |
| 101 |
< |
if (badfmt || getw(fp) != HOLOMAGIC) { |
| 103 |
> |
if (getheader(fp, holheadline, &hflags) < 0 || |
| 104 |
> |
hflags&H_BADF || getw(fp) != HOLOMAGIC) { |
| 105 |
|
sprintf(errmsg, "file \"%s\" not in holodeck format", fname); |
| 106 |
|
error(USER, errmsg); |
| 107 |
|
} |
| 111 |
|
for (n = 0; nextloc > 0L; n++) { /* initialize each section */ |
| 112 |
|
lseek(fd, (long)nextloc, 0); |
| 113 |
|
read(fd, (char *)&nextloc, sizeof(nextloc)); |
| 114 |
< |
hdinit(fd, NULL); |
| 114 |
> |
hdinit(fd, NULL)->priv = hflags&H_OBST ? &obstr : |
| 115 |
> |
hflags&H_OBSF ? &unobstr : (char *)NULL; |
| 116 |
|
} |
| 117 |
|
return(n); |
| 118 |
|
} |
| 119 |
|
|
| 120 |
+ |
#undef H_BADF |
| 121 |
+ |
#undef H_OBST |
| 122 |
+ |
#undef H_OBSF |
| 123 |
|
|
| 124 |
+ |
|
| 125 |
|
addray(ro, rd, d, cv) /* add a ray to our output holodeck */ |
| 126 |
|
FVECT ro, rd; |
| 127 |
|
double d; |
| 139 |
|
d0 = hdinter(gc, rr, &d1, hp, ro, rd); |
| 140 |
|
if (d <= d0 || d1 < -0.001) |
| 141 |
|
continue; /* missed section */ |
| 142 |
< |
if (obstructions > 0 && d0 < -0.001) |
| 142 |
> |
if (hp->priv == &obstr && d0 < -0.001) |
| 143 |
|
continue; /* ray starts too late */ |
| 144 |
< |
if (!obstructions && d < 0.999*d1) |
| 144 |
> |
if (hp->priv == &unobstr && d < 0.999*d1) |
| 145 |
|
continue; /* ray ends too soon */ |
| 146 |
|
/* should we check for duplicates? */ |
| 147 |
|
rv = hdnewrays(hp, hdbindex(hp, gc), 1); |
| 172 |
|
if ((bp = hdgetbeam(hp, j)) != NULL) { |
| 173 |
|
hdbcoord(gc, hp, j); |
| 174 |
|
for (k = bp->nrm; k--; ) { |
| 175 |
< |
hdray(ro, rd, hp, gc, hdbray(bp)[k].r); |
| 176 |
< |
d = hddepth(hp, hdbray(bp)[k].d); |
| 175 |
> |
d = hdray(ro, rd, |
| 176 |
> |
hp, gc, hdbray(bp)[k].r); |
| 177 |
> |
if (hp->priv == &unobstr) |
| 178 |
> |
VSUM(ro, ro, rd, d); |
| 179 |
> |
else |
| 180 |
> |
d = 0.; |
| 181 |
> |
d = hddepth(hp, hdbray(bp)[k].d) - d; |
| 182 |
|
addray(ro, rd, d, hdbray(bp)[k].v); |
| 183 |
|
} |
| 184 |
|
hdfreebeam(hp, j); /* free the beam */ |