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

Comparing ray/src/common/objutil.c (file contents):
Revision 2.2 by greg, Thu Apr 2 20:44:15 2020 UTC vs.
Revision 2.3 by greg, Thu Apr 2 22:14:01 2020 UTC

# Line 665 | Line 665 | dupScene(const Scene *osc)
665   }
666  
667   /* Transform entire scene */
668 + int
669 + xfScene(Scene *sc, int xac, char *xav[])
670 + {
671 +        XF      myxf;
672 +        FVECT   vec;
673 +        int     i;
674 +
675 +        if ((sc == NULL) | (xac <= 0) | (xav == NULL))
676 +                return(0);
677 +                                        /* compute matrix */
678 +        if (xf(&myxf, xac, xav) < xac)
679 +                return(0);
680 +                                        /* transform vertices */
681 +        for (i = 0; i < sc->nverts; i++) {
682 +                VCOPY(vec, sc->vert[i].p);
683 +                multp3(vec, vec, myxf.xfm);
684 +                VCOPY(sc->vert[i].p, vec);
685 +        }
686 +                                        /* transform normals */
687 +        for (i = 0; i < sc->nnorms; i++) {
688 +                VCOPY(vec, sc->norm[i]);
689 +                multv3(vec, vec, myxf.xfm);
690 +                vec[0] /= myxf.sca; vec[1] /= myxf.sca; vec[2] /= myxf.sca;
691 +                VCOPY(sc->norm[i], vec);
692 +        }
693 +        return(xac);                    /* all done */
694 + }
695 +
696 + /* Ditto, using transform string rather than pre-parsed words */
697   #define MAXAC   100
698   int
699   xfmScene(Scene *sc, const char *xfm)
700   {
701          char    *xav[MAXAC+1];
702          int     xac, i;
674        XF      myxf;
675        FVECT   vec;
703  
704          if ((sc == NULL) | (xfm == NULL))
705                  return(0);
706 <        while (isspace(*xfm))           /* find first word */
706 >                                        /* skip spaces at beginning */
707 >        while (isspace(*xfm))
708                  xfm++;
709          if (!*xfm)
710                  return(0);
711 <                                        /* break into words for xf() */
711 >                                        /* parse string into words */
712          xav[0] = strcpy((char *)malloc(strlen(xfm)+1), xfm);
713          xac = 1; i = 0;
714          for ( ; ; ) {
# Line 691 | Line 719 | xfmScene(Scene *sc, const char *xfm)
719                          xav[0][i++] = '\0';
720                  if (!xfm[i])
721                          break;
722 <                if (xac >= MAXAC-1)
723 <                        goto bad_xform;
722 >                if (xac >= MAXAC-1) {
723 >                        free(xav[0]);
724 >                        return(0);
725 >                }
726                  xav[xac++] = xav[0] + i;
727          }
728          xav[xac] = NULL;
729 <        if (xf(&myxf, xac, xav) < xac)
700 <                goto bad_xform;
729 >        i = xfScene(sc, xac, xav);
730          free(xav[0]);
731 <                                        /* transform vertices */
703 <        for (i = 0; i < sc->nverts; i++) {
704 <                VCOPY(vec, sc->vert[i].p);
705 <                multp3(vec, vec, myxf.xfm);
706 <                VCOPY(sc->vert[i].p, vec);
707 <        }
708 <                                        /* transform normals */
709 <        for (i = 0; i < sc->nnorms; i++) {
710 <                VCOPY(vec, sc->norm[i]);
711 <                multv3(vec, vec, myxf.xfm);
712 <                vec[0] /= myxf.sca; vec[1] /= myxf.sca; vec[2] /= myxf.sca;
713 <                VCOPY(sc->norm[i], vec);
714 <        }
715 <        return xac;                     /* finito */
716 < bad_xform:
717 <        free(xav[0]);
718 <        return(0);
731 >        return(i);
732   }
733   #undef MAXAC
734  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines