--- ray/src/gen/gensky.c 1991/08/06 08:22:06 1.5 +++ ray/src/gen/gensky.c 1992/03/10 11:12:06 2.3 @@ -17,7 +17,11 @@ static char SCCSid[] = "$SunId$ LBL"; #include +#include "color.h" +#ifndef atof +extern double atof(); +#endif extern char *strcpy(), *strcat(), *malloc(); extern double stadj(), sdec(), sazi(), salt(); @@ -31,8 +35,9 @@ extern double s_latitude; extern double s_longitude; extern double s_meridian; /* required values */ -int month, day; -double hour; +int month, day; /* date */ +double hour; /* standard time */ +double altitude, azimuth; /* or solar angles */ /* default values */ int cloudy = 0; int dosun = 1; @@ -53,7 +58,7 @@ main(argc, argv) int argc; char *argv[]; { - extern double atof(), fabs(); + extern double fabs(); int i; progname = argv[0]; @@ -63,9 +68,15 @@ char *argv[]; } if (argc < 4) userror("arg count"); - month = atoi(argv[1]); - day = atoi(argv[2]); - hour = atof(argv[3]); + if (!strcmp(argv[1], "-ang")) { + altitude = atof(argv[2]) * (PI/180); + azimuth = atof(argv[3]) * (PI/180); + month = 0; + } else { + month = atoi(argv[1]); + day = atoi(argv[2]); + hour = atof(argv[3]); + } for (i = 4; i < argc; i++) if (argv[i][0] == '-' || argv[i][0] == '+') switch (argv[i][1]) { @@ -116,15 +127,17 @@ char *argv[]; computesky() /* compute sky parameters */ { - int jd; - double sd, st; - double altitude, azimuth; /* compute solar direction */ - jd = jdate(month, day); /* Julian date */ - sd = sdec(jd); /* solar declination */ - st = hour + stadj(jd); /* solar time */ - altitude = salt(sd, st); - azimuth = sazi(sd, st); + if (month) { /* from date and time */ + int jd; + double sd, st; + + jd = jdate(month, day); /* Julian date */ + sd = sdec(jd); /* solar declination */ + st = hour + stadj(jd); /* solar time */ + altitude = salt(sd, st); + azimuth = sazi(sd, st); + } sundir[0] = -sin(azimuth)*cos(altitude); sundir[1] = -cos(azimuth)*cos(altitude); sundir[2] = sin(altitude); @@ -133,10 +146,10 @@ computesky() /* compute sky parameters */ if (zenithbr <= 0.0) if (cloudy) { zenithbr = 8.6*sundir[2] + .123; - zenithbr *= 1000.0*.0064/3.; + zenithbr *= 1000.0/SKYEFFICACY; } else { zenithbr = (1.376*turbidity-1.81)*tan(altitude)+0.38; - zenithbr *= 1000.0*.0064/3.; + zenithbr *= 1000.0/SKYEFFICACY; } if (zenithbr < 0.0) zenithbr = 0.0; @@ -151,9 +164,10 @@ computesky() /* compute sky parameters */ printf("# Ground ambient level: %f\n", groundbr); if (sundir[2] > 0.0) { if (sundir[2] > .16) - solarbr = 2.47e6 - 3.15e5/sundir[2]; + solarbr = (1.5e9/SUNEFFICACY) * + (1.147 - .147/sundir[2]); else - solarbr = 5e5; + solarbr = 1.5e9/SUNEFFICACY*(1.147-.147/.16); groundbr += solarbr*6e-5*sundir[2]/PI; } else dosun = 0; @@ -167,7 +181,7 @@ printsky() /* print out sky */ if (dosun) { printf("\nvoid light solar\n"); printf("0\n0\n"); - printf("3 %f %f %f\n", solarbr, solarbr, solarbr); + printf("3 %.2e %.2e %.2e\n", solarbr, solarbr, solarbr); printf("\nsolar source sun\n"); printf("0\n0\n"); printf("4 %f %f %f 0.5\n", sundir[0], sundir[1], sundir[2]); @@ -177,10 +191,10 @@ printsky() /* print out sky */ printf("2 skybright skybright.cal\n"); printf("0\n"); if (cloudy) - printf("3 1 %f %f\n", zenithbr, groundbr); + printf("3 1 %.2e %.2e\n", zenithbr, groundbr); else - printf("7 -1 %f %f %f %f %f %f\n", zenithbr, groundbr, F2, - sundir[0], sundir[1], sundir[2]); + printf("7 -1 %.2e %.2e %.2e %f %f %f\n", zenithbr, groundbr, + F2, sundir[0], sundir[1], sundir[2]); } @@ -209,6 +223,7 @@ char *msg; if (msg != NULL) fprintf(stderr, "%s: Use error - %s\n", progname, msg); fprintf(stderr, "Usage: %s month day hour [options]\n", progname); + fprintf(stderr, " Or: %s -ang altitude azimuth [options]\n", progname); fprintf(stderr, " Or: %s -defaults\n", progname); exit(1); }