ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/gen/genmarble.c
Revision: 2.6
Committed: Sun Jun 8 12:03:09 2003 UTC (21 years, 4 months ago) by schorsch
Content type: text/plain
Branch: MAIN
Changes since 2.5: +5 -3 lines
Log Message:
Reduced compile warnings/errors on Windows.

File Contents

# User Rev Content
1 greg 1.1 #ifndef lint
2 schorsch 2.6 static const char RCSid[] = "$Id: genmarble.c,v 2.5 2003/02/22 02:07:23 greg Exp $";
3 greg 1.1 #endif
4     /*
5     * genmarble.c - generate a marble with bubbles inside.
6     *
7     * 1/8/86
8     */
9    
10     #include <stdio.h>
11    
12 greg 2.5 #include <stdlib.h>
13    
14 greg 2.3 #include <math.h>
15    
16 greg 1.1 #include "random.h"
17    
18     #define PI 3.14159265359
19    
20     typedef double FVECT[3];
21    
22 schorsch 2.6 static double bubble(); /* pretty cute, huh? */
23     static void sphere_cart();
24 greg 2.4
25 greg 1.1
26     main(argc, argv)
27     int argc;
28     char **argv;
29     {
30     char *cmtype, *cname;
31     FVECT cent;
32     double rad;
33     int nbubbles, i;
34     double bubrad;
35     FVECT v;
36     double brad;
37    
38     if (argc != 9) {
39     fprintf(stderr,
40     "Usage: %s material name cent rad #bubbles bubrad\n",
41     argv[0]);
42     exit(1);
43     }
44     cmtype = argv[1];
45     cname = argv[2];
46     cent[0] = atof(argv[3]);
47     cent[1] = atof(argv[4]);
48     cent[2] = atof(argv[5]);
49     rad = atof(argv[6]);
50     nbubbles = atoi(argv[7]);
51     bubrad = atof(argv[8]);
52    
53     if (bubrad >= rad) {
54     fprintf(stderr, "%s: bubbles too big for marble\n", argv[0]);
55     exit(1);
56     }
57    
58     printf("\n%s sphere %s\n", cmtype, cname);
59     printf("0\n0\n4 %f %f %f %f\n", cent[0], cent[1], cent[2], rad);
60    
61     for (i = 0; i < nbubbles; i++) {
62     brad = bubble(v, cent, rad, bubrad);
63     printf("\n%s bubble %s.%d\n", cmtype, cname, i);
64     printf("0\n0\n4 %f %f %f %f\n", v[0], v[1], v[2], brad);
65     }
66    
67     return(0);
68     }
69    
70    
71 schorsch 2.6 static double
72 greg 1.1 bubble(v, cent, rad, bubrad) /* compute location of random bubble */
73     FVECT v, cent;
74     double rad, bubrad;
75     {
76     double r, ro, theta, phi;
77    
78     r = frandom()*bubrad;
79     ro = sqrt(frandom())*(rad-r);
80     theta = frandom()*(2.0*PI);
81     phi = frandom()*PI;
82     sphere_cart(v, ro, theta, phi);
83     v[0] += cent[0]; v[1] += cent[1]; v[2] += cent[2];
84     return(r);
85     }
86    
87    
88 schorsch 2.6 static void
89 greg 1.1 sphere_cart(v, ro, theta, phi) /* spherical to cartesian coord. conversion */
90     FVECT v;
91     double ro, theta, phi;
92     {
93     double d;
94    
95     d = sin(phi);
96     v[0] = ro*d*cos(theta);
97     v[1] = ro*d*sin(theta);
98     v[2] = ro*cos(phi);
99     }