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

Comparing ray/src/cv/tmesh2rad.c (file contents):
Revision 2.4 by greg, Tue Mar 22 08:54:23 1994 UTC vs.
Revision 2.10 by greg, Sat Feb 22 02:07:23 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1994 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   * Convert a trianglular mesh into a Radiance description.
6   *
# Line 34 | Line 31 | static char SCCSid[] = "$SunId$ LBL";
31  
32   #include "standard.h"
33  
34 + #include "tmesh.h"
35 +
36   #define VOIDID          "void"          /* this is defined in object.h */
37  
39 #define CALNAME         "tmesh.cal"     /* the name of our auxiliary file */
38   #define PATNAME         "T-pat"         /* triangle pattern name (reused) */
39   #define TEXNAME         "T-nor"         /* triangle texture name (reused) */
40  
# Line 54 | Line 52 | typedef struct {
52   VERTEX  *vlist = NULL;          /* our vertex list */
53   int     nverts = 0;             /* number of vertices in our list */
54  
57 typedef FLOAT   BARYCCM[3][4];
58
55   #define novert(i)       ((i)<0|(i)>=nverts || !(vlist[i].flags&V_DEFINED))
56  
57   #define CHUNKSIZ        128     /* vertex allocation chunk size */
# Line 205 | Line 201 | register VERTEX        *v1, *v2, *v3;
201   {
202          static int      ntri = 0;
203          BARYCCM bvecs;
204 +        FLOAT   bvm[3][3];
205 +        register int    i;
206                                          /* compute barycentric coordinates */
207          if (v1->flags & v2->flags & v3->flags & (V_HASINDX|V_HASNORM))
208 <                if (comp_baryc(bvecs, v1->pos, v2->pos, v3->pos) < 0)
208 >                if (comp_baryc(&bvecs, v1->pos, v2->pos, v3->pos) < 0)
209                          return;
210                                          /* put out texture (if any) */
211 <        if (v1->flags & v2->flags & v3->flags & V_HASNORM) {
211 >        if (v1->flags & v2->flags & v3->flags & V_HASNORM &&
212 >                        !flat_tri(v1->pos, v2->pos, v3->pos,
213 >                                        v1->nor, v2->nor, v3->nor)) {
214                  printf("\n%s texfunc %s\n", mod, TEXNAME);
215                  mod = TEXNAME;
216 <                printf("4 dx dy dz %s\n", CALNAME);
217 <                printf("0\n21\n");
218 <                put_baryc(bvecs);
219 <                printf("\t%14.12g %14.12g %14.12g\n",
220 <                                v1->nor[0], v2->nor[0], v3->nor[0]);
221 <                printf("\t%14.12g %14.12g %14.12g\n",
222 <                                v1->nor[1], v2->nor[1], v3->nor[1]);
223 <                printf("\t%14.12g %14.12g %14.12g\n",
224 <                                v1->nor[2], v2->nor[2], v3->nor[2]);
216 >                printf("4 dx dy dz %s\n", TCALNAME);
217 >                printf("0\n");
218 >                for (i = 0; i < 3; i++) {
219 >                        bvm[i][0] = v1->nor[i];
220 >                        bvm[i][1] = v2->nor[i];
221 >                        bvm[i][2] = v3->nor[i];
222 >                }
223 >                put_baryc(&bvecs, bvm, 3);
224          }
225                                          /* put out pattern (if any) */
226          if (*pn && (v1->flags & v2->flags & v3->flags & V_HASINDX)) {
227                  printf("\n%s colorpict %s\n", mod, PATNAME);
228                  mod = PATNAME;
229 <                printf("7 noneg noneg noneg %s %s u v\n", pn, CALNAME);
230 <                printf("0\n18\n");
231 <                put_baryc(bvecs);
232 <                printf("\t%f %f %f\n", v1->ndx[0], v2->ndx[0], v3->ndx[0]);
233 <                printf("\t%f %f %f\n", v1->ndx[1], v2->ndx[1], v3->ndx[1]);
229 >                printf("7 noneg noneg noneg %s %s u v\n", pn, TCALNAME);
230 >                printf("0\n");
231 >                for (i = 0; i < 2; i++) {
232 >                        bvm[i][0] = v1->ndx[i];
233 >                        bvm[i][1] = v2->ndx[i];
234 >                        bvm[i][2] = v3->ndx[i];
235 >                }
236 >                put_baryc(&bvecs, bvm, 2);
237          }
238                                          /* put out triangle */
239          printf("\n%s polygon %s.%d\n", mod, obj, ++ntri);
# Line 239 | Line 241 | register VERTEX        *v1, *v2, *v3;
241          printf("%18.12g %18.12g %18.12g\n", v1->pos[0],v1->pos[1],v1->pos[2]);
242          printf("%18.12g %18.12g %18.12g\n", v2->pos[0],v2->pos[1],v2->pos[2]);
243          printf("%18.12g %18.12g %18.12g\n", v3->pos[0],v3->pos[1],v3->pos[2]);
242 }
243
244
245 int
246 comp_baryc(bcm, v1, v2, v3)             /* compute barycentric vectors */
247 register BARYCCM        bcm;
248 FLOAT   *v1, *v2, *v3;
249 {
250        FLOAT   *vt;
251        FVECT   va, vab, vcb;
252        double  d;
253        register int    i, j;
254
255        for (j = 0; j < 3; j++) {
256                for (i = 0; i < 3; i++) {
257                        vab[i] = v1[i] - v2[i];
258                        vcb[i] = v3[i] - v2[i];
259                }
260                d = DOT(vcb,vcb);
261                if (d <= FTINY)
262                        return(-1);
263                d = DOT(vcb,vab)/d;
264                for (i = 0; i < 3; i++)
265                        va[i] = vab[i] - vcb[i]*d;
266                d = DOT(va,va);
267                if (d <= FTINY)
268                        return(-1);
269                for (i = 0; i < 3; i++) {
270                        va[i] /= d;
271                        bcm[j][i] = va[i];
272                }
273                bcm[j][3] = -DOT(v2,va);
274                                        /* rotate vertices */
275                vt = v1;
276                v1 = v2;
277                v2 = v3;
278                v3 = vt;
279        }
280        return(0);
281 }
282
283
284 put_baryc(bcm)                          /* put barycentric coord. vectors */
285 register BARYCCM        bcm;
286 {
287        register int    i;
288
289        for (i = 0; i < 3; i++)
290                printf("%14.8f %14.8f %14.8f %14.8f\n",
291                                bcm[i][0], bcm[i][1], bcm[i][2], bcm[i][3]);
244   }
245  
246  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines