--- ray/src/gen/mkillum2.c 1991/08/22 12:12:23 1.11 +++ ray/src/gen/mkillum2.c 1994/01/07 14:51:46 2.6 @@ -26,8 +26,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 +66,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++) { @@ -88,7 +101,7 @@ char *nm; h = ilhash(dim, 3) + i; multisamp(sp, 2, urand(h)); r1 = (dim[1] + sp[0])/nalt; - r2 = (dim[2] + sp[1])/nazi; + r2 = (dim[2] + sp[1] - .5)/nazi; flatdir(dn, r1, r2); for (j = 0; j < 3; j++) dir[j] = -dn[0]*u[j] - dn[1]*v[j] - dn[2]*fa->norm[j]; @@ -116,10 +129,12 @@ char *nm; } rayflush(rt); /* write out the face and its distribution */ - average(il, distarr, nalt*nazi); - if (il->sampdens > 0) - flatout(il, distarr, nalt, nazi, u, v, fa->norm); - illumout(il, ob); + if (average(il, distarr, nalt*nazi)) { + if (il->sampdens > 0) + flatout(il, distarr, nalt, nazi, u, v, fa->norm); + illumout(il, ob); + } else + printobj(il->altmat, ob); /* clean up */ freeface(ob); free((char *)distarr); @@ -164,7 +179,7 @@ char *nm; multisamp(sp, 4, urand(ilhash(dim,3)+i)); /* random direction */ r1 = (dim[1] + sp[0])/nalt; - r2 = (dim[2] + sp[1])/nazi; + r2 = (dim[2] + sp[1] - .5)/nazi; rounddir(dir, r1, r2); /* random location */ mkaxes(u, v, dir); /* yuck! */ @@ -183,12 +198,14 @@ char *nm; } rayflush(rt); /* write out the sphere and its distribution */ - average(il, distarr, nalt*nazi); - if (il->sampdens > 0) - roundout(il, distarr, nalt, nazi); - else - objerror(ob, WARNING, "diffuse distribution"); - illumout(il, ob); + if (average(il, distarr, nalt*nazi)) { + if (il->sampdens > 0) + roundout(il, distarr, nalt, nazi); + else + objerror(ob, WARNING, "diffuse distribution"); + illumout(il, ob); + } else + printobj(il->altmat, ob); /* clean up */ free((char *)distarr); } @@ -232,7 +249,7 @@ char *nm; multisamp(sp, 4, urand(ilhash(dim,3)+i)); /* random direction */ r1 = (dim[1] + sp[0])/nalt; - r2 = (dim[2] + sp[1])/nalt; + r2 = (dim[2] + sp[1] - .5)/nazi; flatdir(dn, r1, r2); for (j = 0; j < 3; j++) dir[j] = -dn[0]*u[j] - dn[1]*v[j] - dn[2]*co->ad[j]; @@ -243,7 +260,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 */ @@ -251,10 +268,12 @@ char *nm; } rayflush(rt); /* write out the ring and its distribution */ - average(il, distarr, nalt*nazi); - if (il->sampdens > 0) - flatout(il, distarr, nalt, nazi, u, v, co->ad); - illumout(il, ob); + if (average(il, distarr, nalt*nazi)) { + if (il->sampdens > 0) + flatout(il, distarr, nalt, nazi, u, v, co->ad); + illumout(il, ob); + } else + printobj(il->altmat, ob); /* clean up */ freecone(ob); free((char *)distarr); @@ -285,6 +304,7 @@ register struct rtproc *rt; if (rt->nrays <= 0) return; bzero(rt->buf+6*rt->nrays, 6*sizeof(float)); + errno = 0; if ( process(rt->pd, (char *)rt->buf, (char *)rt->buf, 3*sizeof(float)*rt->nrays, 6*sizeof(float)*(rt->nrays+1)) <