ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/gen/genclock.c
Revision: 2.5
Committed: Sun Jun 8 12:03:09 2003 UTC (21 years, 4 months ago) by schorsch
Content type: text/plain
Branch: MAIN
CVS Tags: rad5R4, rad5R2, rad4R2P2, rad5R0, rad5R1, rad3R7P2, rad3R7P1, rad4R2, rad4R1, rad4R0, rad3R6, rad3R6P1, rad3R8, rad3R9, rad4R2P1, rad5R3, HEAD
Changes since 2.4: +66 -60 lines
Log Message:
Reduced compile warnings/errors on Windows.

File Contents

# Content
1 #ifndef lint
2 static const char RCSid[] = "$Id: genclock.c,v 2.4 2003/02/22 02:07:23 greg Exp $";
3 #endif
4 /*
5 * Generate an analog clock.
6 */
7
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <math.h>
11 #include <ctype.h>
12
13 #define PI 3.14159265358979323846
14
15 #define FACEBITMAP "clockface.hex"
16
17 char myfacemat[] = "white_plastic";
18 double myfacearg[5] = {.85,.85,.85,0,0};
19 char mycasemat[] = "black_plastic";
20 double mycasearg[5] = {.08,.08,.08,.03,.04};
21 char *facemat = myfacemat;
22 char *casemat = mycasemat;
23 char *name = "clock";
24
25 static void
26 genmats() /* put out our materials */
27 {
28 if (facemat == myfacemat)
29 printf("\nvoid plastic %s\n0\n0\n5 %f %f %f %f %f\n",
30 myfacemat, myfacearg[0], myfacearg[1],
31 myfacearg[2], myfacearg[3], myfacearg[4]);
32 if (casemat == mycasemat)
33 printf("\nvoid plastic %s\n0\n0\n5 %f %f %f %f %f\n",
34 mycasemat, mycasearg[0], mycasearg[1],
35 mycasearg[2], mycasearg[3], mycasearg[4]);
36 printf("\n%s brighttext clock_face_paint\n2 hexbit4x1.fnt %s\n",
37 facemat, FACEBITMAP);
38 printf("0\n11\n\t0\t-1\t1\n\t0\t.0185\t0\n\t0\t0\t-.00463\n");
39 printf("\t.02\t1\n");
40 printf("\nvoid glass clock_crystal\n0\n0\n3 .95 .95 .95\n");
41 printf("\nvoid plastic hand_paint\n0\n0\n5 .03 .03 .03 0 0\n");
42 }
43
44
45 static void
46 genclock() /* put out clock body */
47 {
48 printf("\n%s ring %s.case_back\n", casemat, name);
49 printf("0\n0\n8\t0\t0\t0\n\t-1\t0\t0\n\t0\t1.1\n");
50 printf("\n%s cylinder %s.case_outer\n", casemat, name);
51 printf("0\n0\n7\t0\t0\t0\n\t.12\t0\t0\n\t1.1\n");
52 printf("\n%s ring %s.case_front\n", casemat, name);
53 printf("0\n0\n8\t.12\t0\t0\n\t1\t0\t0\n\t1\t1.1\n");
54 printf("\n%s cylinder %s.case_inner\n", casemat, name);
55 printf("0\n0\n7\t.05\t0\t0\n\t.12\t0\t0\n\t1\n");
56 printf("\nclock_crystal ring %s.crystal\n", name);
57 printf("0\n0\n8\t.10\t0\t0\n\t1\t0\t0\n\t0\t1\n");
58 printf("\nclock_face_paint ring %s.face\n", name);
59 printf("0\n0\n8\t.05\t0\t0\n\t1\t0\t0\n\t0\t1\n");
60 }
61
62
63 static void
64 rvert(x, y, z, ang) /* print rotated vertex */
65 double x, y, z, ang;
66 {
67 static double lastang=0, sa=0, ca=1;
68
69 if (ang != lastang) {
70 sa = sin(-ang);
71 ca = cos(-ang);
72 lastang = ang;
73 }
74 printf("%15.12g %15.12g %15.12g\n", x, y*ca-z*sa, z*ca+y*sa);
75 }
76
77
78 static void
79 genhands(hour) /* generate correct hand positions */
80 double hour;
81 {
82 double hrot, mrot;
83
84 hrot = 2.*PI/12. * hour;
85 mrot = 2.*PI * (hour - floor(hour));
86
87 printf("\nhand_paint polygon %s.hour_hand\n", name);
88 printf("0\n0\n12\n");
89 rvert(.06, -.03, -.06, hrot);
90 rvert(.06, .03, -.06, hrot);
91 rvert(.06, .025, .5, hrot);
92 rvert(.06, -.025, .5, hrot);
93
94 printf("\nhand_paint polygon %s.minute_hand\n", name);
95 printf("0\n0\n12\n");
96 rvert(.07, -.02, -.1, mrot);
97 rvert(.07, .02, -.1, mrot);
98 rvert(.07, .01, .9, mrot);
99 rvert(.07, -.01, .9, mrot);
100 }
101
102
103 int
104 main(argc, argv)
105 int argc;
106 char *argv[];
107 {
108 int i, j;
109 double hour;
110
111 for (i = 1; i < argc && argv[i][0] == '-'; i++)
112 switch (argv[i][1]) {
113 case 'f':
114 facemat = argv[++i];
115 break;
116 case 'c':
117 casemat = argv[++i];
118 break;
119 case 'n':
120 name = argv[++i];
121 break;
122 default:
123 goto userr;
124 }
125 if (i >= argc)
126 goto userr;
127 if (!isdigit(argv[i][0]))
128 goto userr;
129 for (j = 1; isdigit(argv[i][j]); j++)
130 ;
131 if (argv[i][j] == ':')
132 hour = atoi(argv[i]) + atoi(argv[i]+j+1)/60.0;
133 else if (!argv[i][j] || argv[i][j] == '.')
134 hour = atof(argv[i]);
135 else
136 goto userr;
137 putchar('#'); /* print header */
138 for (i = 0; i < argc; i++) {
139 putchar(' ');
140 fputs(argv[i], stdout);
141 }
142 putchar('\n');
143 genmats(); /* print materials */
144 genclock(); /* generate clock */
145 genhands(hour); /* generate hands */
146 exit(0);
147 userr:
148 fputs("Usage: ", stderr);
149 fputs(argv[0], stderr);
150 fputs(" [-f face_mat][-c case_mat][-n name] {HH:MM | HH.hh}\n", stderr);
151 exit(1);
152 }
153