8 |
|
*/ |
9 |
|
|
10 |
|
#include <stdlib.h> |
11 |
+ |
#include <ctype.h> |
12 |
|
#include "rtio.h" |
13 |
|
#include "rtmath.h" |
14 |
|
#include "rterror.h" |
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 |