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

Comparing ray/src/hd/holo.c (file contents):
Revision 3.14 by gwlarson, Mon Aug 31 15:40:13 1998 UTC vs.
Revision 3.20 by schorsch, Sun Jul 27 22:12:02 2003 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   * Routines for converting holodeck coordinates, etc.
6   *
# Line 38 | Line 35 | register HOLO  *hp;
35          for (i = 0; i < 3; i++) {
36                  fcross(hp->wg[i], hp->xv[(i+1)%3], hp->xv[(i+2)%3]);
37                  d = DOT(hp->wg[i],hp->xv[i]);
38 <                if (d <= FTINY & d >= -FTINY)
38 >                if ((d <= FTINY) & (d >= -FTINY))
39                          error(USER, "degenerate holodeck section");
40 <                d = (double)hp->grid[i] / d;
40 >                d = hp->grid[i] / d;
41                  hp->wg[i][0] *= d; hp->wg[i][1] *= d; hp->wg[i][2] *= d;
45                hp->wo[i<<1] = DOT(hp->wg[i],hp->orig);
46                d = DOT(hp->wg[i],hp->xv[i]);
47                hp->wo[i<<1|1] = hp->wo[i<<1] + d;
42          }
43                                  /* compute linear depth range */
44          hp->tlin = VLEN(hp->xv[0]) + VLEN(hp->xv[1]) + VLEN(hp->xv[2]);
# Line 60 | Line 54 | register HOLO  *hp;
54   }
55  
56  
63 HOLO *
64 hdalloc(hproto)         /* allocate and set holodeck section based on grid */
65 HDGRID  *hproto;
66 {
67        HOLO    hdhead;
68        register HOLO   *hp;
69        int     n;
70                                /* copy grid to temporary header */
71        bcopy((char *)hproto, (char *)&hdhead, sizeof(HDGRID));
72                                /* compute grid vectors and sizes */
73        hdcompgrid(&hdhead);
74                                /* allocate header with directory */
75        n = sizeof(HOLO)+nbeams(&hdhead)*sizeof(BEAMI);
76        if ((hp = (HOLO *)malloc(n)) == NULL)
77                return(NULL);
78                                /* copy header information */
79        copystruct(hp, &hdhead);
80                                /* allocate and clear beam list */
81        hp->bl = (BEAM **)malloc((nbeams(hp)+1)*sizeof(BEAM *)+sizeof(BEAM));
82        if (hp->bl == NULL) {
83                free((char *)hp);
84                return(NULL);
85        }
86        bzero((char *)hp->bl, (nbeams(hp)+1)*sizeof(BEAM *)+sizeof(BEAM));
87        hp->bl[0] = (BEAM *)(hp->bl+nbeams(hp)+1);      /* set blglob(hp) */
88        hp->fd = -1;
89        hp->dirty = 0;
90        hp->priv = NULL;
91                                /* clear beam directory */
92        bzero((char *)hp->bi, (nbeams(hp)+1)*sizeof(BEAMI));
93        return(hp);             /* all is well */
94 }
95
96
57   hdbcoord(gc, hp, i)             /* compute beam coordinates from index */
58   GCOORD  gc[2];          /* returned */
59   register HOLO   *hp;
# Line 103 | Line 63 | register int   i;
63          int     n2, reverse;
64          GCOORD  g2[2];
65                                          /* check range */
66 <        if (i < 1 | i > nbeams(hp))
66 >        if ((i < 1) | (i > nbeams(hp)))
67                  return(0);
68 <        if (reverse = i >= hp->wi[5])
68 >        if ( (reverse = i >= hp->wi[5]) )
69                  i -= hp->wi[5] - 1;
70          for (j = 0; j < 5; j++)         /* find w0 */
71                  if (hp->wi[j+1] > i)
# Line 130 | Line 90 | register int   i;
90          gc[1].i[1] = i / hp->grid[hdwg0[gc[1].w]];
91          gc[1].i[0] = i - gc[1].i[1]*hp->grid[hdwg0[gc[1].w]];
92          if (reverse) {
93 <                copystruct(g2, gc+1);
94 <                copystruct(gc+1, gc);
95 <                copystruct(gc, g2);
93 >                *g2 = *(gc+1);
94 >                *(gc+1) = *gc;
95 >                *gc = *g2;
96          }
97          return(1);                      /* we're done */
98   }
# Line 147 | Line 107 | register GCOORD        gc[2];
107          int     reverse;
108          register int    i, j;
109                                          /* check ordering and limits */
110 <        if (reverse = gc[0].w > gc[1].w) {
111 <                copystruct(g2, gc+1);
112 <                copystruct(g2+1, gc);
110 >        if ( (reverse = gc[0].w > gc[1].w) ) {
111 >                *g2 = *(gc+1);
112 >                *(g2+1) = *gc;
113                  gc = g2;
114          } else if (gc[0].w == gc[1].w)
115                  return(0);
116 <        if (gc[0].w < 0 | gc[1].w > 5)
116 >        if ((gc[0].w < 0) | (gc[1].w > 5))
117                  return(0);
118          i = 0;                          /* compute index */
119          for (j = gc[0].w+1; j < gc[1].w; j++)
# Line 174 | Line 134 | register FVECT cp[4];  /* returned (may be passed as FV
134   register HOLO   *hp;
135   register GCOORD *gc;
136   {
137 <        register FLOAT  *v;
137 >        register RREAL  *v;
138          double  d;
139                                          /* compute common component */
140          VCOPY(cp[0], hp->orig);
# Line 303 | Line 263 | FVECT  ro, rd;         /* normalization of rd affects distance
263   {
264          FVECT   p[2], vt;
265          double  d, t0, t1, d0, d1;
266 <        register FLOAT  *v;
266 >        register RREAL  *v;
267          register int    i;
268                                          /* first, intersect walls */
269          gc[0].w = gc[1].w = -1;
270          t0 = -FHUGE; t1 = FHUGE;
271 +        VSUB(vt, ro, hp->orig);
272          for (i = 0; i < 3; i++) {               /* for each wall pair */
273                  d = -DOT(rd, hp->wg[i]);        /* plane distance */
274                  if (d <= FTINY && d >= -FTINY)  /* check for parallel */
275                          continue;
276 <                d1 = DOT(ro, hp->wg[i]);        /* ray distances */
277 <                d0 = (d1 - hp->wo[i<<1]) / d;
278 <                d1 = (d1 - hp->wo[i<<1|1]) / d;
279 <                if (d0 < d1) {          /* check against best */
276 >                d1 = DOT(vt, hp->wg[i]);        /* ray distances */
277 >                d0 = d1 / d;
278 >                d1 = (d1 - hp->grid[i]) / d;
279 >                if (d < 0) {                    /* check against best */
280                          if (d0 > t0) {
281                                  t0 = d0;
282                                  gc[0].w = i<<1;
# Line 335 | Line 296 | FVECT  ro, rd;         /* normalization of rd affects distance
296                          }
297                  }
298          }
299 <        if (gc[0].w < 0 | gc[1].w < 0)          /* paranoid check */
299 >        if ((gc[0].w < 0) | (gc[1].w < 0))              /* paranoid check */
300                  return(FHUGE);
301                                                  /* compute intersections */
302          VSUM(p[0], ro, rd, t0);
# Line 345 | Line 306 | FVECT  ro, rd;         /* normalization of rd affects distance
306                  VSUB(vt, p[i], hp->orig);
307                  v = hp->wg[hdwg0[gc[i].w]];
308                  d = DOT(vt, v);
309 <                if (d < 0. || (gc[i].i[0] = d) >= hp->grid[hdwg0[gc[i].w]])
309 >                if (d < 0 || d >= hp->grid[hdwg0[gc[i].w]])
310                          return(FHUGE);          /* outside wall */
311 +                gc[i].i[0] = d;
312                  if (r != NULL)
313                          r[i][0] = 256. * (d - gc[i].i[0]);
314                  v = hp->wg[hdwg1[gc[i].w]];
315                  d = DOT(vt, v);
316 <                if (d < 0. || (gc[i].i[1] = d) >= hp->grid[hdwg1[gc[i].w]])
316 >                if (d < 0 || d >= hp->grid[hdwg1[gc[i].w]])
317                          return(FHUGE);          /* outside wall */
318 +                gc[i].i[1] = d;
319                  if (r != NULL)
320                          r[i][1] = 256. * (d - gc[i].i[1]);
321          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines