ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/gen/mkillum2.c
(Generate patch)

Comparing ray/src/gen/mkillum2.c (file contents):
Revision 1.3 by greg, Wed Jul 24 13:32:05 1991 UTC vs.
Revision 1.8 by greg, Thu Jul 25 14:43:15 1991 UTC

# Line 5 | Line 5 | static char SCCSid[] = "$SunId$ LBL";
5   #endif
6  
7   /*
8 < * Routines to do the actual calcultion and output for mkillum
8 > * Routines to do the actual calculation for mkillum
9   */
10  
11   #include  "mkillum.h"
# Line 17 | Line 17 | static char SCCSid[] = "$SunId$ LBL";
17   #include  "random.h"
18  
19  
20 printobj(mod, obj)              /* print out an object */
21 char  *mod;
22 register OBJREC  *obj;
23 {
24        register int  i;
25
26        printf("\n%s %s %s", mod, ofun[obj->otype].funame, obj->oname);
27        printf("\n%d", obj->oargs.nsargs);
28        for (i = 0; i < obj->oargs.nsargs; i++)
29                printf(" %s", obj->oargs.sarg[i]);
30 #ifdef  IARGS
31        printf("\n%d", obj->oargs.niargs);
32        for (i = 0; i < obj->oargs.niargs; i++)
33                printf(" %d", obj->oargs.iarg[i]);
34 #else
35        printf("\n0");
36 #endif
37        printf("\n%d", obj->oargs.nfargs);
38        for (i = 0; i < obj->oargs.nfargs; i++) {
39                if (i%3 == 0)
40                        putchar('\n');
41                printf(" %18.12g", obj->oargs.farg[i]);
42        }
43        putchar('\n');
44 }
45
46
20   o_default(ob, il, rt, nm)       /* default illum action */
21   OBJREC  *ob;
22   struct illum_args  *il;
# Line 54 | Line 27 | char  *nm;
27                          nm, ofun[ob->otype].funame, ob->oname);
28          error(WARNING, errmsg);
29          if (!(il->flags & IL_LIGHT))
30 <                printobj(il->altname, ob);
30 >                printobj(il->altmat, ob);
31   }
32  
33  
# Line 69 | Line 42 | char  *nm;
42          int  n, nalt, nazi;
43          float  *distarr;
44          double  r1, r2;
45 <        FVECT  dn, pos, dir;
45 >        FVECT  dn, org, dir;
46          FVECT  u, v;
47          double  ur[2], vr[2];
48          int  nmisses;
# Line 111 | Line 84 | char  *nm;
84                      dim[3] = 1;
85                      r1 = (dim[1]+urand(urind(ilhash(dim,4),i)))/nalt;
86                      dim[3] = 2;
87 <                    r2 = (dim[2]+urand(urind(ilhash(dim,4),i)))/nalt;
87 >                    r2 = (dim[2]+urand(urind(ilhash(dim,4),i)))/nazi;
88                      flatdir(dn, r1, r2);
89                      for (j = 0; j < 3; j++)
90 <                        dir[j] = dn[0]*u[j] + dn[1]*v[j] - dn[2]*fa->norm[j];
90 >                        dir[j] = -dn[0]*u[j] - dn[1]*v[j] - dn[2]*fa->norm[j];
91                                          /* random location */
92                      do {
93                          dim[3] = 3;
94 <                        r1 = ur[0] +
95 <                                (ur[1]-ur[0])*urand(urind(ilhash(dim,4),i));
94 >                        r1 = ur[0] + (ur[1]-ur[0]) *
95 >                                        urand(urind(ilhash(dim,4),i+nmisses));
96                          dim[3] = 4;
97 <                        r2 = vr[0] +
98 <                                (vr[1]-vr[0])*urand(urind(ilhash(dim,4),i));
97 >                        r2 = vr[0] + (vr[1]-vr[0]) *
98 >                                        urand(urind(ilhash(dim,4),i+nmisses));
99                          for (j = 0; j < 3; j++)
100                              org[j] = r1*u[j] + r2*v[j]
101                                          + fa->offset*fa->norm[j];
# Line 138 | Line 111 | char  *nm;
111                      for (j = 0; j < 3; j++)
112                          org[j] += .001*fa->norm[j];
113                                          /* send sample */
114 <                    raysamp(distarr+dim[1]*nazi+dim[2], org, dir, rt);
114 >                    raysamp(distarr+3*(dim[1]*nazi+dim[2]), org, dir, rt);
115                  }
116          rayflush(rt);
117 <                                /* write out the distribution */
118 <        flatdist(distarr, nalt, nazi, il, ob);
117 >                                /* write out the face w/ distribution */
118 >        flatout(il, distarr, nalt, nazi, u, v, fa->norm);
119 >        illumout(il, ob);
120                                  /* clean up */
121          freeface(ob);
122          free((char *)distarr);
# Line 159 | Line 133 | char  *nm;
133          int  dim[4];
134          int  n, nalt, nazi;
135          float  *distarr;
136 <        double  r1, r2;
137 <        FVECT  pos, dir;
136 >        double  r1, r2, r3;
137 >        FVECT  org, dir;
138          FVECT  u, v;
139          register int  i, j;
140                                  /* check arguments */
# Line 183 | Line 157 | char  *nm;
157                      dim[3] = 1;
158                      r1 = (dim[1]+urand(urind(ilhash(dim,4),i)))/nalt;
159                      dim[3] = 2;
160 <                    r2 = (dim[2]+urand(urind(ilhash(dim,4),i)))/nalt;
160 >                    r2 = (dim[2]+urand(urind(ilhash(dim,4),i)))/nazi;
161                      rounddir(dir, r1, r2);
162                                          /* random location */
163                      mkaxes(u, v, dir);          /* yuck! */
164                      dim[3] = 3;
165 <                    r1 = sqrt(urand(urind(ilhash(dim,4),i)));
165 >                    r3 = sqrt(urand(urind(ilhash(dim,4),i)));
166                      dim[3] = 4;
167                      r2 = 2.*PI*urand(urind(ilhash(dim,4),i));
168 <                    for (j = 0; j < 3; j++)
169 <                        org[j] = obj->oargs.farg[j] + obj->oargs.farg[3] *
170 <                                        ( r1*cos(r2)*u[j] + r1*sin(r2)*v[j]
171 <                                                - sqrt(1.01-r1*r1)*dir[j] );
172 <
168 >                    r1 = r3*ob->oargs.farg[3]*cos(r2);
169 >                    r2 = r3*ob->oargs.farg[3]*sin(r2);
170 >                    r3 = ob->oargs.farg[3]*sqrt(1.01-r3*r3);
171 >                    for (j = 0; j < 3; j++) {
172 >                        org[j] = ob->oargs.farg[j] + r1*u[j] + r2*v[j] +
173 >                                        r3*dir[j];
174 >                        dir[j] = -dir[j];
175 >                    }
176                                          /* send sample */
177 <                    raysamp(distarr+dim[1]*nazi+dim[2], org, dir, rt);
177 >                    raysamp(distarr+3*(dim[1]*nazi+dim[2]), org, dir, rt);
178                  }
179          rayflush(rt);
180 <                                /* write out the distribution */
181 <        rounddist(distarr, nalt, nazi, il, ob);
180 >                                /* write out the sphere w/ distribution */
181 >        roundout(il, distarr, nalt, nazi);
182 >        illumout(il, ob);
183                                  /* clean up */
184          free((char *)distarr);
185   }
# Line 216 | Line 194 | char  *nm;
194          int  dim[4];
195          int  n, nalt, nazi;
196          float  *distarr;
197 <        double  r1, r2;
198 <        FVECT  dn, pos, dir;
197 >        double  r1, r2, r3;
198 >        FVECT  dn, org, dir;
199          FVECT  u, v;
200          register CONE  *co;
201          register int  i, j;
# Line 244 | Line 222 | char  *nm;
222                      r2 = (dim[2]+urand(urind(ilhash(dim,4),i)))/nalt;
223                      flatdir(dn, r1, r2);
224                      for (j = 0; j < 3; j++)
225 <                        dir[j] = dn[0]*u[j] + dn[1]*v[j] - dn[2]*co->ad[j];
225 >                        dir[j] = -dn[0]*u[j] - dn[1]*v[j] - dn[2]*co->ad[j];
226                                          /* random location */
227                      dim[3] = 3;
228 <                    r1 = sqrt(CO_R0(co)*CO_R0(co) +
228 >                    r3 = sqrt(CO_R0(co)*CO_R0(co) +
229                                  urand(urind(ilhash(dim,4),i))*
230                                  (CO_R1(co)*CO_R1(co) - CO_R0(co)*CO_R0(co)));
231                      dim[3] = 4;
232                      r2 = 2.*PI*urand(urind(ilhash(dim,4),i));
233 +                    r1 = r3*cos(r2);
234 +                    r2 = r3*sin(r2);
235                      for (j = 0; j < 3; j++)
236 <                        org[j] = CO_P0(co)[j] +
237 <                                        r1*cos(r2)*u[j] + r1*sin(r2)*v[j]
258 <                                        + .001*co->ad[j];
236 >                        org[j] = CO_P0(co)[j] + r1*u[j] + r1*v[j] +
237 >                                        .001*co->ad[j];
238  
239                                          /* send sample */
240 <                    raysamp(distarr+dim[1]*nazi+dim[2], org, dir, rt);
240 >                    raysamp(distarr+3*(dim[1]*nazi+dim[2]), org, dir, rt);
241                  }
242          rayflush(rt);
243 <                                /* write out the distribution */
244 <        flatdist(distarr, nalt, nazi, il, ob);
243 >                                /* write out the ring w/ distribution */
244 >        flatout(il, distarr, nalt, nazi, u, v, co->ad);
245 >        illumout(il, ob);
246                                  /* clean up */
247          freecone(ob);
248          free((char *)distarr);
# Line 306 | Line 286 | register struct rtproc  *rt;
286                  rt->dest[i][2] += rt->buf[3*i+2];
287          }
288          rt->nrays = 0;
289 + }
290 +
291 +
292 + mkaxes(u, v, n)                 /* compute u and v to go with n */
293 + FVECT  u, v, n;
294 + {
295 +        register int  i;
296 +
297 +        v[0] = v[1] = v[2] = 0.0;
298 +        for (i = 0; i < 3; i++)
299 +                if (n[i] < 0.6 && n[i] > -0.6)
300 +                        break;
301 +        v[i] = 1.0;
302 +        fcross(u, v, n);
303 +        normalize(u);
304 +        fcross(v, n, u);
305 + }
306 +
307 +
308 + rounddir(dv, alt, azi)          /* compute uniform spherical direction */
309 + register FVECT  dv;
310 + double  alt, azi;
311 + {
312 +        double  d1, d2;
313 +
314 +        dv[2] = 1. - 2.*alt;
315 +        d1 = sqrt(1. - dv[2]*dv[2]);
316 +        d2 = 2.*PI * azi;
317 +        dv[0] = d1*cos(d2);
318 +        dv[1] = d1*sin(d2);
319 + }
320 +
321 +
322 + flatdir(dv, alt, azi)           /* compute uniform hemispherical direction */
323 + register FVECT  dv;
324 + double  alt, azi;
325 + {
326 +        double  d1, d2;
327 +
328 +        d1 = sqrt(alt);
329 +        d2 = 2.*PI * azi;
330 +        dv[0] = d1*cos(d2);
331 +        dv[1] = d1*sin(d2);
332 +        dv[2] = sqrt(1. - alt);
333   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines