--- ray/src/gen/replmarks.c 2004/01/29 22:20:31 2.11 +++ ray/src/gen/replmarks.c 2014/03/06 00:47:37 2.16 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id"; +static const char RCSid[] = "$Id: replmarks.c,v 2.16 2014/03/06 00:47:37 greg Exp $"; #endif /* * Replace markers in Radiance scene description with objects or instances. @@ -26,7 +26,7 @@ static const char RCSid[] = "$Id"; #define FEQ(a,b) ((a)-(b) <= 1e-7 && (b)-(a) <= 1e-7) #define MAXVERT 6 /* maximum number of vertices for markers */ -#define MAXMARK 32 /* maximum number of markers */ +#define MAXMARK 128 /* maximum number of markers */ #define USE_XFORM 1 /* use !xform inline command */ #define USE_INSTANCE 2 /* use instance primitive */ @@ -43,7 +43,7 @@ struct mrkr { char *modin; /* input modifier indicating marker */ char *objname; /* output object file or octree */ int usetype; /* one of USE_* above */ -} marker[MAXMARK]; /* array of markers */ +} marker[MAXMARK+1]; /* array of markers */ int nmarkers = 0; /* number of markers */ int expand; /* expand commands? */ @@ -102,9 +102,11 @@ main( } while (argv[i][0] == '-'); if (marker[nmarkers].objname == NULL) goto userr; + if (nmarkers >= MAXMARK) { + fprintf(stderr, "%s: too many markers\n", progname); + return 1; + } marker[nmarkers++].modin = argv[i++]; - if (nmarkers >= MAXMARK) - break; marker[nmarkers].mscale = marker[nmarkers-1].mscale; } if (nmarkers == 0) @@ -200,7 +202,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++) @@ -208,11 +212,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 */ @@ -385,6 +391,14 @@ 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)) { @@ -392,7 +406,7 @@ addrot( /* compute rotation (x,y,z) => (xp,yp,zp) */ while (*xf) ++xf; n += 2; } - theta = asin(-xp[2]); + theta = Asin(-xp[2]); if (!FEQ(theta,0.0)) { sprintf(xf, " -ry %f", theta*(180./PI)); while (*xf) ++xf;