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; |
94 |
< |
int4 nextloc; |
93 |
> |
int hflags = 0; |
94 |
> |
long nextloc; |
95 |
|
int n; |
96 |
|
/* open holodeck file */ |
97 |
|
if ((fp = fopen(fname, append ? "r+" : "r")) == NULL) { |
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 |
|
} |
109 |
|
nextloc = ftell(fp); /* get stdio position */ |
110 |
|
fclose(fp); /* done with stdio */ |
111 |
|
for (n = 0; nextloc > 0L; n++) { /* initialize each section */ |
112 |
< |
lseek(fd, (long)nextloc, 0); |
112 |
> |
lseek(fd, 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); |
159 |
|
int fd; |
160 |
|
register HOLO *hp; |
161 |
|
register BEAM *bp; |
162 |
+ |
register HDBEAMI *hbl; |
163 |
|
GCOORD gc[2]; |
164 |
|
FVECT ro, rd; |
165 |
|
double d; |
166 |
|
int i, j; |
167 |
|
register int k; |
168 |
< |
|
169 |
< |
openholo(hdf, 0); /* open the holodeck for reading */ |
168 |
> |
/* open the holodeck for reading */ |
169 |
> |
openholo(hdf, 0); |
170 |
|
fd = hdlist[noutsects]->fd; /* remember the file handle */ |
171 |
|
while ((hp = hdlist[noutsects]) != NULL) { /* load each section */ |
172 |
< |
for (j = nbeams(hp); j > 0; j--) /* load each beam */ |
173 |
< |
if ((bp = hdgetbeam(hp, j)) != NULL) { |
174 |
< |
hdbcoord(gc, hp, j); |
172 |
> |
hbl = (HDBEAMI *)malloc(nbeams(hp)*sizeof(HDBEAMI)); |
173 |
> |
if (hbl == NULL) |
174 |
> |
error(SYSTEM, "out of memory in addholo"); |
175 |
> |
for (j = nbeams(hp); j > 0; j--) { /* sort the beams */ |
176 |
> |
hbl[j].h = hp; |
177 |
> |
hbl[j].b = j; |
178 |
> |
} |
179 |
> |
qsort((char *)hbl, nbeams(hp), sizeof(HDBEAMI), hdfilord); |
180 |
> |
for (j = 0; j < nbeams(hp); j++) /* load each beam */ |
181 |
> |
if ((bp = hdgetbeam(hp, hbl[j].b)) != NULL) { |
182 |
> |
hdbcoord(gc, hp, hbl[j].b); |
183 |
|
for (k = bp->nrm; k--; ) { |
184 |
< |
hdray(ro, rd, hp, gc, hdbray(bp)[k].r); |
185 |
< |
d = hddepth(hp, hdbray(bp)[k].d); |
184 |
> |
d = hdray(ro, rd, |
185 |
> |
hp, gc, hdbray(bp)[k].r); |
186 |
> |
if (hp->priv == &unobstr) |
187 |
> |
VSUM(ro, ro, rd, d); |
188 |
> |
else |
189 |
> |
d = 0.; |
190 |
> |
d = hddepth(hp, hdbray(bp)[k].d) - d; |
191 |
|
addray(ro, rd, d, hdbray(bp)[k].v); |
192 |
|
} |
193 |
< |
hdfreebeam(hp, j); /* free the beam */ |
193 |
> |
hdfreebeam(hp, hbl[j].b); /* free beam */ |
194 |
|
} |
195 |
+ |
free((char *)hbl); /* free beam list */ |
196 |
|
hddone(hp); /* free the section */ |
197 |
|
} |
198 |
|
close(fd); /* close the file */ |