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.7 by gregl, Tue Nov 25 10:48:38 1997 UTC vs.
Revision 3.18 by gregl, Tue Jan 6 15:08:50 1998 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1997 Silicon Graphics, Inc. */
1 > /* Copyright (c) 1998 Silicon Graphics, Inc. */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ SGI";
# Line 12 | Line 12 | static char SCCSid[] = "$SunId$ SGI";
12   #include "rhdisp.h"
13   #include "rhdriver.h"
14  
15 + #ifndef MAXDIST
16 + #define MAXDIST         42      /* maximum distance outside section */
17 + #endif
18 +
19   extern GCOORD   *getviewcells();
20  
21   static VIEW     dvw;            /* current view corresponding to beam list */
# Line 90 | Line 94 | register struct beamcomp       *cb1, *cb2;
94  
95          if (!cb1->wants)                /* put orphans at the end, unsorted */
96                  return(cb2->wants);
97 +        if (!cb2->wants)
98 +                return(-1);
99          if ((c = cb1->bi - cb2->bi))    /* sort on beam index first */
100                  return(c);
101          return(cb1->hd - cb2->hd);      /* use hd to resolve matches */
# Line 178 | Line 184 | int    hr, vr;
184                  pa[i].bi = bl[i].bi;
185                  pa[i].nr = v==NULL ? 0 :
186                                  npixels(v, hr, vr, hdlist[bl[i].hd], bl[i].bi);
187 +                pa[i].nc = 0;
188          }
189          serv_request(op, n*sizeof(PACKHEAD), (char *)pa);
190          free((char *)pa);
# Line 228 | Line 235 | get_voxels(vl, vp)     /* find voxels corresponding to vie
235   VOXL    vl[8];
236   FVECT   vp;
237   {
231        static int      lastn = 0, lastd = -1;
238          int     n = 0;
239          FVECT   gp;
240          double  d;
# Line 259 | Line 265 | FVECT  vp;
265                          n++;
266                  }
267          }
268 <                                        /* warn of dangerous moves */
269 <        if (n < lastn && bestd >= lastd)
270 <                error(WARNING, "moving outside holodeck section");
271 <        else if (n > lastn && bestd <= lastd)
272 <                error(WARNING, "moving inside holodeck section");
273 <        lastd = bestd;
268 <        return(lastn = n);
268 >                                        /* check for really stupid move */
269 >        if (bestd > MAXDIST) {
270 >                error(COMMAND, "move past outer limits");
271 >                return(0);
272 >        }
273 >        return(n);
274   }
275  
276  
# Line 307 | Line 312 | docell(gcp, cap)       /* find beams corresponding to cell a
312   GCOORD  *gcp;
313   register struct cellact *cap;
314   {
315 +        register HOLO   *hp = hdlist[voxel[cap->vi].hd];
316          FVECT   org, dir[4];
317 <        FVECT   gp, cv[4], vc;
317 >        FVECT   vgp, cgp, vc;
318 >        FVECT   v1, v2;
319          struct beamact  bo;
320 +        int     axmax, j;
321 +        double  d, avmax;
322          register int    i;
323 <                                /* compute cell vertices */
324 <        hdcell(cv, hdlist[voxel[cap->vi].hd], gcp);
325 <                                /* compute cell and voxel centers */
326 <        for (i = 0; i < 3; i++) {
327 <                org[i] = 0.5*(cv[0][i] + cv[2][i]);
328 <                gp[i] = voxel[cap->vi].i[i] + 0.5;
329 <        }
330 <        hdworld(vc, hdlist[voxel[cap->vi].hd], gp);
331 <                                /* compute voxel pyramid using vector trick */
332 <        for (i = 0; i < 3; i++) {
333 <                dir[0][i] = vc[i] - cv[0][i];           /* to 3 */
334 <                dir[2][i] = vc[i] - cv[3][i];           /* to 0 */
335 <                if (gcp->w & 1) {       /* watch vertex order! */
336 <                        dir[1][i] = vc[i] - cv[2][i];   /* to 1 */
337 <                        dir[3][i] = vc[i] - cv[1][i];   /* to 2 */
338 <                } else {
339 <                        dir[1][i] = vc[i] - cv[1][i];   /* to 2 */
340 <                        dir[3][i] = vc[i] - cv[2][i];   /* to 1 */
323 >                                /* compute cell center */
324 >        cgp[gcp->w>>1] = gcp->w&1 ? hp->grid[gcp->w>>1] : 0 ;
325 >        cgp[hdwg0[gcp->w]] = gcp->i[0] + .5;
326 >        cgp[hdwg1[gcp->w]] = gcp->i[1] + .5;
327 >        hdworld(org, hp, cgp);
328 >                                /* compute direction to voxel center */
329 >        for (i = 3; i--; )
330 >                vgp[i] = voxel[cap->vi].i[i] + .5;
331 >        hdworld(vc, hp, vgp);
332 >        for (i = 3; i--; )
333 >                vc[i] -= org[i];
334 >                                /* compute maximum area axis */
335 >        axmax = -1; avmax = 0;
336 >        for (i = 3; i--; ) {
337 >                d = vgp[i] - cgp[i];
338 >                if (d < 0.) d = -d;
339 >                if (d > avmax) {
340 >                        avmax = d;
341 >                        axmax = i;
342                  }
343          }
344 + #ifdef DEBUG
345 +        if (axmax < 0.)
346 +                error(CONSISTENCY, "botched axis computation in docell");
347 + #endif
348 +                                /* compute offset vectors */
349 +        d = 0.5/hp->grid[j=(axmax+1)%3];
350 +        for (i = 3; i--; )
351 +                v1[i] = hp->xv[j][i] * d;
352 +        d = 0.5/hp->grid[j=(axmax+2)%3];
353 +        if (DOT(hp->wg[axmax], vc) < 0.)
354 +                d = -d; /* reverse vertex order */
355 +        for (i = 3; i--; )
356 +                v2[i] = hp->xv[j][i] * d;
357 +                                /* compute voxel pyramid */
358 +        for (i = 3; i--; ) {
359 +                dir[0][i] = vc[i] - v1[i] - v2[i];
360 +                dir[1][i] = vc[i] + v1[i] - v2[i];
361 +                dir[2][i] = vc[i] + v1[i] + v2[i];
362 +                dir[3][i] = vc[i] - v1[i] + v2[i];
363 +        }
364                                  /* visit beams for opposite cells */
365          copystruct(&bo.ca, cap);
366          copystruct(&bo.gc, gcp);
367 <        return(visit_cells(org, dir, hdlist[voxel[cap->vi].hd], dobeam, &bo));
367 >        return(visit_cells(org, dir, hp, dobeam, &bo));
368   }
369  
370  
# Line 370 | Line 400 | VIEW   *vold, *vnew;
400          ngcp = ngcl = getviewcells(&ncnt, hdlist[voxel[voxi].hd], vnew);
401                                  /* set up actions */
402          oca.vi = nca.vi = voxi;
373        oca.rev = nca.rev = 0;
403          oca.add = 0; nca.add = 1;
404          if ((oca.rev = ocnt < 0))
405                  ocnt = -ocnt;
# Line 400 | Line 429 | VIEW   *vold, *vnew;
429   }
430  
431  
432 + int
433   beam_sync()             /* synchronize beams on server */
434   {
435          cbeamop(DR_NEWSET, cbeam, ncbeams, &odev.v, odev.hres, odev.vres);
436 +        return(ncbeams);
437   }
438  
439  
440 < beam_view(vn)                   /* change beam view */
440 > beam_view(vn)                   /* change beam view (if advisable) */
441   VIEW    *vn;
442   {
443          struct cellact  ca;
444          VOXL    vlnew[8];
445          int     n, comn;
446  
447 <        if (!vn->type) {                /* clear our beam list */
447 >        if (vn == NULL || !vn->type) {  /* clear our beam list */
448                  set_voxels(vlnew, 0);
449                  cbeamop(DR_DELSET, cbeam, ncbeams, NULL, 0, 0);
450                  ncbeams = 0;
451 <                copystruct(&dvw, vn);
452 <                return;
451 >                dvw.type = 0;
452 >                return(1);
453          }
454                                          /* find our new voxels */
455          n = get_voxels(vlnew, vn->vp);
456 +        if (dvw.type && !n) {
457 +                copystruct(vn, &dvw);           /* cancel move */
458 +                return(0);
459 +        }
460                                          /* set the new voxels */
461          comn = set_voxels(vlnew, n);
462          if (!dvw.type)
# Line 440 | Line 475 | VIEW   *vn;
475          cbeamop(DR_DELSET, cbeam+ncbeams, xcbeams, NULL, 0, 0);
476          xcbeams = 0;                    /* truncate our list */
477          copystruct(&dvw, vn);           /* record new view */
478 +        return(1);
479   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines