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

Comparing ray/src/rt/o_mesh.c (file contents):
Revision 2.1 by greg, Tue Mar 11 17:08:55 2003 UTC vs.
Revision 2.9 by schorsch, Mon Jul 21 22:30:19 2003 UTC

# Line 21 | Line 21 | static const char RCSid[] = "$Id$";
21  
22   #include  "copyright.h"
23  
24 < #include  "ray.h"
24 > #include <string.h>
25  
26 + #include  "ray.h"
27   #include  "mesh.h"
27
28   #include  "tmesh.h"
29  
30  
31 < #define  EDGE_CACHE_SIZ         109     /* length of mesh edge cache */
31 > #define  EDGE_CACHE_SIZ         251     /* length of mesh edge cache */
32  
33   #define  curmi                  (edge_cache.mi)
34   #define  curmsh                 (curmi->msh)
# Line 39 | Line 39 | struct EdgeCache {
39          OBJREC          *o;     /* mesh object */
40          MESHINST        *mi;    /* current mesh instance */
41          struct EdgeSide {
42 <                int4    v1i, v2i;       /* vertex indices (lowest first) */
42 >                int32   v1i, v2i;       /* vertex indices (lowest first) */
43                  short   signum;         /* signed volume */
44          }               cache[EDGE_CACHE_SIZ];
45   }       edge_cache;
# Line 52 | Line 52 | OBJREC *o;
52                                          /* get mesh instance */
53          edge_cache.mi = getmeshinst(edge_cache.o = o, IO_ALL);
54                                          /* clear edge cache */
55 <        bzero((void *)edge_cache.cache, sizeof(edge_cache.cache));
55 >        memset((void *)edge_cache.cache, '\0', sizeof(edge_cache.cache));
56   }
57  
58  
59   static int
60   signed_volume(r, v1, v2)        /* get signed volume for ray and edge */
61   register RAY    *r;
62 < int4            v1, v2;
62 > int32           v1, v2;
63   {
64          int                             reversed = 0;
65          register struct EdgeSide        *ecp;
66          
67          if (v1 > v2) {
68 <                int4    t = v2; v2 = v1; v1 = t;
68 >                int32   t = v2; v2 = v1; v1 = t;
69                  reversed = 1;
70          }
71 <        ecp = &edge_cache.cache[(v2<<11 ^ v1) % EDGE_CACHE_SIZ];
71 >        ecp = &edge_cache.cache[((v2<<11 ^ v1) & 0x7fffffff) % EDGE_CACHE_SIZ];
72          if (ecp->v1i != v1 || ecp->v2i != v2) {
73                  MESHVERT        tv1, tv2;       /* compute signed volume */
74 +                FVECT           v2d;
75                  double          vol;
76                  if (!getmeshvert(&tv1, edge_cache.mi->msh, v1, MT_V) ||
77 <                                !getmeshvert(&tv2, edge_cache.mi->msh, v2, MT_V))
77 >                            !getmeshvert(&tv2, edge_cache.mi->msh, v2, MT_V))
78                          objerror(edge_cache.o, INTERNAL,
79 <                                        "missing mesh vertex in signed_volume");
79 >                                "missing mesh vertex in signed_volume");
80 >                VSUB(v2d, tv2.v, r->rorg);
81                  vol = (tv1.v[0] - r->rorg[0]) *
82 <                                ( (tv2.v[1] - r->rorg[1])*r->rdir[2] -
81 <                                  (tv2.v[2] - r->rorg[2])*r->rdir[1] );
82 >                                (v2d[1]*r->rdir[2] - v2d[2]*r->rdir[1]);
83                  vol += (tv1.v[1] - r->rorg[1]) *
84 <                                ( (tv2.v[2] - r->rorg[2])*r->rdir[0] -
84 <                                  (tv2.v[0] - r->rorg[0])*r->rdir[2] );
84 >                                (v2d[2]*r->rdir[0] - v2d[0]*r->rdir[2]);
85                  vol += (tv1.v[2] - r->rorg[2]) *
86 <                                ( (tv2.v[0] - r->rorg[0])*r->rdir[1] -
87 <                                  (tv2.v[1] - r->rorg[1])*r->rdir[0] );
86 >                                (v2d[0]*r->rdir[1] - v2d[1]*r->rdir[0]);
87                  if (vol > .0)
88                          ecp->signum = 1;
89                  else if (vol < .0)
# Line 103 | Line 102 | mesh_hit(oset, r)              /* intersect ray with mesh triangle
102   OBJECT  *oset;
103   RAY     *r;
104   {
105 <        int4            tvi[3];
105 >        int32           tvi[3];
106          int             sv1, sv2, sv3;
107          MESHVERT        tv[3];
108 +        OBJECT          tmod;
109          FVECT           va, vb, nrm;
110          double          d;
111          int             i;
112                                          /* check each triangle */
113          for (i = oset[0]; i > 0; i--) {
114 <                if (!getmeshtrivid(tvi, curmsh, oset[i]))
114 >                if (!getmeshtrivid(tvi, &tmod, curmsh, oset[i]))
115                          objerror(edge_cache.o, INTERNAL,
116 <                                        "missing triangle vertices in mesh_hit");
116 >                                "missing triangle vertices in mesh_hit");
117                  sv1 = signed_volume(r, tvi[0], tvi[1]);
118                  sv2 = signed_volume(r, tvi[1], tvi[2]);
119                  sv3 = signed_volume(r, tvi[2], tvi[0]);
# Line 139 | Line 139 | RAY    *r;
139                  r->rot = d;
140                  VSUM(r->rop, r->rorg, r->rdir, d);
141                  VCOPY(r->ron, nrm);
142 <                /* normalize(r->ron) called in o_mesh() & rod set */
142 >                /* normalize(r->ron) called & r->rod set in o_mesh() */
143          }
144   }
145  
# Line 152 | Line 152 | register RAY   *r;
152          RAY             rcont;
153          int             flags;
154          MESHVERT        tv[3];
155 <        FLOAT           wt[3];
155 >        OBJECT          tmod;
156 >        RREAL           wt[3];
157          int             i;
158                                          /* get the mesh instance */
159          prep_edge_cache(o);
160                                          /* copy and transform ray */
161 <        copystruct(&rcont, r);
161 >        rcont = *r;
162          multp3(rcont.rorg, r->rorg, curmi->x.b.xfm);
163          multv3(rcont.rdir, r->rdir, curmi->x.b.xfm);
164          for (i = 0; i < 3; i++)
# Line 170 | Line 171 | register RAY   *r;
171                  return(0);                      /* missed */
172          if (rcont.rot * curmi->x.f.sca >= r->rot)
173                  return(0);                      /* not close enough */
173
174        r->robj = objndx(o);            /* record new hit */
175        r->ro = o;
174                                          /* transform ray back */
175          r->rot = rcont.rot * curmi->x.f.sca;
176          multp3(r->rop, rcont.rop, curmi->x.f.xfm);
177          multv3(r->ron, rcont.ron, curmi->x.f.xfm);
178          normalize(r->ron);
179          r->rod = -DOT(r->rdir, r->ron);
180 <                                        /* compute barycentric weights */
181 <        flags = getmeshtri(tv, curmsh, rcont.robj, MT_ALL);
180 >                                        /* get triangle */
181 >        flags = getmeshtri(tv, &tmod, curmsh, rcont.robj, MT_ALL);
182          if (!(flags & MT_V))
183                  objerror(o, INTERNAL, "missing mesh vertices in o_mesh");
184 +        r->robj = objndx(o);            /* set object and material */
185 +        if (o->omod == OVOID && tmod != OVOID) {
186 +                r->ro = getmeshpseudo(curmsh, tmod);
187 +                r->rox = &curmi->x;
188 +        } else
189 +                r->ro = o;
190 +                                        /* compute barycentric weights */
191          if (flags & (MT_N|MT_UV))
192                  if (get_baryc(wt, rcont.rop, tv[0].v, tv[1].v, tv[2].v) < 0) {
193                          objerror(o, WARNING, "bad triangle in o_mesh");
# Line 197 | Line 202 | register RAY   *r;
202                  if (normalize(r->pert) != 0.0)
203                          for (i = 0; i < 3; i++)
204                                  r->pert[i] -= r->ron[i];
205 <        }
205 >        } else
206 >                r->pert[0] = r->pert[1] = r->pert[2] = .0;
207 >
208          if (flags & MT_UV)              /* interpolate uv coordinates */
209                  for (i = 0; i < 2; i++)
210                          r->uv[i] = wt[0]*tv[0].uv[i] +
211                                          wt[1]*tv[1].uv[i] +
212                                          wt[2]*tv[2].uv[i];
213 +        else
214 +                r->uv[0] = r->uv[1] = .0;
215  
216                                          /* return hit */
217          return(1);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines