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.21 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   * Routines for converting holodeck coordinates, etc.
6   *
# Line 20 | Line 17 | int    hdwg1[6] = {2,2,0,0,1,1};
17   static double   logstep;
18  
19  
20 < hdcompgrid(hp)                  /* compute derived grid vector and index */
21 < register HOLO   *hp;
20 > extern void
21 > hdcompgrid(                     /* compute derived grid vector and index */
22 >        register HOLO   *hp
23 > )
24   {
25          double  d;
26          register int    i, j;
# Line 38 | Line 37 | register HOLO  *hp;
37          for (i = 0; i < 3; i++) {
38                  fcross(hp->wg[i], hp->xv[(i+1)%3], hp->xv[(i+2)%3]);
39                  d = DOT(hp->wg[i],hp->xv[i]);
40 <                if (d <= FTINY & d >= -FTINY)
40 >                if ((d <= FTINY) & (d >= -FTINY))
41                          error(USER, "degenerate holodeck section");
42 <                d = (double)hp->grid[i] / d;
42 >                d = hp->grid[i] / d;
43                  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;
44          }
45                                  /* compute linear depth range */
46          hp->tlin = VLEN(hp->xv[0]) + VLEN(hp->xv[1]) + VLEN(hp->xv[2]);
# Line 60 | Line 56 | register HOLO  *hp;
56   }
57  
58  
59 < HOLO *
60 < hdalloc(hproto)         /* allocate and set holodeck section based on grid */
61 < HDGRID  *hproto;
59 > extern int
60 > hdbcoord(               /* compute beam coordinates from index */
61 >        GCOORD  gc[2],          /* returned */
62 >        register HOLO   *hp,
63 >        register int    i
64 > )
65   {
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
97 hdbcoord(gc, hp, i)             /* compute beam coordinates from index */
98 GCOORD  gc[2];          /* returned */
99 register HOLO   *hp;
100 register int    i;
101 {
66          register int    j, n;
67          int     n2, reverse;
68          GCOORD  g2[2];
69                                          /* check range */
70 <        if (i < 1 | i > nbeams(hp))
70 >        if ((i < 1) | (i > nbeams(hp)))
71                  return(0);
72 <        if (reverse = i >= hp->wi[5])
72 >        if ( (reverse = i >= hp->wi[5]) )
73                  i -= hp->wi[5] - 1;
74          for (j = 0; j < 5; j++)         /* find w0 */
75                  if (hp->wi[j+1] > i)
# Line 130 | Line 94 | register int   i;
94          gc[1].i[1] = i / hp->grid[hdwg0[gc[1].w]];
95          gc[1].i[0] = i - gc[1].i[1]*hp->grid[hdwg0[gc[1].w]];
96          if (reverse) {
97 <                copystruct(g2, gc+1);
98 <                copystruct(gc+1, gc);
99 <                copystruct(gc, g2);
97 >                *g2 = *(gc+1);
98 >                *(gc+1) = *gc;
99 >                *gc = *g2;
100          }
101          return(1);                      /* we're done */
102   }
103  
104  
105 < int
106 < hdbindex(hp, gc)                /* compute index from beam coordinates */
107 < register HOLO   *hp;
108 < register GCOORD gc[2];
105 > extern int
106 > hdbindex(               /* compute index from beam coordinates */
107 >        register HOLO   *hp,
108 >        register GCOORD gc[2]
109 > )
110   {
111          GCOORD  g2[2];
112          int     reverse;
113          register int    i, j;
114                                          /* check ordering and limits */
115 <        if (reverse = gc[0].w > gc[1].w) {
116 <                copystruct(g2, gc+1);
117 <                copystruct(g2+1, gc);
115 >        if ( (reverse = gc[0].w > gc[1].w) ) {
116 >                *g2 = *(gc+1);
117 >                *(g2+1) = *gc;
118                  gc = g2;
119          } else if (gc[0].w == gc[1].w)
120                  return(0);
121 <        if (gc[0].w < 0 | gc[1].w > 5)
121 >        if ((gc[0].w < 0) | (gc[1].w > 5))
122                  return(0);
123          i = 0;                          /* compute index */
124          for (j = gc[0].w+1; j < gc[1].w; j++)
# Line 169 | Line 134 | register GCOORD        gc[2];
134   }
135  
136  
137 < hdcell(cp, hp, gc)              /* compute cell coordinates */
138 < register FVECT  cp[4];  /* returned (may be passed as FVECT cp[2][2]) */
139 < register HOLO   *hp;
140 < register GCOORD *gc;
137 > extern void
138 > hdcell(         /* compute cell coordinates */
139 >        register FVECT  cp[4],  /* returned (may be passed as FVECT cp[2][2]) */
140 >        register HOLO   *hp,
141 >        register GCOORD *gc
142 > )
143   {
144 <        register FLOAT  *v;
144 >        register RREAL  *v;
145          double  d;
146                                          /* compute common component */
147          VCOPY(cp[0], hp->orig);
# Line 201 | Line 168 | register GCOORD        *gc;
168   }
169  
170  
171 < hdlseg(lseg, hp, gc)                    /* compute line segment for beam */
172 < register int    lseg[2][3];
173 < register HOLO   *hp;
174 < GCOORD  gc[2];
171 > extern int
172 > hdlseg(                 /* compute line segment for beam */
173 >        register int    lseg[2][3],
174 >        register HOLO   *hp,
175 >        GCOORD  gc[2]
176 > )
177   {
178          register int    k;
179  
# Line 217 | Line 186 | GCOORD gc[2];
186   }
187  
188  
189 < unsigned
190 < hdcode(hp, d)                   /* compute depth code for d */
191 < HOLO    *hp;
192 < double  d;
189 > extern unsigned int
190 > hdcode(                 /* compute depth code for d */
191 >        HOLO    *hp,
192 >        double  d
193 > )
194   {
195          double  tl = hp->tlin;
196          register long   c;
# Line 236 | Line 206 | double d;
206   }
207  
208  
209 < hdgrid(gp, hp, wp)              /* compute grid coordinates */
210 < FVECT   gp;             /* returned */
211 < register HOLO   *hp;
212 < FVECT   wp;
209 > extern void
210 > hdgrid(         /* compute grid coordinates */
211 >        FVECT   gp,             /* returned */
212 >        register HOLO   *hp,
213 >        FVECT   wp
214 > )
215   {
216          FVECT   vt;
217  
# Line 250 | Line 222 | FVECT  wp;
222   }
223  
224  
225 < hdworld(wp, hp, gp)             /* compute world coordinates */
226 < register FVECT  wp;
227 < register HOLO   *hp;
228 < FVECT   gp;
225 > extern void
226 > hdworld(                /* compute world coordinates */
227 >        register FVECT  wp,
228 >        register HOLO   *hp,
229 >        FVECT   gp
230 > )
231   {
232          register double d;
233  
# Line 268 | Line 242 | FVECT  gp;
242   }
243  
244  
245 < double
246 < hdray(ro, rd, hp, gc, r)        /* compute ray within a beam */
247 < FVECT   ro, rd;         /* returned */
248 < HOLO    *hp;
249 < GCOORD  gc[2];
250 < BYTE    r[2][2];
245 > extern double
246 > hdray(  /* compute ray within a beam */
247 >        FVECT   ro,
248 >        FVECT   rd,             /* returned */
249 >        HOLO    *hp,
250 >        GCOORD  gc[2],
251 >        BYTE    r[2][2]
252 > )
253   {
254          FVECT   cp[4], p[2];
255          register int    i, j;
# Line 293 | Line 269 | BYTE   r[2][2];
269   }
270  
271  
272 < double
273 < hdinter(gc, r, ed, hp, ro, rd)  /* compute ray intersection with section */
274 < register GCOORD gc[2];  /* returned */
275 < BYTE    r[2][2];        /* returned (optional) */
276 < double  *ed;            /* returned (optional) */
277 < register HOLO   *hp;
278 < FVECT   ro, rd;         /* normalization of rd affects distances */
272 > extern double
273 > hdinter(        /* compute ray intersection with section */
274 >        register GCOORD gc[2],  /* returned */
275 >        BYTE    r[2][2],        /* returned (optional) */
276 >        double  *ed,            /* returned (optional) */
277 >        register HOLO   *hp,
278 >        FVECT   ro,
279 >        FVECT   rd              /* normalization of rd affects distances */
280 > )
281   {
282          FVECT   p[2], vt;
283          double  d, t0, t1, d0, d1;
284 <        register FLOAT  *v;
284 >        register RREAL  *v;
285          register int    i;
286                                          /* first, intersect walls */
287          gc[0].w = gc[1].w = -1;
288          t0 = -FHUGE; t1 = FHUGE;
289 +        VSUB(vt, ro, hp->orig);
290          for (i = 0; i < 3; i++) {               /* for each wall pair */
291                  d = -DOT(rd, hp->wg[i]);        /* plane distance */
292                  if (d <= FTINY && d >= -FTINY)  /* check for parallel */
293                          continue;
294 <                d1 = DOT(ro, hp->wg[i]);        /* ray distances */
295 <                d0 = (d1 - hp->wo[i<<1]) / d;
296 <                d1 = (d1 - hp->wo[i<<1|1]) / d;
297 <                if (d0 < d1) {          /* check against best */
294 >                d1 = DOT(vt, hp->wg[i]);        /* ray distances */
295 >                d0 = d1 / d;
296 >                d1 = (d1 - hp->grid[i]) / d;
297 >                if (d < 0) {                    /* check against best */
298                          if (d0 > t0) {
299                                  t0 = d0;
300                                  gc[0].w = i<<1;
# Line 335 | Line 314 | FVECT  ro, rd;         /* normalization of rd affects distance
314                          }
315                  }
316          }
317 <        if (gc[0].w < 0 | gc[1].w < 0)          /* paranoid check */
317 >        if ((gc[0].w < 0) | (gc[1].w < 0))              /* paranoid check */
318                  return(FHUGE);
319                                                  /* compute intersections */
320          VSUM(p[0], ro, rd, t0);
# Line 345 | Line 324 | FVECT  ro, rd;         /* normalization of rd affects distance
324                  VSUB(vt, p[i], hp->orig);
325                  v = hp->wg[hdwg0[gc[i].w]];
326                  d = DOT(vt, v);
327 <                if (d < 0. || (gc[i].i[0] = d) >= hp->grid[hdwg0[gc[i].w]])
327 >                if (d < 0 || d >= hp->grid[hdwg0[gc[i].w]])
328                          return(FHUGE);          /* outside wall */
329 +                gc[i].i[0] = d;
330                  if (r != NULL)
331                          r[i][0] = 256. * (d - gc[i].i[0]);
332                  v = hp->wg[hdwg1[gc[i].w]];
333                  d = DOT(vt, v);
334 <                if (d < 0. || (gc[i].i[1] = d) >= hp->grid[hdwg1[gc[i].w]])
334 >                if (d < 0 || d >= hp->grid[hdwg1[gc[i].w]])
335                          return(FHUGE);          /* outside wall */
336 +                gc[i].i[1] = d;
337                  if (r != NULL)
338                          r[i][1] = 256. * (d - gc[i].i[1]);
339          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines