--- ray/src/gen/mkillum2.c 1991/11/12 17:05:11 2.1 +++ ray/src/gen/mkillum2.c 2003/06/30 14:59:11 2.11 @@ -1,19 +1,15 @@ -/* Copyright (c) 1991 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: mkillum2.c,v 2.11 2003/06/30 14:59:11 schorsch Exp $"; #endif - /* * Routines to do the actual calculation for mkillum */ -#include "mkillum.h" +#include +#include "mkillum.h" #include "face.h" - #include "cone.h" - #include "random.h" @@ -26,8 +22,7 @@ char *nm; sprintf(errmsg, "(%s): cannot make illum for %s \"%s\"", nm, ofun[ob->otype].funame, ob->oname); error(WARNING, errmsg); - if (!(il->flags & IL_LIGHT)) - printobj(il->altmat, ob); + printobj(il->altmat, ob); } @@ -67,7 +62,21 @@ char *nm; distarr = (float *)calloc(n, 3*sizeof(float)); if (distarr == NULL) error(SYSTEM, "out of memory in o_face"); - mkaxes(u, v, fa->norm); + /* take first edge longer than sqrt(area) */ + for (j = fa->nv-1, i = 0; i < fa->nv; j = i++) { + u[0] = VERTEX(fa,i)[0] - VERTEX(fa,j)[0]; + u[1] = VERTEX(fa,i)[1] - VERTEX(fa,j)[1]; + u[2] = VERTEX(fa,i)[2] - VERTEX(fa,j)[2]; + if ((r1 = DOT(u,u)) >= fa->area-FTINY) + break; + } + if (i < fa->nv) { /* got one! -- let's align our axes */ + r2 = 1.0/sqrt(r1); + u[0] *= r2; u[1] *= r2; u[2] *= r2; + fcross(v, fa->norm, u); + } else /* oh well, we'll just have to wing it */ + mkaxes(u, v, fa->norm); + /* now, find limits in (u,v) coordinates */ ur[0] = vr[0] = FHUGE; ur[1] = vr[1] = -FHUGE; for (i = 0; i < fa->nv; i++) { @@ -105,7 +114,7 @@ char *nm; objerror(ob, WARNING, "bad aspect"); rt->nrays = 0; freeface(ob); - free((char *)distarr); + free((void *)distarr); o_default(ob, il, rt, nm); return; } @@ -120,11 +129,11 @@ char *nm; if (il->sampdens > 0) flatout(il, distarr, nalt, nazi, u, v, fa->norm); illumout(il, ob); - } else if (!(il->flags & IL_LIGHT)) + } else printobj(il->altmat, ob); /* clean up */ freeface(ob); - free((char *)distarr); + free((void *)distarr); #undef MAXMISS } @@ -150,8 +159,8 @@ char *nm; nalt = nazi = 1; else { n = 4.*PI * il->sampdens; - nalt = sqrt(n/PI) + .5; - nazi = PI*nalt + .5; + nalt = sqrt(2./PI*n) + .5; + nazi = PI/2.*nalt + .5; } n = nalt*nazi; distarr = (float *)calloc(n, 3*sizeof(float)); @@ -191,10 +200,10 @@ char *nm; else objerror(ob, WARNING, "diffuse distribution"); illumout(il, ob); - } else if (!(il->flags & IL_LIGHT)) + } else printobj(il->altmat, ob); /* clean up */ - free((char *)distarr); + free((void *)distarr); } @@ -247,7 +256,7 @@ char *nm; r1 = r3*cos(r2); r2 = r3*sin(r2); for (j = 0; j < 3; j++) - org[j] = CO_P0(co)[j] + r1*u[j] + r1*v[j] + + org[j] = CO_P0(co)[j] + r1*u[j] + r2*v[j] + .001*co->ad[j]; /* send sample */ @@ -259,11 +268,11 @@ char *nm; if (il->sampdens > 0) flatout(il, distarr, nalt, nazi, u, v, co->ad); illumout(il, ob); - } else if (!(il->flags & IL_LIGHT)) + } else printobj(il->altmat, ob); /* clean up */ freecone(ob); - free((char *)distarr); + free((void *)distarr); } @@ -290,12 +299,12 @@ register struct rtproc *rt; if (rt->nrays <= 0) return; - bzero(rt->buf+6*rt->nrays, 6*sizeof(float)); + memset(rt->buf+6*rt->nrays, '\0', 6*sizeof(float)); errno = 0; - if ( process(rt->pd, (char *)rt->buf, (char *)rt->buf, - 3*sizeof(float)*rt->nrays, + if ( process(&(rt->pd), (char *)rt->buf, (char *)rt->buf, + 3*sizeof(float)*(rt->nrays+1), 6*sizeof(float)*(rt->nrays+1)) < - 3*sizeof(float)*rt->nrays ) + 3*sizeof(float)*(rt->nrays+1) ) error(SYSTEM, "error reading from rtrace process"); i = rt->nrays; while (i--) {