ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/rhdisp2.c
(Generate patch)

Comparing ray/src/hd/rhdisp2.c (file contents):
Revision 3.16 by gregl, Tue Dec 16 11:57:32 1997 UTC vs.
Revision 3.37 by schorsch, Thu Jan 1 11:21:55 2004 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1997 Silicon Graphics, Inc. */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ SGI";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   * Holodeck beam tracking for display process
6   */
# Line 12 | Line 9 | static char SCCSid[] = "$SunId$ SGI";
9   #include "rhdisp.h"
10   #include "rhdriver.h"
11  
12 < #ifndef MAXDIST
13 < #define MAXDIST         42      /* maximum distance outside section */
12 > #ifndef MEYERNG
13 > #define MEYERNG         0.2     /* target mean eye range (rel. to grid) */
14   #endif
15  
19 extern GCOORD   *getviewcells();
20
21 static VIEW     dvw;            /* current view corresponding to beam list */
22
23 typedef struct {
24        int     hd;             /* holodeck section number (-1 if inactive) */
25        int     i[3];           /* voxel index (may be outside section) */
26 } VOXL;                 /* a voxel */
27
28 static VOXL voxel[8] = {        /* current voxel list */
29        {-1}, {-1}, {-1}, {-1},
30        {-1}, {-1}, {-1}, {-1}
31 };
32
16   #define CBEAMBLK        1024    /* cbeam allocation block size */
17  
18 < static struct beamcomp {
36 <        short   wants;          /* flags telling which voxels want us */
37 <        short   hd;             /* holodeck section number */
38 <        int     bi;             /* beam index */
39 < } *cbeam = NULL;        /* current beam list */
40 <
18 > static PACKHEAD *cbeam = NULL;  /* current beam list */
19   static int      ncbeams = 0;    /* number of sorted beams in cbeam */
20   static int      xcbeams = 0;    /* extra (unregistered) beams past ncbeams */
21   static int      maxcbeam = 0;   /* size of cbeam array */
22  
23 < struct cellact {
46 <        short   vi;             /* voxel index */
47 <        short   add;            /* zero means delete */
48 <        short   rev;            /* reverse ray direction? */
49 < };              /* action for cell */
23 > VIEWPOINT       cureye;         /* current eye position */
24  
25 < struct beamact {
26 <        struct cellact  ca;     /* cell action */
27 <        GCOORD  gc;             /* grid coordinate */
28 < };              /* beam origin and action */
25 > static int newcbeam(void);
26 > static int cbeamcmp(const void *cb1, const void *cb2);
27 > static int cbeamcmp2(const void *cb1, const void *cb2);
28 > static int findcbeam(int hd, int bi);
29 > static int getcbeam(int hd, int bi);
30 > static void cbeamsort(int adopt);
31  
32  
33 < int
34 < newcbeam()              /* allocate new entry at end of cbeam array */
33 > static int
34 > newcbeam(void)          /* allocate new entry at end of cbeam array */
35   {
36          int     i;
37  
38          if ((i = ncbeams + xcbeams++) >= maxcbeam) {    /* grow array */
39                  maxcbeam += CBEAMBLK;
40                  if (cbeam == NULL)
41 <                        cbeam = (struct beamcomp *)malloc(
42 <                                        maxcbeam*sizeof(struct beamcomp) );
41 >                        cbeam = (PACKHEAD *)malloc(
42 >                                        maxcbeam*sizeof(PACKHEAD) );
43                  else
44 <                        cbeam = (struct beamcomp *)realloc( (char *)cbeam,
45 <                                        maxcbeam*sizeof(struct beamcomp) );
44 >                        cbeam = (PACKHEAD *)realloc((void *)cbeam,
45 >                                        maxcbeam*sizeof(PACKHEAD) );
46                  if (cbeam == NULL)
47                          error(SYSTEM, "out of memory in newcbeam");
48          }
# Line 74 | Line 50 | newcbeam()             /* allocate new entry at end of cbeam arra
50   }
51  
52  
53 < int
54 < cbeamcmp(cb1, cb2)      /* compare two cbeam entries for sort: keep orphans */
55 < register struct beamcomp        *cb1, *cb2;
53 > static int
54 > cbeamcmp(       /* compare two cbeam entries for sort: keep orphans */
55 >        const void      *cb1,
56 >        const void      *cb2
57 > )
58   {
59          register int    c;
60  
61 <        if ((c = cb1->bi - cb2->bi))    /* sort on beam index first */
61 >        if ((c = ((PACKHEAD*)cb1)->bi - ((PACKHEAD*)cb2)->bi))  /* sort on beam index first */
62                  return(c);
63 <        return(cb1->hd - cb2->hd);      /* use hd to resolve matches */
63 >        return(((PACKHEAD*)cb1)->hd - ((PACKHEAD*)cb2)->hd);    /* use hd to resolve matches */
64   }
65  
66  
67 < int
68 < cbeamcmp2(cb1, cb2)     /* compare two cbeam entries for sort: no orphans */
69 < register struct beamcomp        *cb1, *cb2;
67 > static int
68 > cbeamcmp2(      /* compare two cbeam entries for sort: no orphans */
69 >        const void      *cb1,
70 >        const void      *cb2
71 > )
72   {
73          register int    c;
74  
75 <        if (!cb1->wants)                /* put orphans at the end, unsorted */
76 <                return(cb2->wants);
77 <        if (!cb2->wants)
75 >        if (!((PACKHEAD*)cb1)->nr)                      /* put orphans at the end, unsorted */
76 >                return(((PACKHEAD*)cb2)->nr);
77 >        if (!((PACKHEAD*)cb2)->nr)
78                  return(-1);
79 <        if ((c = cb1->bi - cb2->bi))    /* sort on beam index first */
79 >        if ((c = ((PACKHEAD*)cb1)->bi - ((PACKHEAD*)cb2)->bi))  /* sort on beam index first */
80                  return(c);
81 <        return(cb1->hd - cb2->hd);      /* use hd to resolve matches */
81 >        return(((PACKHEAD*)cb1)->hd - ((PACKHEAD*)cb2)->hd);    /* use hd to resolve matches */
82   }
83  
84  
85 < int
86 < findcbeam(hd, bi)       /* find the specified beam in our sorted list */
87 < int     hd, bi;
85 > static int
86 > findcbeam(      /* find the specified beam in our sorted list */
87 >        int     hd,
88 >        int     bi
89 > )
90   {
91 <        struct beamcomp cb;
92 <        register struct beamcomp        *p;
91 >        PACKHEAD        cb;
92 >        register PACKHEAD       *p;
93  
94          if (ncbeams <= 0)
95                  return(-1);
96 <        cb.wants = 0; cb.hd = hd; cb.bi = bi;
97 <        p = (struct beamcomp *)bsearch((char *)&cb, (char *)cbeam, ncbeams,
98 <                        sizeof(struct beamcomp), cbeamcmp);
96 >        cb.hd = hd; cb.bi = bi; cb.nr = cb.nc = 0;
97 >        p = (PACKHEAD *)bsearch((char *)&cb, (char *)cbeam, ncbeams,
98 >                        sizeof(PACKHEAD), cbeamcmp);
99          if (p == NULL)
100                  return(-1);
101          return(p - cbeam);
102   }
103  
104  
105 < int
106 < getcbeam(hd, bi)        /* get the specified beam, allocating as necessary */
107 < register int    hd;
108 < int     bi;
105 > static int
106 > getcbeam(       /* get the specified beam, allocating as necessary */
107 >        register int    hd,
108 >        int     bi
109 > )
110   {
111          register int    n;
112                                  /* first, look in sorted list */
# Line 134 | Line 117 | int    bi;
117                  if (cbeam[n].bi == bi && cbeam[n].hd == hd)
118                          return(n);
119                                  /* check legality */
120 <        if (hd < 0 | hd >= HDMAX || hdlist[hd] == NULL)
120 >        if ((hd < 0) | (hd >= HDMAX) || hdlist[hd] == NULL)
121                  error(INTERNAL, "illegal holodeck number in getcbeam");
122 <        if (bi < 1 | bi > nbeams(hdlist[hd]))
122 >        if ((bi < 1) | (bi > nbeams(hdlist[hd])))
123                  error(INTERNAL, "illegal beam index in getcbeam");
124          n = newcbeam();         /* allocate and assign */
125 <        cbeam[n].wants = 0; cbeam[n].hd = hd; cbeam[n].bi = bi;
125 >        cbeam[n].hd = hd; cbeam[n].bi = bi; cbeam[n].nr = cbeam[n].nc = 0;
126          return(n);
127   }
128  
129  
130 < cbeamsort(adopt)        /* sort our beam list, possibly turning out orphans */
131 < int     adopt;
130 > static void
131 > cbeamsort(      /* sort our beam list, possibly turning out orphans */
132 >        int     adopt
133 > )
134   {
135          register int    i;
136  
137          if (!(ncbeams += xcbeams))
138                  return;
139          xcbeams = 0;
140 <        qsort((char *)cbeam, ncbeams, sizeof(struct beamcomp),
140 >        qsort((char *)cbeam, ncbeams, sizeof(PACKHEAD),
141                          adopt ? cbeamcmp : cbeamcmp2);
142          if (adopt)
143                  return;
144          for (i = ncbeams; i--; )        /* identify orphans */
145 <                if (cbeam[i].wants)
145 >                if (cbeam[i].nr)
146                          break;
147          xcbeams = ncbeams - ++i;        /* put orphans after ncbeams */
148          ncbeams = i;
149   }
150  
151  
152 < cbeamadj(v, hr, vr)             /* adjust our beam list */
153 < VIEW    *v;
154 < int     hr, vr;
152 > extern void
153 > beam_init(              /* clear beam list for new view(s) */
154 >        int     fresh
155 > )
156   {
171        PACKHEAD        *pa, *pa2;
172        register PACKHEAD       *pp;
173        int     n, n2;
174        FVECT   gp;
175        int     igp[3], vcflgs;
157          register int    i;
177                                        /* figure out center voxel(s) */
178        n = -1; vcflgs = 0;
179        for (i = 0; i < 8 && voxel[i].hd >= 0; i++) {
180                if (voxel[i].hd != n) {
181                        hdgrid(gp, hdlist[n=voxel[i].hd], v->vp);
182                        igp[0] = gp[0]; igp[1] = gp[1]; igp[2] = gp[2];
183                }
184                if (voxel[i].i[0] == igp[0] && voxel[i].i[1] == igp[1] &&
185                                voxel[i].i[2] == igp[2])
186                        vcflgs |= 1<<i;
187        }
188                                        /* get additions */
189        pa2 = (PACKHEAD *)malloc(xcbeams*sizeof(PACKHEAD));
190        if (xcbeams && pa2 == NULL)
191                goto memerr;
192        pa = pa2 + xcbeams; n2 = 0;
193        for (i = xcbeams; i--; ) {
194                if (cbeam[ncbeams+i].wants & vcflgs)
195                        pp = --pa;              /* priority list */
196                else
197                        pp = pa2 + n2++;        /* secondary list */
198                pp->hd = cbeam[ncbeams+i].hd;
199                pp->bi = cbeam[ncbeams+i].bi;
200                pp->nr = npixels(v, hr, vr, hdlist[pp->hd], pp->bi) + 1;
201                pp->nc = 0;
202        }
203        n = xcbeams - n2;
204                                        /* now sort list for deletions */
205        cbeamsort(0);
206        pa2 = (PACKHEAD *)realloc((char *)pa2, (n+n2+xcbeams)*sizeof(PACKHEAD));
207        if (n+n2+xcbeams && pa2 == NULL)
208                goto memerr;
209        pa = pa2 + n2;
210        for (i = xcbeams; i--; ) {
211                pp = pa + n++;
212                pp->hd = cbeam[ncbeams+i].hd;
213                pp->bi = cbeam[ncbeams+i].bi;
214                pp->nr = 0;
215                pp->nc = 0;
216        }
217        if (n)                          /* adjust the set */
218                serv_request(DR_ADJSET, n*sizeof(PACKHEAD), (char *)pa);
219        if (n2)                         /* make secondary additions */
220                serv_request(DR_ADDSET, n2*sizeof(PACKHEAD), (char *)pa2);
221        xcbeams = 0;                    /* clean up */
222        free((char *)pa2);
223        return;
224 memerr:
225        error(SYSTEM, "out of memory in cbeamadj");
226 }
158  
159 <
160 < cbeamop(op, bl, n, v, hr, vr)   /* update beams on server list */
161 < int     op;
162 < register struct beamcomp        *bl;
163 < int     n;
164 < VIEW    *v;
234 < int     hr, vr;
235 < {
236 <        register PACKHEAD       *pa;
237 <        register int    i;
238 <
239 <        if (n <= 0)
240 <                return;
241 <        pa = (PACKHEAD *)malloc(n*sizeof(PACKHEAD));
242 <        if (pa == NULL)
243 <                error(SYSTEM, "out of memory in cbeamadd");
244 <        for (i = 0; i < n; i++) {
245 <                pa[i].hd = bl[i].hd;
246 <                pa[i].bi = bl[i].bi;
247 <                pa[i].nr = v==NULL ? 0 :
248 <                                npixels(v, hr, vr, hdlist[bl[i].hd], bl[i].bi);
249 <                pa[i].nc = 0;
250 <        }
251 <        serv_request(op, n*sizeof(PACKHEAD), (char *)pa);
252 <        free((char *)pa);
159 >        if (fresh)                      /* discard old beams? */
160 >                ncbeams = xcbeams = 0;
161 >        else                            /* else clear sample requests */
162 >                for (i = ncbeams+xcbeams; i--; )
163 >                        cbeam[i].nr = 0;
164 >        cureye.rng = 0.;
165   }
166  
167  
168 < int
169 < set_voxels(vl, n)       /* set new voxel array */
170 < VOXL    vl[8];
171 < int     n;
168 > extern int16 *
169 > beam_view(              /* add beam view (if advisable) */
170 >        VIEW    *vn,
171 >        int     hr,
172 >        int     vr
173 > )
174   {
175 <        short   wmap[256];
176 <        int     vmap[8];
177 <        int     comn = 0;
178 <        int     no;
179 <        register int    i, j;
180 <                                        /* find common voxels */
181 <        for (j = 0; j < 8 && voxel[j].hd >= 0; j++) {
182 <                vmap[j] = -1;
183 <                for (i = n; i--; )
184 <                        if (!bcmp((char *)(vl+i), (char *)(voxel+j),
271 <                                        sizeof(VOXL))) {
272 <                                vmap[j] = i;
273 <                                comn |= 1<<i;
274 <                                break;
275 <                        }
175 >        int16   *slist;
176 >        BEAMLIST        blist;
177 >        double  eravg, d;
178 >        register HOLO   *hp;
179 >        register int    i, n;
180 >                                        /* compute beams for view */
181 >        slist = viewbeams(vn, hr, vr, &blist);
182 >        if (*slist < 0) {
183 >                error(COMMAND, "no sections visible from this view");
184 >                return(NULL);
185          }
186 <        no = comn ? j : 0;              /* compute flag mapping */
187 <        for (i = 256; i--; ) {
188 <                wmap[i] = 0;
189 <                for (j = no; j--; )
190 <                        if (vmap[j] >= 0 && i & 1<<j)
191 <                                wmap[i] |= 1<<vmap[j];
186 >                                        /* sort current beam list */
187 >        cbeamsort(1);
188 >                                        /* add new beams to list */
189 >        for (i = blist.nb; i--; ) {
190 >                n = getcbeam(blist.bl[i].hd, blist.bl[i].bi);
191 >                if (blist.bl[i].nr > cbeam[n].nr)
192 >                        cbeam[n].nr = blist.bl[i].nr;
193          }
194 <                                        /* fix cbeam flags */
195 <        for (i = ncbeams; i--; )
196 <                cbeam[i].wants = wmap[cbeam[i].wants];
197 <                                        /* update our voxel list */
198 <        bcopy((char *)vl, (char *)voxel, n*sizeof(VOXL));
199 <        for (j = n; j < 8; j++)
200 <                voxel[j].hd = -1;
201 <        return(comn);                   /* return bit array of common voxels */
202 < }
203 <
294 <
295 < int
296 < get_voxels(vl, vp)      /* find voxels corresponding to view point */
297 < VOXL    vl[8];
298 < FVECT   vp;
299 < {
300 <        static int      lastn = 0, lastd = -1;
301 <        int     n = 0;
302 <        FVECT   gp;
303 <        double  d;
304 <        int     dist, bestd = 0x7fff;
305 <        VOXL    vox;
306 <        register int    i, j, k;
307 <                                        /* find closest voxels */
308 <        for (i = 0; n < 8 && hdlist[i]; i++) {
309 <                hdgrid(gp, hdlist[i], vp);
310 <                for (j = 0; n < 8 && j < 8; j++) {
311 <                        dist = 0;
312 <                        for (k = 0; k < 3; k++) {
313 <                                d = gp[k] - .5 + (j>>k & 1);
314 <                                if (d < 0.)
315 <                                        dist += -(vox.i[k] = (int)d - 1);
316 <                                else if ((vox.i[k] = d) >= hdlist[i]->grid[k])
317 <                                        dist += vox.i[k] -
318 <                                                        hdlist[i]->grid[k] + 1;
319 <                        }
320 <                        if (dist > bestd)       /* others were closer */
321 <                                continue;
322 <                        if (dist < bestd) {     /* start closer list */
323 <                                n = 0;
324 <                                bestd = dist;
325 <                        }
326 <                        vox.hd = i;             /* add this voxel */
327 <                        copystruct(&vl[n], &vox);
328 <                        n++;
329 <                }
194 >        free((void *)blist.bl);         /* free list */
195 >        if (MEYERNG <= FTINY)
196 >                return(slist);
197 >                                        /* compute average eye range */
198 >        eravg = 0.;
199 >        for (n = 0; slist[n] >= 0; n++) {
200 >                hp = hdlist[slist[n]];
201 >                eravg +=        MEYERNG/3. / VLEN(hp->wg[0]) +
202 >                                MEYERNG/3. / VLEN(hp->wg[1]) +
203 >                                MEYERNG/3. / VLEN(hp->wg[2]) ;
204          }
205 <                                        /* check for really stupid move */
206 <        if (bestd > MAXDIST) {
207 <                error(COMMAND, "move past outer limits");
208 <                return(0);
205 >        eravg /= (double)n;
206 >                                        /* add to current eye position */
207 >        if (cureye.rng <= FTINY) {
208 >                VCOPY(cureye.vpt, vn->vp);
209 >                cureye.rng = eravg;
210 >        } else if ((d = sqrt(dist2(vn->vp,cureye.vpt))) + eravg > cureye.rng) {
211 >                for (i = 3; i--; )
212 >                        cureye.vpt[i] = 0.5*(cureye.vpt[i] + vn->vp[i]);
213 >                cureye.rng = 0.5*(cureye.rng + eravg + d);
214          }
215 <                                        /* warn of dangerous moves */
337 <        if (n < lastn && bestd >= lastd)
338 <                error(WARNING, "moving outside holodeck section");
339 <        else if (n > lastn && bestd <= lastd)
340 <                error(WARNING, "moving inside holodeck section");
341 <        lastd = bestd;
342 <        return(lastn = n);
215 >        return(slist);
216   }
217  
218  
219 < int
220 < dobeam(gcp, bp)         /* express interest or disintrest in a beam */
221 < GCOORD  *gcp;
222 < register struct beamact *bp;
219 > extern int
220 > beam_sync(                      /* update beam list on server */
221 >        int     all
222 > )
223   {
224 <        GCOORD  gc[2];
225 <        int     bi, i;
226 <                                        /* compute beam index */
227 <        if (bp->ca.rev) {
228 <                copystruct(gc, &bp->gc);
229 <                copystruct(gc+1, gcp);
224 >                                        /* set new eye position */
225 >        serv_request(DR_VIEWPOINT, sizeof(VIEWPOINT), (char *)&cureye);
226 >                                        /* sort list (put orphans at end) */
227 >        cbeamsort(all < 0);
228 >                                        /* send beam request */
229 >        if (all) {
230 >                if (ncbeams > 0)
231 >                        serv_request(DR_NEWSET,
232 >                                        ncbeams*sizeof(PACKHEAD), (char *)cbeam);
233          } else {
234 <                copystruct(gc, gcp);
235 <                copystruct(gc+1, &bp->gc);
234 >                if (ncbeams+xcbeams > 0)
235 >                        serv_request(DR_ADJSET,
236 >                                (ncbeams+xcbeams)*sizeof(PACKHEAD), (char *)cbeam);
237          }
238 <        if ((bi = hdbindex(hdlist[voxel[bp->ca.vi].hd], gc)) <= 0)
362 <                error(CONSISTENCY, "bad grid coordinate in dobeam");
363 <        if (bp->ca.add) {               /* add it in */
364 <                i = getcbeam(voxel[bp->ca.vi].hd, bi);
365 <                cbeam[i].wants |= 1<<bp->ca.vi; /* say we want it */
366 <                return(i == ncbeams+xcbeams-1); /* return 1 if totally new */
367 <        }
368 <                                        /* else delete it */
369 <        i = findcbeam(voxel[bp->ca.vi].hd, bi);
370 <        if (i >= 0 && cbeam[i].wants & 1<<bp->ca.vi) {
371 <                cbeam[i].wants &= ~(1<<bp->ca.vi);      /* we don't want it */
372 <                return(1);                      /* indicate change */
373 <        }
374 <        return(0);
375 < }
376 <
377 <
378 <
379 < int
380 < docell(gcp, cap)        /* find beams corresponding to cell and voxel */
381 < GCOORD  *gcp;
382 < register struct cellact *cap;
383 < {
384 <        register HOLO   *hp = hdlist[voxel[cap->vi].hd];
385 <        FVECT   org, dir[4];
386 <        FVECT   vgp, cgp, vc;
387 <        FVECT   v1, v2;
388 <        struct beamact  bo;
389 <        int     axmax, j;
390 <        double  d, avmax;
391 <        register int    i;
392 <                                /* compute cell center */
393 <        cgp[gcp->w>>1] = gcp->w&1 ? hp->grid[gcp->w>>1] : 0 ;
394 <        cgp[((gcp->w>>1)+1)%3] = gcp->i[0] + .5;
395 <        cgp[((gcp->w>>1)+2)%3] = gcp->i[1] + .5;
396 <        hdworld(org, hp, cgp);
397 <                                /* compute direction to voxel center */
398 <        for (i = 3; i--; )
399 <                vgp[i] = voxel[cap->vi].i[i] + .5;
400 <        hdworld(vc, hp, vgp);
401 <        for (i = 3; i--; )
402 <                vc[i] -= org[i];
403 <                                /* compute maximum area axis */
404 <        axmax = -1; avmax = 0;
405 <        for (i = 3; i--; ) {
406 <                d = vgp[i] - cgp[i];
407 <                if (d < 0.) d = -d;
408 <                if (d > avmax) {
409 <                        avmax = d;
410 <                        axmax = i;
411 <                }
412 <        }
413 < #ifdef DEBUG
414 <        if (axmax < 0.)
415 <                error(CONSISTENCY, "botched axis computation in docell");
416 < #endif
417 <                                /* compute offset vectors */
418 <        d = 0.5/hp->grid[j=(axmax+1)%3];
419 <        for (i = 3; i--; )
420 <                v1[i] = hp->xv[j][i] * d;
421 <        d = 0.5/hp->grid[j=(axmax+2)%3];
422 <        if (DOT(hp->wn[axmax], vc) < 0.)
423 <                d = -d; /* reverse vertex ordering */
424 <        for (i = 3; i--; )
425 <                v2[i] = hp->xv[j][i] * d;
426 <                                /* compute voxel pyramid */
427 <        for (i = 3; i--; ) {
428 <                dir[0][i] = vc[i] - v1[i] - v2[i];
429 <                dir[1][i] = vc[i] + v1[i] - v2[i];
430 <                dir[2][i] = vc[i] + v1[i] + v2[i];
431 <                dir[3][i] = vc[i] - v1[i] + v2[i];
432 <        }
433 <                                /* visit beams for opposite cells */
434 <        copystruct(&bo.ca, cap);
435 <        copystruct(&bo.gc, gcp);
436 <        return(visit_cells(org, dir, hp, dobeam, &bo));
437 < }
438 <
439 <
440 < int
441 < doview(cap, vp)                 /* visit cells for a given view */
442 < struct cellact  *cap;
443 < VIEW    *vp;
444 < {
445 <        int     orient;
446 <        FVECT   org, dir[4];
447 <                                        /* compute view pyramid */
448 <        orient = viewpyramid(org, dir, hdlist[voxel[cap->vi].hd], vp);
449 <        if (!orient)
450 <                error(INTERNAL, "unusable view in doview");
451 <        cap->rev = orient < 0;
452 <                                        /* visit cells within pyramid */
453 <        return(visit_cells(org, dir, hdlist[voxel[cap->vi].hd], docell, cap));
454 < }
455 <
456 <
457 < mvview(voxi, vold, vnew)        /* move view for a voxel */
458 < int     voxi;
459 < VIEW    *vold, *vnew;
460 < {
461 <        int     netchange = 0;
462 <        struct cellact  oca, nca;
463 <        int     ocnt, ncnt;
464 <        int     c;
465 <        GCOORD  *ogcl, *ngcl;
466 <        register GCOORD *ogcp, *ngcp;
467 <                                /* get old and new cell lists */
468 <        ogcp = ogcl = getviewcells(&ocnt, hdlist[voxel[voxi].hd], vold);
469 <        ngcp = ngcl = getviewcells(&ncnt, hdlist[voxel[voxi].hd], vnew);
470 <                                /* set up actions */
471 <        oca.vi = nca.vi = voxi;
472 <        oca.add = 0; nca.add = 1;
473 <        if ((oca.rev = ocnt < 0))
474 <                ocnt = -ocnt;
475 <        if ((nca.rev = ncnt < 0))
476 <                ncnt = -ncnt;
477 <        if (nca.rev == oca.rev)         /* add and delete cells in order */
478 <                while (ocnt > 0 & ncnt > 0)
479 <                        if ((c = cellcmp(ogcp, ngcp)) > 0) {    /* new cell */
480 <                                netchange += docell(ngcp++, &nca);
481 <                                ncnt--;
482 <                        } else if (c < 0) {                     /* old cell */
483 <                                netchange -= docell(ogcp++, &oca);
484 <                                ocnt--;
485 <                        } else {                                /* same cell */
486 <                                ogcp++; ocnt--;
487 <                                ngcp++; ncnt--;
488 <                        }
489 <                                /* take care of list tails */
490 <        for ( ; ncnt > 0; ncnt--)
491 <                netchange += docell(ngcp++, &nca);
492 <        for ( ; ocnt > 0; ocnt--)
493 <                netchange -= docell(ogcp++, &oca);
494 <                                /* clean up */
495 <        if (ogcl != NULL) free((char *)ogcl);
496 <        if (ngcl != NULL) free((char *)ngcl);
497 <        return(netchange);
498 < }
499 <
500 <
501 < int
502 < beam_sync()             /* synchronize beams on server */
503 < {
504 <        cbeamop(DR_NEWSET, cbeam, ncbeams, &odev.v, odev.hres, odev.vres);
238 >        xcbeams = 0;                    /* truncate our list */
239          return(ncbeams);
240   }
241  
242  
243 < beam_view(vn)                   /* change beam view (if advisable) */
244 < VIEW    *vn;
243 > extern void
244 > gridlines(                      /* run through holodeck section grid lines */
245 >        void    (*f)(FVECT wp[2])
246 > )
247   {
248 <        struct cellact  ca;
249 <        VOXL    vlnew[8];
250 <        int     n, comn;
251 <
252 <        if (vn == NULL || !vn->type) {  /* clear our beam list */
253 <                set_voxels(vlnew, 0);
254 <                cbeamop(DR_DELSET, cbeam, ncbeams, NULL, 0, 0);
255 <                ncbeams = 0;
256 <                dvw.type = 0;
257 <                return(1);
258 <        }
259 <                                        /* find our new voxels */
260 <        n = get_voxels(vlnew, vn->vp);
261 <        if (dvw.type && !n) {
262 <                copystruct(vn, &dvw);           /* cancel move */
263 <                return(0);
264 <        }
265 <                                        /* set the new voxels */
266 <        comn = set_voxels(vlnew, n);
267 <        if (!dvw.type)
268 <                comn = 0;
269 <        ca.add = 1;                     /* update our beam list */
270 <        for (ca.vi = n; ca.vi--; )
271 <                if (comn & 1<<ca.vi)    /* change which cells we see */
272 <                        mvview(ca.vi, &dvw, vn);
273 <                else                    /* else add all new cells */
274 <                        doview(&ca, vn);
275 < #if 1
276 <        cbeamadj(vn, odev.hres, odev.vres);
277 < #else
278 <                                        /* inform server of new beams */
279 <        cbeamop(DR_ADDSET, cbeam+ncbeams, xcbeams, vn, odev.hres, odev.vres);
280 <                                        /* sort list to put orphans at end */
281 <        cbeamsort(0);
282 <                                        /* tell server to delete orphans */
283 <        cbeamop(DR_DELSET, cbeam+ncbeams, xcbeams, NULL, 0, 0);
284 <        xcbeams = 0;                    /* truncate our list */
285 < #endif
286 <        copystruct(&dvw, vn);           /* record new view */
287 <        return(1);
248 >        register int    hd, w, i;
249 >        int     g0, g1;
250 >        FVECT   wp[2], mov;
251 >        double  d;
252 >                                        /* do each wall on each section */
253 >        for (hd = 0; hdlist[hd] != NULL; hd++)
254 >                for (w = 0; w < 6; w++) {
255 >                        g0 = hdwg0[w];
256 >                        g1 = hdwg1[w];
257 >                        d = 1.0/hdlist[hd]->grid[g0];
258 >                        mov[0] = d * hdlist[hd]->xv[g0][0];
259 >                        mov[1] = d * hdlist[hd]->xv[g0][1];
260 >                        mov[2] = d * hdlist[hd]->xv[g0][2];
261 >                        if (w & 1) {
262 >                                VSUM(wp[0], hdlist[hd]->orig,
263 >                                                hdlist[hd]->xv[w>>1], 1.);
264 >                                VSUM(wp[0], wp[0], mov, 1.);
265 >                        } else
266 >                                VCOPY(wp[0], hdlist[hd]->orig);
267 >                        VSUM(wp[1], wp[0], hdlist[hd]->xv[g1], 1.);
268 >                        for (i = hdlist[hd]->grid[g0]; ; ) {    /* g0 lines */
269 >                                (*f)(wp);
270 >                                if (!--i) break;
271 >                                wp[0][0] += mov[0]; wp[0][1] += mov[1];
272 >                                wp[0][2] += mov[2]; wp[1][0] += mov[0];
273 >                                wp[1][1] += mov[1]; wp[1][2] += mov[2];
274 >                        }
275 >                        d = 1.0/hdlist[hd]->grid[g1];
276 >                        mov[0] = d * hdlist[hd]->xv[g1][0];
277 >                        mov[1] = d * hdlist[hd]->xv[g1][1];
278 >                        mov[2] = d * hdlist[hd]->xv[g1][2];
279 >                        if (w & 1)
280 >                                VSUM(wp[0], hdlist[hd]->orig,
281 >                                                hdlist[hd]->xv[w>>1], 1.);
282 >                        else
283 >                                VSUM(wp[0], hdlist[hd]->orig, mov, 1.);
284 >                        VSUM(wp[1], wp[0], hdlist[hd]->xv[g0], 1.);
285 >                        for (i = hdlist[hd]->grid[g1]; ; ) {    /* g1 lines */
286 >                                (*f)(wp);
287 >                                if (!--i) break;
288 >                                wp[0][0] += mov[0]; wp[0][1] += mov[1];
289 >                                wp[0][2] += mov[2]; wp[1][0] += mov[0];
290 >                                wp[1][1] += mov[1]; wp[1][2] += mov[2];
291 >                        }
292 >                }
293   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines