--- ray/src/common/xf.c 1989/10/05 07:54:31 1.4 +++ ray/src/common/xf.c 1989/10/13 19:34:51 1.6 @@ -12,8 +12,9 @@ static char SCCSid[] = "$SunId$ LBL"; #define PI 3.14159265358979323846 +#define d2r(a) ((PI/180.)*(a)) -#define checkarg(a,n) if (strcmp(av[i],a) || i+n >= ac) goto done +#define checkarg(a,n) if (av[i][a] || i+n >= ac) goto done int @@ -26,13 +27,11 @@ char *av[]; double atof(), sin(), cos(); double xfmat[4][4], m4[4][4]; double xfsca, theta; - int i, j; - int rept; + int i, icnt; setident4(retmat); *retsca = 1.0; - rept = 1; setident4(xfmat); xfsca = 1.0; @@ -43,7 +42,7 @@ char *av[]; switch (av[i][1]) { case 't': /* translate */ - checkarg("-t",3); + checkarg(2,3); m4[3][0] = atof(av[++i]); m4[3][1] = atof(av[++i]); m4[3][2] = atof(av[++i]); @@ -52,20 +51,20 @@ char *av[]; case 'r': /* rotate */ switch (av[i][2]) { case 'x': - checkarg("-rx",1); - theta = PI/180.0 * atof(av[++i]); + checkarg(3,1); + theta = d2r(atof(av[++i])); m4[1][1] = m4[2][2] = cos(theta); m4[2][1] = -(m4[1][2] = sin(theta)); break; case 'y': - checkarg("-ry",1); - theta = PI/180.0 * atof(av[++i]); + checkarg(3,1); + theta = d2r(atof(av[++i])); m4[0][0] = m4[2][2] = cos(theta); m4[0][2] = -(m4[2][0] = sin(theta)); break; case 'z': - checkarg("-rz",1); - theta = PI/180.0 * atof(av[++i]); + checkarg(3,1); + theta = d2r(atof(av[++i])); m4[0][0] = m4[1][1] = cos(theta); m4[1][0] = -(m4[0][1] = sin(theta)); break; @@ -75,7 +74,7 @@ char *av[]; break; case 's': /* scale */ - checkarg("-s",1); + checkarg(2,1); xfsca *= m4[0][0] = m4[1][1] = @@ -85,17 +84,17 @@ char *av[]; case 'm': /* mirror */ switch (av[i][2]) { case 'x': - checkarg("-mx",0); + checkarg(3,0); xfsca *= m4[0][0] = -1.0; break; case 'y': - checkarg("-my",0); + checkarg(3,0); xfsca *= m4[1][1] = -1.0; break; case 'z': - checkarg("-mz",0); + checkarg(3,0); xfsca *= m4[2][2] = -1.0; break; @@ -105,12 +104,12 @@ char *av[]; break; case 'i': /* iterate */ - checkarg("-i",1); - for (j = 0; j < rept; j++) { + checkarg(2,1); + icnt = atoi(av[++i]); + while (icnt-- > 0) { multmat4(retmat, retmat, xfmat); *retsca *= xfsca; } - rept = atoi(av[++i]); setident4(xfmat); xfsca = 1.0; break; @@ -122,10 +121,8 @@ char *av[]; multmat4(xfmat, xfmat, m4); } done: - for (j = 0; j < rept; j++) { - multmat4(retmat, retmat, xfmat); - *retsca *= xfsca; - } + multmat4(retmat, retmat, xfmat); + *retsca *= xfsca; return(i); } @@ -141,13 +138,11 @@ char *av[]; double atof(), sin(), cos(); double xfmat[4][4], m4[4][4]; double xfsca, theta; - int i, j; - int rept; + int i, icnt; setident4(retmat); *retsca = 1.0; - rept = 1; setident4(xfmat); xfsca = 1.0; @@ -158,7 +153,7 @@ char *av[]; switch (av[i][1]) { case 't': /* translate */ - checkarg("-t",3); + checkarg(2,3); m4[3][0] = -atof(av[++i]); m4[3][1] = -atof(av[++i]); m4[3][2] = -atof(av[++i]); @@ -167,20 +162,20 @@ char *av[]; case 'r': /* rotate */ switch (av[i][2]) { case 'x': - checkarg("-rx",1); - theta = -PI/180.0 * atof(av[++i]); + checkarg(3,1); + theta = -d2r(atof(av[++i])); m4[1][1] = m4[2][2] = cos(theta); m4[2][1] = -(m4[1][2] = sin(theta)); break; case 'y': - checkarg("-ry",1); - theta = -PI/180.0 * atof(av[++i]); + checkarg(3,1); + theta = -d2r(atof(av[++i])); m4[0][0] = m4[2][2] = cos(theta); m4[0][2] = -(m4[2][0] = sin(theta)); break; case 'z': - checkarg("-rz",1); - theta = -PI/180.0 * atof(av[++i]); + checkarg(3,1); + theta = -d2r(atof(av[++i])); m4[0][0] = m4[1][1] = cos(theta); m4[1][0] = -(m4[0][1] = sin(theta)); break; @@ -190,8 +185,8 @@ char *av[]; break; case 's': /* scale */ - checkarg("-s",1); - *xfsca *= + checkarg(2,1); + xfsca *= m4[0][0] = m4[1][1] = m4[2][2] = 1.0 / atof(av[++i]); @@ -200,18 +195,18 @@ char *av[]; case 'm': /* mirror */ switch (av[i][2]) { case 'x': - checkarg("-mx",0); - *xfsca *= + checkarg(3,0); + xfsca *= m4[0][0] = -1.0; break; case 'y': - checkarg("-my",0); - *xfsca *= + checkarg(3,0); + xfsca *= m4[1][1] = -1.0; break; case 'z': - checkarg("-mz",0); - *xfsca *= + checkarg(3,0); + xfsca *= m4[2][2] = -1.0; break; default: @@ -220,12 +215,12 @@ char *av[]; break; case 'i': /* iterate */ - checkarg("-i",1); - for (j = 0; j < rept; j++) { + checkarg(2,1); + icnt = atoi(av[++i]); + while (icnt-- > 0) { multmat4(retmat, xfmat, retmat); *retsca *= xfsca; } - rept = atoi(av[++i]); setident4(xfmat); xfsca = 1.0; break; @@ -237,10 +232,8 @@ char *av[]; multmat4(xfmat, m4, xfmat); /* left multiply */ } done: - for (j = 0; j < rept; j++) { - multmat4(retmat, xfmat, retmat); - *retsca *= xfsca; - } + multmat4(retmat, xfmat, retmat); + *retsca *= xfsca; return(i); } #endif