--- ray/src/gen/replmarks.c 2005/03/17 06:38:45 2.13 +++ ray/src/gen/replmarks.c 2025/04/22 04:45:25 2.19 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: replmarks.c,v 2.13 2005/03/17 06:38:45 greg Exp $"; +static const char RCSid[] = "$Id: replmarks.c,v 2.19 2025/04/22 04:45:25 greg Exp $"; #endif /* * Replace markers in Radiance scene description with objects or instances. @@ -14,7 +14,7 @@ static const char RCSid[] = "$Id: replmarks.c,v 2.13 2 #include "platform.h" #include "rtio.h" -#include "rtprocess.h" +#include "paths.h" #include "fvect.h" #ifdef M_PI @@ -23,8 +23,6 @@ static const char RCSid[] = "$Id: replmarks.c,v 2.13 2 #define PI 3.14159265358979323846 #endif -#define FEQ(a,b) ((a)-(b) <= 1e-7 && (b)-(a) <= 1e-7) - #define MAXVERT 6 /* maximum number of vertices for markers */ #define MAXMARK 128 /* maximum number of markers */ @@ -185,7 +183,12 @@ cvcomm( /* convert a command */ exit(1); } convert(buf, pin); - pclose(pin); + if (pclose(pin) != 0) { + fprintf(stderr, + "%s: (%s): bad status from \"%s\"\n", + progname, fname, buf); + exit(1); + } } else printf("\n%s\n", buf); } @@ -202,7 +205,9 @@ cvobject( /* convert an object */ int i, n; register int j; - if (fscanf(fin, "%s %s %s", buf, typ, nam) != 3) + if (fgetword(buf, sizeof(buf), fin) == NULL || + fgetword(typ, sizeof(typ), fin) == NULL || + fgetword(nam, sizeof(nam), fin) == NULL) goto readerr; if (!strcmp(typ, "polygon")) for (j = 0; j < nmarkers; j++) @@ -210,11 +215,13 @@ cvobject( /* convert an object */ replace(fname, &marker[j], nam, fin); return; } - printf("\n%s %s %s\n", buf, typ, nam); + putchar('\n'); fputword(buf, stdout); + printf(" %s ", typ); + fputword(nam, stdout); putchar('\n'); if (!strcmp(typ, "alias")) { /* alias special case */ - if (fscanf(fin, "%s", buf) != 1) + if (fgetword(buf, sizeof(buf), fin) == NULL) goto readerr; - printf("\t%s\n", buf); + putchar('\t'); fputword(buf, stdout); putchar('\n'); return; } for (i = 0; i < 3; i++) { /* pass along arguments */ @@ -387,21 +394,29 @@ addrot( /* compute rotation (x,y,z) => (xp,yp,zp) */ int n; double theta; + if (yp[2]*yp[2] + zp[2]*zp[2] < 2.*FTINY*FTINY) { + /* Special case for X' along Z-axis */ + theta = -atan2(yp[0], yp[1]); + sprintf(xf, " -ry %f -rz %f", + xp[2] < 0.0 ? 90.0 : -90.0, + theta*(180./PI)); + return(4); + } n = 0; theta = atan2(yp[2], zp[2]); - if (!FEQ(theta,0.0)) { + if (!FABSEQ(theta,0.0)) { sprintf(xf, " -rx %f", theta*(180./PI)); while (*xf) ++xf; n += 2; } - theta = asin(-xp[2]); - if (!FEQ(theta,0.0)) { + theta = Asin(-xp[2]); + if (!FABSEQ(theta,0.0)) { sprintf(xf, " -ry %f", theta*(180./PI)); while (*xf) ++xf; n += 2; } theta = atan2(xp[1], xp[0]); - if (!FEQ(theta,0.0)) { + if (!FABSEQ(theta,0.0)) { sprintf(xf, " -rz %f", theta*(180./PI)); /* while (*xf) ++xf; */ n += 2;