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.1 by greg, Mon Mar 30 18:28:35 2020 UTC vs.
Revision 2.2 by greg, Thu Apr 2 20:44:15 2020 UTC

# Line 8 | Line 8 | static const char RCSid[] = "$Id$";
8   */
9  
10   #include <stdlib.h>
11 + #include <ctype.h>
12   #include "rtio.h"
13   #include "rtmath.h"
14   #include "rterror.h"
# Line 662 | Line 663 | dupScene(const Scene *osc)
663          }
664          return(sc);
665   }
666 +
667 + /* Transform entire scene */
668 + #define MAXAC   100
669 + int
670 + xfmScene(Scene *sc, const char *xfm)
671 + {
672 +        char    *xav[MAXAC+1];
673 +        int     xac, i;
674 +        XF      myxf;
675 +        FVECT   vec;
676 +
677 +        if ((sc == NULL) | (xfm == NULL))
678 +                return(0);
679 +        while (isspace(*xfm))           /* find first word */
680 +                xfm++;
681 +        if (!*xfm)
682 +                return(0);
683 +                                        /* break into words for xf() */
684 +        xav[0] = strcpy((char *)malloc(strlen(xfm)+1), xfm);
685 +        xac = 1; i = 0;
686 +        for ( ; ; ) {
687 +                while (!isspace(xfm[++i]))
688 +                        if (!xfm[i])
689 +                                break;
690 +                while (isspace(xfm[i]))
691 +                        xav[0][i++] = '\0';
692 +                if (!xfm[i])
693 +                        break;
694 +                if (xac >= MAXAC-1)
695 +                        goto bad_xform;
696 +                xav[xac++] = xav[0] + i;
697 +        }
698 +        xav[xac] = NULL;
699 +        if (xf(&myxf, xac, xav) < xac)
700 +                goto bad_xform;
701 +        free(xav[0]);
702 +                                        /* 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);
719 + }
720 + #undef MAXAC
721  
722   /* Free a scene */
723   void

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines