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.10 by greg, Wed Jun 15 12:29:55 1994 UTC vs.
Revision 2.11 by greg, Wed Jun 15 12:50:37 1994 UTC

# Line 20 | Line 20 | static char SCCSid[] = "$SunId$ LBL";
20   #include <ctype.h>
21  
22   #define TCALNAME        "tmesh.cal"     /* triangle interp. file */
23 #define QCALNAME        "surf.cal"      /* quad interp. file */
23   #define PATNAME         "M-pat"         /* mesh pattern name (reused) */
24   #define TEXNAME         "M-nor"         /* mesh texture name (reused) */
25   #define DEFOBJ          "unnamed"       /* default object name */
# Line 240 | Line 239 | FILE   *fp;
239                                  if (!puttri(argv[1], argv[2], argv[3]))
240                                          syntax("Bad triangle");
241                                  break;
243                        case 4:
244                                if (!putquad(argv[1], argv[2],
245                                                argv[3], argv[4]))
246                                        syntax("Bad quad");
247                                break;
242                          default:
243                                  if (!putface(argc-1, argv+1))
244                                          syntax("Bad face");
# Line 539 | Line 533 | register char  **av;
533          char    *cp;
534          register int    i;
535  
536 <        if (nonplanar(ac, av)) {        /* break into quads and triangles */
537 <                while (ac > 3) {
538 <                        if (!putquad(av[0], av[1], av[2], av[3]))
536 >        if (nonplanar(ac, av)) {        /* break into triangles */
537 >                while (ac > 2) {
538 >                        if (!puttri(av[0], av[1], av[2]))
539                                  return(0);
540 <                        ac -= 2;        /* remove two vertices & rotate */
540 >                        ac--;           /* remove vertex & rotate */
541                          cp = av[0];
542                          for (i = 0; i < ac-1; i++)
543 <                                av[i] = av[i+3];
543 >                                av[i] = av[i+2];
544                          av[i] = cp;
545                  }
552                if (ac == 3 && !puttri(av[0], av[1], av[2]))
553                        return(0);
546                  return(1);
547          }
548          if ((cp = getmtl()) == NULL)
# Line 687 | Line 679 | register BARYCCM       *bcm;
679                                  bcm->tm[0][0], bcm->tm[0][1], bcm->tm[0][2]);
680          printf("%14.8f %14.8f %14.8f\n",
681                                  bcm->tm[1][0], bcm->tm[1][1], bcm->tm[1][2]);
690 }
691
692
693 putquad(p0, p1, p3, p2)                 /* put out a quadrilateral */
694 char  *p0, *p1, *p3, *p2;               /* names correspond to binary pos. */
695 {
696        VNDX  p0i, p1i, p2i, p3i;
697        FVECT  norm[4];
698        char  *mod, *name;
699        int  axis;
700        FVECT  v1, v2, vc1, vc2;
701        int  ok1, ok2;
702
703 #ifdef TEXMAPS
704        /* also should output texture index coordinates,
705         * which will require new .cal file
706         */
707 #endif
708        if ((mod = getmtl()) == NULL)
709                return(-1);
710        name = getonm();
711                                        /* get actual indices */
712        if (!cvtndx(p0i,p0) || !cvtndx(p1i,p1) ||
713                        !cvtndx(p2i,p2) || !cvtndx(p3i,p3))
714                return(0);
715                                        /* compute exact normals */
716        fvsum(v1, vlist[p1i[0]], vlist[p0i[0]], -1.0);
717        fvsum(v2, vlist[p2i[0]], vlist[p0i[0]], -1.0);
718        fcross(vc1, v1, v2);
719        ok1 = normalize(vc1) != 0.0;
720        fvsum(v1, vlist[p2i[0]], vlist[p3i[0]], -1.0);
721        fvsum(v2, vlist[p1i[0]], vlist[p3i[0]], -1.0);
722        fcross(vc2, v1, v2);
723        ok2 = normalize(vc2) != 0.0;
724        if (!(ok1 | ok2))
725                return(-1);
726                                        /* compute normal interpolation */
727        axis = norminterp(norm, p0i, p1i, p2i, p3i);
728
729                                        /* put out quadrilateral? */
730        if (ok1 & ok2 && fabs(fdot(vc1,vc2)) >= 1.0-FTINY) {
731                printf("\n%s ", mod);
732                if (axis != -1) {
733                        printf("texfunc %s\n", TEXNAME);
734                        printf("4 surf_dx surf_dy surf_dz %s\n", QCALNAME);
735                        printf("0\n13\t%d\n", axis);
736                        pvect(norm[0]);
737                        pvect(norm[1]);
738                        pvect(norm[2]);
739                        fvsum(v1, norm[3], vc1, -0.5);
740                        fvsum(v1, v1, vc2, -0.5);
741                        pvect(v1);
742                        printf("\n%s ", TEXNAME);
743                }
744                printf("polygon %s.%d\n", name, faceno);
745                printf("0\n0\n12\n");
746                pvect(vlist[p0i[0]]);
747                pvect(vlist[p1i[0]]);
748                pvect(vlist[p3i[0]]);
749                pvect(vlist[p2i[0]]);
750                return(1);
751        }
752                                        /* put out triangles? */
753        if (ok1) {
754                printf("\n%s ", mod);
755                if (axis != -1) {
756                        printf("texfunc %s\n", TEXNAME);
757                        printf("4 surf_dx surf_dy surf_dz %s\n", QCALNAME);
758                        printf("0\n13\t%d\n", axis);
759                        pvect(norm[0]);
760                        pvect(norm[1]);
761                        pvect(norm[2]);
762                        fvsum(v1, norm[3], vc1, -1.0);
763                        pvect(v1);
764                        printf("\n%s ", TEXNAME);
765                }
766                printf("polygon %s.%da\n", name, faceno);
767                printf("0\n0\n9\n");
768                pvect(vlist[p0i[0]]);
769                pvect(vlist[p1i[0]]);
770                pvect(vlist[p2i[0]]);
771        }
772        if (ok2) {
773                printf("\n%s ", mod);
774                if (axis != -1) {
775                        printf("texfunc %s\n", TEXNAME);
776                        printf("4 surf_dx surf_dy surf_dz %s\n", QCALNAME);
777                        printf("0\n13\t%d\n", axis);
778                        pvect(norm[0]);
779                        pvect(norm[1]);
780                        pvect(norm[2]);
781                        fvsum(v2, norm[3], vc2, -1.0);
782                        pvect(v2);
783                        printf("\n%s ", TEXNAME);
784                }
785                printf("polygon %s.%db\n", name, faceno);
786                printf("0\n0\n9\n");
787                pvect(vlist[p2i[0]]);
788                pvect(vlist[p1i[0]]);
789                pvect(vlist[p3i[0]]);
790        }
791        return(1);
792 }
793
794
795 int
796 norminterp(resmat, p0i, p1i, p2i, p3i)  /* compute normal interpolation */
797 register FVECT  resmat[4];
798 register VNDX  p0i, p1i, p2i, p3i;
799 {
800 #define u  ((ax+1)%3)
801 #define v  ((ax+2)%3)
802
803        register int  ax;
804        MAT4  eqnmat;
805        FVECT  v1;
806        register int  i, j;
807
808 #ifdef TEXMAPS
809        /* also check for texture indices */
810 #endif
811        if (flatten || !(p0i[2]>=0 && p1i[2]>=0 && p2i[2]>=0 && p3i[2]>=0))
812                return(-1);
813                                        /* find dominant axis */
814        VCOPY(v1, vnlist[p0i[2]]);
815        fvsum(v1, v1, vnlist[p1i[2]], 1.0);
816        fvsum(v1, v1, vnlist[p2i[2]], 1.0);
817        fvsum(v1, v1, vnlist[p3i[2]], 1.0);
818        ax = ABS(v1[0]) > ABS(v1[1]) ? 0 : 1;
819        ax = ABS(v1[ax]) > ABS(v1[2]) ? ax : 2;
820                                        /* assign equation matrix */
821        eqnmat[0][0] = vlist[p0i[0]][u]*vlist[p0i[0]][v];
822        eqnmat[0][1] = vlist[p0i[0]][u];
823        eqnmat[0][2] = vlist[p0i[0]][v];
824        eqnmat[0][3] = 1.0;
825        eqnmat[1][0] = vlist[p1i[0]][u]*vlist[p1i[0]][v];
826        eqnmat[1][1] = vlist[p1i[0]][u];
827        eqnmat[1][2] = vlist[p1i[0]][v];
828        eqnmat[1][3] = 1.0;
829        eqnmat[2][0] = vlist[p2i[0]][u]*vlist[p2i[0]][v];
830        eqnmat[2][1] = vlist[p2i[0]][u];
831        eqnmat[2][2] = vlist[p2i[0]][v];
832        eqnmat[2][3] = 1.0;
833        eqnmat[3][0] = vlist[p3i[0]][u]*vlist[p3i[0]][v];
834        eqnmat[3][1] = vlist[p3i[0]][u];
835        eqnmat[3][2] = vlist[p3i[0]][v];
836        eqnmat[3][3] = 1.0;
837                                        /* invert matrix (solve system) */
838        if (!invmat4(eqnmat, eqnmat))
839                return(-1);                     /* no solution */
840                                        /* compute result matrix */
841        for (j = 0; j < 4; j++)
842                for (i = 0; i < 3; i++)
843                        resmat[j][i] =  eqnmat[j][0]*vnlist[p0i[2]][i] +
844                                        eqnmat[j][1]*vnlist[p1i[2]][i] +
845                                        eqnmat[j][2]*vnlist[p2i[2]][i] +
846                                        eqnmat[j][3]*vnlist[p3i[2]][i];
847 #ifdef TEXMAPS
848        /* compute result matrix for texture indices */
849 #endif
850        return(ax);
851
852 #undef u
853 #undef v
682   }
683  
684  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines