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.13 by greg, Mon Aug 26 10:16:56 1991 UTC vs.
Revision 2.9 by greg, Sat Feb 22 02:07:24 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1991 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   * Routines to do the actual calculation for mkillum
6   */
# Line 26 | Line 23 | char  *nm;
23          sprintf(errmsg, "(%s): cannot make illum for %s \"%s\"",
24                          nm, ofun[ob->otype].funame, ob->oname);
25          error(WARNING, errmsg);
26 <        if (!(il->flags & IL_LIGHT))
30 <                printobj(il->altmat, ob);
26 >        printobj(il->altmat, ob);
27   }
28  
29  
# Line 67 | Line 63 | char  *nm;
63          distarr = (float *)calloc(n, 3*sizeof(float));
64          if (distarr == NULL)
65                  error(SYSTEM, "out of memory in o_face");
66 <        mkaxes(u, v, fa->norm);
66 >                                /* take first edge longer than sqrt(area) */
67 >        for (j = fa->nv-1, i = 0; i < fa->nv; j = i++) {
68 >                u[0] = VERTEX(fa,i)[0] - VERTEX(fa,j)[0];
69 >                u[1] = VERTEX(fa,i)[1] - VERTEX(fa,j)[1];
70 >                u[2] = VERTEX(fa,i)[2] - VERTEX(fa,j)[2];
71 >                if ((r1 = DOT(u,u)) >= fa->area-FTINY)
72 >                        break;
73 >        }
74 >        if (i < fa->nv) {       /* got one! -- let's align our axes */
75 >                r2 = 1.0/sqrt(r1);
76 >                u[0] *= r2; u[1] *= r2; u[2] *= r2;
77 >                fcross(v, fa->norm, u);
78 >        } else                  /* oh well, we'll just have to wing it */
79 >                mkaxes(u, v, fa->norm);
80 >                                /* now, find limits in (u,v) coordinates */
81          ur[0] = vr[0] = FHUGE;
82          ur[1] = vr[1] = -FHUGE;
83          for (i = 0; i < fa->nv; i++) {
# Line 105 | Line 115 | char  *nm;
115                          objerror(ob, WARNING, "bad aspect");
116                          rt->nrays = 0;
117                          freeface(ob);
118 <                        free((char *)distarr);
118 >                        free((void *)distarr);
119                          o_default(ob, il, rt, nm);
120                          return;
121                      }
# Line 120 | Line 130 | char  *nm;
130                  if (il->sampdens > 0)
131                          flatout(il, distarr, nalt, nazi, u, v, fa->norm);
132                  illumout(il, ob);
133 <        } else if (!(il->flags & IL_LIGHT))
133 >        } else
134                  printobj(il->altmat, ob);
135                                  /* clean up */
136          freeface(ob);
137 <        free((char *)distarr);
137 >        free((void *)distarr);
138   #undef MAXMISS
139   }
140  
# Line 150 | Line 160 | char  *nm;
160                  nalt = nazi = 1;
161          else {
162                  n = 4.*PI * il->sampdens;
163 <                nalt = sqrt(n/PI) + .5;
164 <                nazi = PI*nalt + .5;
163 >                nalt = sqrt(2./PI*n) + .5;
164 >                nazi = PI/2.*nalt + .5;
165          }
166          n = nalt*nazi;
167          distarr = (float *)calloc(n, 3*sizeof(float));
# Line 191 | Line 201 | char  *nm;
201                  else
202                          objerror(ob, WARNING, "diffuse distribution");
203                  illumout(il, ob);
204 <        } else if (!(il->flags & IL_LIGHT))
204 >        } else
205                  printobj(il->altmat, ob);
206                                  /* clean up */
207 <        free((char *)distarr);
207 >        free((void *)distarr);
208   }
209  
210  
# Line 247 | Line 257 | char  *nm;
257                      r1 = r3*cos(r2);
258                      r2 = r3*sin(r2);
259                      for (j = 0; j < 3; j++)
260 <                        org[j] = CO_P0(co)[j] + r1*u[j] + r1*v[j] +
260 >                        org[j] = CO_P0(co)[j] + r1*u[j] + r2*v[j] +
261                                          .001*co->ad[j];
262  
263                                          /* send sample */
# Line 259 | Line 269 | char  *nm;
269                  if (il->sampdens > 0)
270                          flatout(il, distarr, nalt, nazi, u, v, co->ad);
271                  illumout(il, ob);
272 <        } else if (!(il->flags & IL_LIGHT))
272 >        } else
273                  printobj(il->altmat, ob);
274                                  /* clean up */
275          freecone(ob);
276 <        free((char *)distarr);
276 >        free((void *)distarr);
277   }
278  
279  
# Line 291 | Line 301 | register struct rtproc  *rt;
301          if (rt->nrays <= 0)
302                  return;
303          bzero(rt->buf+6*rt->nrays, 6*sizeof(float));
304 +        errno = 0;
305          if ( process(rt->pd, (char *)rt->buf, (char *)rt->buf,
306 <                        3*sizeof(float)*rt->nrays,
306 >                        3*sizeof(float)*(rt->nrays+1),
307                          6*sizeof(float)*(rt->nrays+1)) <
308 <                        3*sizeof(float)*rt->nrays )
308 >                        3*sizeof(float)*(rt->nrays+1) )
309                  error(SYSTEM, "error reading from rtrace process");
310          i = rt->nrays;
311          while (i--) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines