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

Comparing ray/src/cv/obj2rad.c (file contents):
Revision 2.7 by greg, Thu Apr 14 13:36:18 1994 UTC vs.
Revision 2.22 by schorsch, Sat Nov 15 17:54:06 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 Wavefront .obj file to Radiance format.
6   *
# Line 13 | Line 10 | static char SCCSid[] = "$SunId$ LBL";
10   * I'm not sure they work correctly.  (Taken out -- see TEXMAPS defines.)
11   */
12  
13 < #include "standard.h"
13 > #include <stdlib.h>
14 > #include <stdio.h>
15 > #include <ctype.h>
16  
17 + #include "rtmath.h"
18 + #include "rtio.h"
19 + #include "resolu.h"
20   #include "trans.h"
21 + #include "tmesh.h"
22  
20 #include <ctype.h>
23  
22 #define TCALNAME        "tmesh.cal"     /* triangle interp. file */
23 #define QCALNAME        "surf.cal"      /* quad interp. file */
24   #define PATNAME         "M-pat"         /* mesh pattern name (reused) */
25   #define TEXNAME         "M-nor"         /* mesh texture name (reused) */
26   #define DEFOBJ          "unnamed"       /* default object name */
27   #define DEFMAT          "white"         /* default material name */
28  
29 #define  ABS(x)         ((x)>=0 ? (x) : -(x))
30
29   #define pvect(v)        printf("%18.12g %18.12g %18.12g\n",(v)[0],(v)[1],(v)[2])
30  
31   FVECT   *vlist;                 /* our vertex list */
32   int     nvs;                    /* number of vertices in our list */
33   FVECT   *vnlist;                /* vertex normal list */
34   int     nvns;
35 < FLOAT   (*vtlist)[2];           /* map vertex list */
35 > RREAL   (*vtlist)[2];           /* map vertex list */
36   int     nvts;
37  
40 typedef FLOAT   BARYCCM[3][4];  /* barycentric coordinate system */
41
38   typedef int     VNDX[3];        /* vertex index (point,map,normal) */
39  
40   #define CHUNKSIZ        256     /* vertex allocation chunk size */
# Line 70 | Line 66 | RULEHD *ourmapping = NULL;
66   char    *defmat = DEFMAT;       /* default (starting) material name */
67   char    *defobj = DEFOBJ;       /* default (starting) object name */
68  
69 < char    *getmtl(), *getonm();
69 > int     flatten = 0;            /* discard surface normal information */
70  
71   char    mapname[128];           /* current picture file */
72   char    matname[64];            /* current material name */
# Line 80 | Line 76 | char   *inpfile;               /* input file name */
76   int     lineno;                 /* current line number */
77   int     faceno;                 /* current face number */
78  
79 + static void getnames(FILE *fp);
80 + static void convert(FILE *fp);
81 + static int getstmt(char *av[MAXARG], FILE *fp);
82 + static char * getmtl(void);
83 + static char * getonm(void);
84 + static int matchrule(RULEHD *rp);
85 + static int cvtndx(VNDX vi, char *vs);
86 + static int nonplanar(int ac, char **av);
87 + static int putface(int ac, char **av);
88 + static int puttri(char *v1, char *v2, char *v3);
89 + static void freeverts(void);
90 + static int newv(double x, double y, double z);
91 + static int newvn(double x, double y, double z);
92 + static int newvt(double x, double y);
93 + static void syntax(char *er);
94  
95 < main(argc, argv)                /* read in .obj file and convert */
96 < int     argc;
97 < char    *argv[];
95 >
96 > int
97 > main(           /* read in .obj file and convert */
98 >        int     argc,
99 >        char    *argv[]
100 > )
101   {
102          int     donames = 0;
103          int     i;
# Line 99 | Line 113 | char   *argv[];
113                  case 'm':               /* use custom mapfile */
114                          ourmapping = getmapping(argv[++i], &qlist);
115                          break;
116 +                case 'f':               /* flatten surfaces */
117 +                        flatten++;
118 +                        break;
119                  default:
120                          goto userr;
121                  }
122 <        if (i > argc | i < argc-1)
122 >        if ((i > argc) | (i < argc-1))
123                  goto userr;
124          if (i == argc)
125                  inpfile = "<stdin>";
# Line 125 | Line 142 | char   *argv[];
142          }
143          exit(0);
144   userr:
145 <        fprintf(stderr, "Usage: %s [-o obj][-m mapping][-n] [file.obj]\n",
145 >        fprintf(stderr, "Usage: %s [-o obj][-m mapping][-n][-f] [file.obj]\n",
146                          argv[0]);
147          exit(1);
148   }
149  
150  
151 < getnames(fp)                    /* get valid qualifier names */
152 < FILE    *fp;
151 > void
152 > getnames(                       /* get valid qualifier names */
153 >        FILE    *fp
154 > )
155   {
156          char    *argv[MAXARG];
157          int     argc;
158          ID      tmpid;
159          register int    i;
160  
161 <        while (argc = getstmt(argv, fp))
161 >        while ( (argc = getstmt(argv, fp)) )
162                  switch (argv[0][0]) {
163                  case 'f':                               /* face */
164                          if (!argv[0][1])
# Line 180 | Line 199 | FILE   *fp;
199   }
200  
201  
202 < convert(fp)                     /* convert a T-mesh */
203 < FILE    *fp;
202 > void
203 > convert(                        /* convert a T-mesh */
204 >        FILE    *fp
205 > )
206   {
207          char    *argv[MAXARG];
208          int     argc;
# Line 190 | Line 211 | FILE   *fp;
211  
212          nstats = nunknown = 0;
213                                          /* scan until EOF */
214 <        while (argc = getstmt(argv, fp)) {
214 >        while ( (argc = getstmt(argv, fp)) ) {
215                  switch (argv[0][0]) {
216                  case 'v':               /* vertex */
217                          switch (argv[0][1]) {
# Line 232 | Line 253 | FILE   *fp;
253                                  if (!puttri(argv[1], argv[2], argv[3]))
254                                          syntax("Bad triangle");
255                                  break;
235                        case 4:
236                                if (!putquad(argv[1], argv[2],
237                                                argv[3], argv[4]))
238                                        syntax("Bad quad");
239                                break;
256                          default:
257                                  if (!putface(argc-1, argv+1))
258                                          syntax("Bad face");
# Line 289 | Line 305 | FILE   *fp;
305  
306  
307   int
308 < getstmt(av, fp)                         /* read the next statement from fp */
309 < register char   *av[MAXARG];
310 < FILE    *fp;
308 > getstmt(                                /* read the next statement from fp */
309 >        register char   *av[MAXARG],
310 >        FILE    *fp
311 > )
312   {
313          extern char     *fgetline();
314          static char     sbuf[MAXARG*10];
# Line 323 | Line 340 | FILE   *fp;
340  
341  
342   char *
343 < getmtl()                                /* figure material for this face */
343 > getmtl(void)                            /* figure material for this face */
344   {
345          register RULEHD *rp = ourmapping;
346  
# Line 349 | Line 366 | getmtl()                               /* figure material for this face */
366  
367  
368   char *
369 < getonm()                                /* invent a good name for object */
369 > getonm(void)                            /* invent a good name for object */
370   {
371          static char     name[64];
372          register char   *cp1, *cp2;
# Line 364 | Line 381 | getonm()                               /* invent a good name for object */
381                  cp2 = group[i];
382                  if (cp1 > name)
383                          *cp1++ = '.';
384 <                while (*cp1 = *cp2++)
384 >                while ( (*cp1 = *cp2++) )
385                          if (++cp1 >= name+sizeof(name)-2) {
386                                  *cp1 = '\0';
387                                  return(name);
# Line 374 | Line 391 | getonm()                               /* invent a good name for object */
391   }
392  
393  
394 < matchrule(rp)                           /* check for a match on this rule */
395 < register RULEHD *rp;
394 > int
395 > matchrule(                              /* check for a match on this rule */
396 >        register RULEHD *rp
397 > )
398   {
399          ID      tmpid;
400          int     gotmatch;
# Line 425 | Line 444 | register RULEHD        *rp;
444   }
445  
446  
447 < cvtndx(vi, vs)                          /* convert vertex string to index */
448 < register VNDX   vi;
449 < register char   *vs;
447 > int
448 > cvtndx(                         /* convert vertex string to index */
449 >        register VNDX   vi,
450 >        register char   *vs
451 > )
452   {
453                                          /* get point */
454          vi[0] = atoi(vs);
# Line 435 | Line 456 | register char  *vs;
456                  if (vi[0]-- > nvs)
457                          return(0);
458          } else if (vi[0] < 0) {
459 <                vi[0] = nvs + vi[0];
459 >                vi[0] += nvs;
460                  if (vi[0] < 0)
461                          return(0);
462          } else
# Line 449 | Line 470 | register char  *vs;
470                  if (vi[1]-- > nvts)
471                          return(0);
472          } else if (vi[1] < 0) {
473 <                vi[1] = nvts + vi[1];
473 >                vi[1] += nvts;
474                  if (vi[1] < 0)
475                          return(0);
476          } else
# Line 463 | Line 484 | register char  *vs;
484                  if (vi[2]-- > nvns)
485                          return(0);
486          } else if (vi[2] < 0) {
487 <                vi[2] = nvns + vi[2];
487 >                vi[2] += nvns;
488                  if (vi[2] < 0)
489                          return(0);
490          } else
# Line 472 | Line 493 | register char  *vs;
493   }
494  
495  
496 < nonplanar(ac, av)                       /* are vertices are non-planar? */
497 < register int    ac;
498 < register char   **av;
496 > int
497 > nonplanar(                      /* are vertices non-planar? */
498 >        register int    ac,
499 >        register char   **av
500 > )
501   {
502          VNDX    vi;
503 <        FLOAT   *p0, *p1;
503 >        RREAL   *p0, *p1;
504          FVECT   v1, v2, nsum, newn;
505          double  d;
506          register int    i;
507  
508          if (!cvtndx(vi, av[0]))
509                  return(0);
510 <        if (vi[2] >= 0)
510 >        if (!flatten && vi[2] >= 0)
511                  return(1);              /* has interpolated normals */
512          if (ac < 4)
513                  return(0);              /* it's a triangle! */
# Line 523 | Line 546 | register char  **av;
546   }
547  
548  
549 < putface(ac, av)                         /* put out an N-sided polygon */
550 < int     ac;
551 < register char   **av;
549 > int
550 > putface(                                /* put out an N-sided polygon */
551 >        int     ac,
552 >        register char   **av
553 > )
554   {
555          VNDX    vi;
556          char    *cp;
557          register int    i;
558  
559 <        if (nonplanar(ac, av)) {        /* break into quads and triangles */
560 <                while (ac > 3) {
561 <                        if (!putquad(av[0], av[1], av[2], av[3]))
559 >        if (nonplanar(ac, av)) {        /* break into triangles */
560 >                while (ac > 2) {
561 >                        if (!puttri(av[0], av[1], av[2]))
562                                  return(0);
563 <                        ac -= 2;        /* remove two vertices & rotate */
563 >                        ac--;           /* remove vertex & rotate */
564                          cp = av[0];
565                          for (i = 0; i < ac-1; i++)
566 <                                av[i] = av[i+3];
566 >                                av[i] = av[i+2];
567                          av[i] = cp;
568                  }
544                if (ac == 3 && !puttri(av[0], av[1], av[2]))
545                        return(0);
569                  return(1);
570          }
571          if ((cp = getmtl()) == NULL)
# Line 558 | Line 581 | register char  **av;
581   }
582  
583  
584 < puttri(v1, v2, v3)                      /* put out a triangle */
585 < char    *v1, *v2, *v3;
584 > int
585 > puttri(                 /* put out a triangle */
586 >        char *v1,
587 >        char *v2,
588 >        char *v3
589 > )
590   {
591          char    *mod;
592          VNDX    v1i, v2i, v3i;
593          BARYCCM bvecs;
594 <        int     texOK, patOK;
594 >        RREAL   bcoor[3][3];
595 >        int     texOK = 0, patOK;
596 >        int     flatness;
597 >        register int    i;
598  
599          if ((mod = getmtl()) == NULL)
600                  return(-1);
# Line 572 | Line 602 | char   *v1, *v2, *v3;
602          if (!cvtndx(v1i, v1) || !cvtndx(v2i, v2) || !cvtndx(v3i, v3))
603                  return(0);
604                                          /* compute barycentric coordinates */
605 <        texOK = (v1i[2]>=0 && v2i[2]>=0 && v3i[2]>=0);
605 >        if (v1i[2]>=0 && v2i[2]>=0 && v3i[2]>=0)
606 >                flatness = flat_tri(vlist[v1i[0]], vlist[v2i[0]], vlist[v3i[0]],
607 >                                vnlist[v1i[2]], vnlist[v2i[2]], vnlist[v3i[2]]);
608 >        else
609 >                flatness = ISFLAT;
610 >
611 >        switch (flatness) {
612 >        case DEGEN:                     /* zero area */
613 >                return(-1);
614 >        case RVFLAT:                    /* reversed normals, but flat */
615 >        case ISFLAT:                    /* smoothing unnecessary */
616 >                texOK = 0;
617 >                break;
618 >        case RVBENT:                    /* reversed normals with smoothing */
619 >        case ISBENT:                    /* proper smoothing */
620 >                texOK = 1;
621 >                break;
622 >        }
623 >        if (flatten)
624 >                texOK = 0;
625   #ifdef TEXMAPS
626          patOK = mapname[0] && (v1i[1]>=0 && v2i[1]>=0 && v3i[1]>=0);
627   #else
628          patOK = 0;
629   #endif
630          if (texOK | patOK)
631 <                if (comp_baryc(bvecs, vlist[v1i[0]], vlist[v2i[0]],
631 >                if (comp_baryc(&bvecs, vlist[v1i[0]], vlist[v2i[0]],
632                                  vlist[v3i[0]]) < 0)
633                          return(-1);
634                                          /* put out texture (if any) */
# Line 587 | Line 636 | char   *v1, *v2, *v3;
636                  printf("\n%s texfunc %s\n", mod, TEXNAME);
637                  mod = TEXNAME;
638                  printf("4 dx dy dz %s\n", TCALNAME);
639 <                printf("0\n21\n");
640 <                put_baryc(bvecs);
641 <                printf("\t%14.12g %14.12g %14.12g\n",
642 <                                vnlist[v1i[2]][0], vnlist[v2i[2]][0],
643 <                                vnlist[v3i[2]][0]);
644 <                printf("\t%14.12g %14.12g %14.12g\n",
645 <                                vnlist[v1i[2]][1], vnlist[v2i[2]][1],
597 <                                vnlist[v3i[2]][1]);
598 <                printf("\t%14.12g %14.12g %14.12g\n",
599 <                                vnlist[v1i[2]][2], vnlist[v2i[2]][2],
600 <                                vnlist[v3i[2]][2]);
639 >                printf("0\n");
640 >                for (i = 0; i < 3; i++) {
641 >                        bcoor[i][0] = vnlist[v1i[2]][i];
642 >                        bcoor[i][1] = vnlist[v2i[2]][i];
643 >                        bcoor[i][2] = vnlist[v3i[2]][i];
644 >                }
645 >                put_baryc(&bvecs, bcoor, 3);
646          }
647   #ifdef TEXMAPS
648                                          /* put out pattern (if any) */
# Line 605 | Line 650 | char   *v1, *v2, *v3;
650                  printf("\n%s colorpict %s\n", mod, PATNAME);
651                  mod = PATNAME;
652                  printf("7 noneg noneg noneg %s %s u v\n", mapname, TCALNAME);
653 <                printf("0\n18\n");
654 <                put_baryc(bvecs);
655 <                printf("\t%f %f %f\n", vtlist[v1i[1]][0],
656 <                                vtlist[v2i[1]][0], vtlist[v3i[1]][0]);
657 <                printf("\t%f %f %f\n", vtlist[v1i[1]][1],
658 <                                vtlist[v2i[1]][1], vtlist[v3i[1]][1]);
653 >                printf("0\n");
654 >                for (i = 0; i < 2; i++) {
655 >                        bcoor[i][0] = vtlist[v1i[1]][i];
656 >                        bcoor[i][1] = vtlist[v2i[1]][i];
657 >                        bcoor[i][2] = vtlist[v3i[1]][i];
658 >                }
659 >                put_baryc(&bvecs, bcoor, 2);
660          }
661   #endif
662 <                                        /* put out triangle */
662 >                                        /* put out (reversed) triangle */
663          printf("\n%s polygon %s.%d\n", mod, getonm(), faceno);
664          printf("0\n0\n9\n");
665 <        pvect(vlist[v1i[0]]);
666 <        pvect(vlist[v2i[0]]);
667 <        pvect(vlist[v3i[0]]);
668 <
669 <        return(1);
670 < }
671 <
672 <
627 < int
628 < comp_baryc(bcm, v1, v2, v3)             /* compute barycentric vectors */
629 < register BARYCCM        bcm;
630 < FLOAT   *v1, *v2, *v3;
631 < {
632 <        FLOAT   *vt;
633 <        FVECT   va, vab, vcb;
634 <        double  d;
635 <        register int    i, j;
636 <
637 <        for (j = 0; j < 3; j++) {
638 <                for (i = 0; i < 3; i++) {
639 <                        vab[i] = v1[i] - v2[i];
640 <                        vcb[i] = v3[i] - v2[i];
641 <                }
642 <                d = DOT(vcb,vcb);
643 <                if (d <= FTINY)
644 <                        return(-1);
645 <                d = DOT(vcb,vab)/d;
646 <                for (i = 0; i < 3; i++)
647 <                        va[i] = vab[i] - vcb[i]*d;
648 <                d = DOT(va,va);
649 <                if (d <= FTINY)
650 <                        return(-1);
651 <                for (i = 0; i < 3; i++) {
652 <                        va[i] /= d;
653 <                        bcm[j][i] = va[i];
654 <                }
655 <                bcm[j][3] = -DOT(v2,va);
656 <                                        /* rotate vertices */
657 <                vt = v1;
658 <                v1 = v2;
659 <                v2 = v3;
660 <                v3 = vt;
665 >        if (flatness == RVFLAT || flatness == RVBENT) {
666 >                pvect(vlist[v3i[0]]);
667 >                pvect(vlist[v2i[0]]);
668 >                pvect(vlist[v1i[0]]);
669 >        } else {
670 >                pvect(vlist[v1i[0]]);
671 >                pvect(vlist[v2i[0]]);
672 >                pvect(vlist[v3i[0]]);
673          }
662        return(0);
663 }
664
665
666 put_baryc(bcm)                          /* put barycentric coord. vectors */
667 register BARYCCM        bcm;
668 {
669        register int    i;
670
671        for (i = 0; i < 3; i++)
672                printf("%14.8f %14.8f %14.8f %14.8f\n",
673                                bcm[i][0], bcm[i][1], bcm[i][2], bcm[i][3]);
674 }
675
676
677 putquad(p0, p1, p3, p2)                 /* put out a quadrilateral */
678 char  *p0, *p1, *p3, *p2;               /* names correspond to binary pos. */
679 {
680        VNDX  p0i, p1i, p2i, p3i;
681        FVECT  norm[4];
682        char  *mod, *name;
683        int  axis;
684        FVECT  v1, v2, vc1, vc2;
685        int  ok1, ok2;
686
687 #ifdef TEXMAPS
688        /* also should output texture index coordinates,
689         * which will require new .cal file
690         */
691 #endif
692        if ((mod = getmtl()) == NULL)
693                return(-1);
694        name = getonm();
695                                        /* get actual indices */
696        if (!cvtndx(p0i,p0) || !cvtndx(p1i,p1) ||
697                        !cvtndx(p2i,p2) || !cvtndx(p3i,p3))
698                return(0);
699                                        /* compute exact normals */
700        fvsum(v1, vlist[p1i[0]], vlist[p0i[0]], -1.0);
701        fvsum(v2, vlist[p2i[0]], vlist[p0i[0]], -1.0);
702        fcross(vc1, v1, v2);
703        ok1 = normalize(vc1) != 0.0;
704        fvsum(v1, vlist[p2i[0]], vlist[p3i[0]], -1.0);
705        fvsum(v2, vlist[p1i[0]], vlist[p3i[0]], -1.0);
706        fcross(vc2, v1, v2);
707        ok2 = normalize(vc2) != 0.0;
708        if (!(ok1 | ok2))
709                return(-1);
710                                        /* compute normal interpolation */
711        axis = norminterp(norm, p0i, p1i, p2i, p3i);
712
713                                        /* put out quadrilateral? */
714        if (ok1 & ok2 && fabs(fdot(vc1,vc2)) >= 1.0-FTINY) {
715                printf("\n%s ", mod);
716                if (axis != -1) {
717                        printf("texfunc %s\n", TEXNAME);
718                        printf("4 surf_dx surf_dy surf_dz %s\n", QCALNAME);
719                        printf("0\n13\t%d\n", axis);
720                        pvect(norm[0]);
721                        pvect(norm[1]);
722                        pvect(norm[2]);
723                        fvsum(v1, norm[3], vc1, -0.5);
724                        fvsum(v1, v1, vc2, -0.5);
725                        pvect(v1);
726                        printf("\n%s ", TEXNAME);
727                }
728                printf("polygon %s.%d\n", name, faceno);
729                printf("0\n0\n12\n");
730                pvect(vlist[p0i[0]]);
731                pvect(vlist[p1i[0]]);
732                pvect(vlist[p3i[0]]);
733                pvect(vlist[p2i[0]]);
734                return(1);
735        }
736                                        /* put out triangles? */
737        if (ok1) {
738                printf("\n%s ", mod);
739                if (axis != -1) {
740                        printf("texfunc %s\n", TEXNAME);
741                        printf("4 surf_dx surf_dy surf_dz %s\n", QCALNAME);
742                        printf("0\n13\t%d\n", axis);
743                        pvect(norm[0]);
744                        pvect(norm[1]);
745                        pvect(norm[2]);
746                        fvsum(v1, norm[3], vc1, -1.0);
747                        pvect(v1);
748                        printf("\n%s ", TEXNAME);
749                }
750                printf("polygon %s.%da\n", name, faceno);
751                printf("0\n0\n9\n");
752                pvect(vlist[p0i[0]]);
753                pvect(vlist[p1i[0]]);
754                pvect(vlist[p2i[0]]);
755        }
756        if (ok2) {
757                printf("\n%s ", mod);
758                if (axis != -1) {
759                        printf("texfunc %s\n", TEXNAME);
760                        printf("4 surf_dx surf_dy surf_dz %s\n", QCALNAME);
761                        printf("0\n13\t%d\n", axis);
762                        pvect(norm[0]);
763                        pvect(norm[1]);
764                        pvect(norm[2]);
765                        fvsum(v2, norm[3], vc2, -1.0);
766                        pvect(v2);
767                        printf("\n%s ", TEXNAME);
768                }
769                printf("polygon %s.%db\n", name, faceno);
770                printf("0\n0\n9\n");
771                pvect(vlist[p2i[0]]);
772                pvect(vlist[p1i[0]]);
773                pvect(vlist[p3i[0]]);
774        }
674          return(1);
675   }
676  
677  
678 < int
679 < norminterp(resmat, p0i, p1i, p2i, p3i)  /* compute normal interpolation */
781 < register FVECT  resmat[4];
782 < register VNDX  p0i, p1i, p2i, p3i;
678 > void
679 > freeverts(void)                 /* free all vertices */
680   {
784 #define u  ((ax+1)%3)
785 #define v  ((ax+2)%3)
786
787        register int  ax;
788        MAT4  eqnmat;
789        FVECT  v1;
790        register int  i, j;
791
792 #ifdef TEXMAPS
793        /* also check for texture indices */
794 #endif
795        if (!(p0i[2]>=0 && p1i[2]>=0 && p2i[2]>=0 && p3i[2]>=0))
796                return(-1);
797                                        /* find dominant axis */
798        VCOPY(v1, vnlist[p0i[2]]);
799        fvsum(v1, v1, vnlist[p1i[2]], 1.0);
800        fvsum(v1, v1, vnlist[p2i[2]], 1.0);
801        fvsum(v1, v1, vnlist[p3i[2]], 1.0);
802        ax = ABS(v1[0]) > ABS(v1[1]) ? 0 : 1;
803        ax = ABS(v1[ax]) > ABS(v1[2]) ? ax : 2;
804                                        /* assign equation matrix */
805        eqnmat[0][0] = vlist[p0i[0]][u]*vlist[p0i[0]][v];
806        eqnmat[0][1] = vlist[p0i[0]][u];
807        eqnmat[0][2] = vlist[p0i[0]][v];
808        eqnmat[0][3] = 1.0;
809        eqnmat[1][0] = vlist[p1i[0]][u]*vlist[p1i[0]][v];
810        eqnmat[1][1] = vlist[p1i[0]][u];
811        eqnmat[1][2] = vlist[p1i[0]][v];
812        eqnmat[1][3] = 1.0;
813        eqnmat[2][0] = vlist[p2i[0]][u]*vlist[p2i[0]][v];
814        eqnmat[2][1] = vlist[p2i[0]][u];
815        eqnmat[2][2] = vlist[p2i[0]][v];
816        eqnmat[2][3] = 1.0;
817        eqnmat[3][0] = vlist[p3i[0]][u]*vlist[p3i[0]][v];
818        eqnmat[3][1] = vlist[p3i[0]][u];
819        eqnmat[3][2] = vlist[p3i[0]][v];
820        eqnmat[3][3] = 1.0;
821                                        /* invert matrix (solve system) */
822        if (!invmat4(eqnmat, eqnmat))
823                return(-1);                     /* no solution */
824                                        /* compute result matrix */
825        for (j = 0; j < 4; j++)
826                for (i = 0; i < 3; i++)
827                        resmat[j][i] =  eqnmat[j][0]*vnlist[p0i[2]][i] +
828                                        eqnmat[j][1]*vnlist[p1i[2]][i] +
829                                        eqnmat[j][2]*vnlist[p2i[2]][i] +
830                                        eqnmat[j][3]*vnlist[p3i[2]][i];
831 #ifdef TEXMAPS
832        /* compute result matrix for texture indices */
833 #endif
834        return(ax);
835
836 #undef u
837 #undef v
838 }
839
840
841 freeverts()                     /* free all vertices */
842 {
681          if (nvs) {
682 <                free((char *)vlist);
682 >                free((void *)vlist);
683                  nvs = 0;
684          }
685          if (nvts) {
686 <                free((char *)vtlist);
686 >                free((void *)vtlist);
687                  nvts = 0;
688          }
689          if (nvns) {
690 <                free((char *)vnlist);
690 >                free((void *)vnlist);
691                  nvns = 0;
692          }
693   }
694  
695  
696   int
697 < newv(x, y, z)                   /* create a new vertex */
698 < double  x, y, z;
697 > newv(                   /* create a new vertex */
698 >        double  x,
699 >        double  y,
700 >        double  z
701 > )
702   {
703          if (!(nvs%CHUNKSIZ)) {          /* allocate next block */
704                  if (nvs == 0)
705                          vlist = (FVECT *)malloc(CHUNKSIZ*sizeof(FVECT));
706                  else
707 <                        vlist = (FVECT *)realloc((char *)vlist,
707 >                        vlist = (FVECT *)realloc((void *)vlist,
708                                          (nvs+CHUNKSIZ)*sizeof(FVECT));
709                  if (vlist == NULL) {
710                          fprintf(stderr,
# Line 880 | Line 721 | double x, y, z;
721  
722  
723   int
724 < newvn(x, y, z)                  /* create a new vertex normal */
725 < double  x, y, z;
724 > newvn(                  /* create a new vertex normal */
725 >        double  x,
726 >        double  y,
727 >        double  z
728 > )
729   {
730          if (!(nvns%CHUNKSIZ)) {         /* allocate next block */
731                  if (nvns == 0)
732                          vnlist = (FVECT *)malloc(CHUNKSIZ*sizeof(FVECT));
733                  else
734 <                        vnlist = (FVECT *)realloc((char *)vnlist,
734 >                        vnlist = (FVECT *)realloc((void *)vnlist,
735                                          (nvns+CHUNKSIZ)*sizeof(FVECT));
736                  if (vnlist == NULL) {
737                          fprintf(stderr,
# Line 906 | Line 750 | double x, y, z;
750  
751  
752   int
753 < newvt(x, y)                     /* create a new texture map vertex */
754 < double  x, y;
753 > newvt(                  /* create a new texture map vertex */
754 >        double  x,
755 >        double  y
756 > )
757   {
758          if (!(nvts%CHUNKSIZ)) {         /* allocate next block */
759                  if (nvts == 0)
760 <                        vtlist = (FLOAT (*)[2])malloc(CHUNKSIZ*2*sizeof(FLOAT));
760 >                        vtlist = (RREAL (*)[2])malloc(CHUNKSIZ*2*sizeof(RREAL));
761                  else
762 <                        vtlist = (FLOAT (*)[2])realloc((char *)vtlist,
763 <                                        (nvts+CHUNKSIZ)*2*sizeof(FLOAT));
762 >                        vtlist = (RREAL (*)[2])realloc((void *)vtlist,
763 >                                        (nvts+CHUNKSIZ)*2*sizeof(RREAL));
764                  if (vtlist == NULL) {
765                          fprintf(stderr,
766                          "Out of memory while allocating texture vertex %d\n",
# Line 929 | Line 775 | double x, y;
775   }
776  
777  
778 < syntax(er)                      /* report syntax error and exit */
779 < char    *er;
778 > void
779 > syntax(                 /* report syntax error and exit */
780 >        char    *er
781 > )
782   {
783          fprintf(stderr, "%s: Wavefront syntax error near line %d: %s\n",
784                          inpfile, lineno, er);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines