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.3 by greg, Thu Apr 2 22:14:01 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 + 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;
703 +
704 +        if ((sc == NULL) | (xfm == NULL))
705 +                return(0);
706 +                                        /* skip spaces at beginning */
707 +        while (isspace(*xfm))
708 +                xfm++;
709 +        if (!*xfm)
710 +                return(0);
711 +                                        /* parse string into words */
712 +        xav[0] = strcpy((char *)malloc(strlen(xfm)+1), xfm);
713 +        xac = 1; i = 0;
714 +        for ( ; ; ) {
715 +                while (!isspace(xfm[++i]))
716 +                        if (!xfm[i])
717 +                                break;
718 +                while (isspace(xfm[i]))
719 +                        xav[0][i++] = '\0';
720 +                if (!xfm[i])
721 +                        break;
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 +        i = xfScene(sc, xac, xav);
730 +        free(xav[0]);
731 +        return(i);
732 + }
733 + #undef MAXAC
734  
735   /* Free a scene */
736   void

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines