27 |
|
|
28 |
|
initstypes() /* initialize source dispatch table */ |
29 |
|
{ |
30 |
< |
extern VSMATERIAL mirror_vs; |
30 |
> |
extern VSMATERIAL mirror_vs, direct1_vs, direct2_vs; |
31 |
|
extern int fsetsrc(), ssetsrc(), sphsetsrc(), rsetsrc(); |
32 |
|
extern double fgetplaneq(), rgetplaneq(); |
33 |
|
extern double fgetmaxdisk(), rgetmaxdisk(); |
37 |
|
static SOBJECT rsobj = {rsetsrc, rgetplaneq, rgetmaxdisk}; |
38 |
|
|
39 |
|
sfun[MAT_MIRROR].mf = &mirror_vs; |
40 |
+ |
sfun[MAT_DIRECT1].mf = &direct1_vs; |
41 |
+ |
sfun[MAT_DIRECT2].mf = &direct2_vs; |
42 |
|
sfun[OBJ_FACE].of = &fsobj; |
43 |
|
sfun[OBJ_SOURCE].of = &ssobj; |
44 |
|
sfun[OBJ_SPHERE].of = &sphsobj; |
107 |
|
theta = PI/180.0/2.0 * so->oargs.farg[3]; |
108 |
|
if (theta <= FTINY) |
109 |
|
objerror(so, USER, "zero size"); |
110 |
< |
src->ss = theta >= PI/4 ? 1.0 : tan(theta); |
110 |
> |
src->ss = theta >= PI/4.0 ? 1.0 : tan(theta); |
111 |
|
src->ss2 = 2.0*PI * (1.0 - cos(theta)); |
112 |
|
} |
113 |
|
|
290 |
|
|
291 |
|
d = DOT(sp->aim, nrm); |
292 |
|
if (d > FTINY) /* center in front? */ |
293 |
< |
return(0); |
293 |
> |
return(1); |
294 |
|
/* else check horizon */ |
295 |
|
d1 = 1. - sp->siz/(2.*PI); |
296 |
< |
return(1.-FTINY-d*d > d1*d1); |
296 |
> |
return(1.-FTINY-d*d < d1*d1); |
297 |
|
} |
298 |
|
|
299 |
|
|
300 |
|
double |
301 |
+ |
spotdisk(oc, op, sp, pos) /* intersect spot with object op */ |
302 |
+ |
FVECT oc; |
303 |
+ |
OBJREC *op; |
304 |
+ |
register SPOT *sp; |
305 |
+ |
FVECT pos; |
306 |
+ |
{ |
307 |
+ |
FVECT onorm; |
308 |
+ |
double offs, d, dist; |
309 |
+ |
register int i; |
310 |
+ |
|
311 |
+ |
offs = getplaneq(onorm, op); |
312 |
+ |
d = -DOT(onorm, sp->aim); |
313 |
+ |
if (d >= -FTINY && d <= FTINY) |
314 |
+ |
return(0.); |
315 |
+ |
dist = (DOT(pos, onorm) - offs)/d; |
316 |
+ |
if (dist < 0.) |
317 |
+ |
return(0.); |
318 |
+ |
for (i = 0; i < 3; i++) |
319 |
+ |
oc[i] = pos[i] + dist*sp->aim[i]; |
320 |
+ |
return(sp->siz*dist*dist/PI/(d*d)); |
321 |
+ |
} |
322 |
+ |
|
323 |
+ |
|
324 |
+ |
double |
325 |
+ |
beamdisk(oc, op, sp, dir) /* intersect beam with object op */ |
326 |
+ |
FVECT oc; |
327 |
+ |
OBJREC *op; |
328 |
+ |
register SPOT *sp; |
329 |
+ |
FVECT dir; |
330 |
+ |
{ |
331 |
+ |
FVECT onorm; |
332 |
+ |
double offs, d, dist; |
333 |
+ |
register int i; |
334 |
+ |
|
335 |
+ |
offs = getplaneq(onorm, op); |
336 |
+ |
d = -DOT(onorm, dir); |
337 |
+ |
if (d >= -FTINY && d <= FTINY) |
338 |
+ |
return(0.); |
339 |
+ |
dist = (DOT(sp->aim, onorm) - offs)/d; |
340 |
+ |
for (i = 0; i < 3; i++) |
341 |
+ |
oc[i] = sp->aim[i] + dist*dir[i]; |
342 |
+ |
return(sp->siz/PI/(d*d)); |
343 |
+ |
} |
344 |
+ |
|
345 |
+ |
|
346 |
+ |
double |
347 |
|
intercircle(cc, c1, c2, r1s, r2s) /* intersect two circles */ |
348 |
|
FVECT cc; /* midpoint (return value) */ |
349 |
|
FVECT c1, c2; /* circle centers */ |
392 |
|
first = 0; last = nsources-1; |
393 |
|
} |
394 |
|
for (i = first; i <= last; i++) |
395 |
< |
if (source[i].sflags & SDISTANT) |
395 |
> |
if ((source[i].sflags & (SDISTANT|SVIRTUAL)) == SDISTANT) |
396 |
|
/* |
397 |
|
* Check to see if ray is within |
398 |
|
* solid angle of source. |
415 |
|
} |
416 |
|
|
417 |
|
|
418 |
< |
#define wrongsource(m, r) (m->otype!=MAT_ILLUM && \ |
419 |
< |
r->rsrc>=0 && \ |
420 |
< |
source[r->rsrc].so!=r->ro) |
418 |
> |
#define wrongsource(m, r) (r->rsrc>=0 && \ |
419 |
> |
source[r->rsrc].so!=r->ro && \ |
420 |
> |
(m->otype!=MAT_ILLUM || \ |
421 |
> |
objptr(source[r->rsrc].so->omod)->otype==MAT_ILLUM)) |
422 |
|
|
423 |
+ |
#define distglow(m, r) (m->otype==MAT_GLOW && \ |
424 |
+ |
r->rot > m->oargs.farg[3]) |
425 |
+ |
|
426 |
|
#define badambient(m, r) ((r->crtype&(AMBIENT|SHADOW))==AMBIENT && \ |
427 |
< |
!(m->otype==MAT_GLOW&&r->rot>m->oargs.farg[3])) |
427 |
> |
!distglow(m, r)) |
428 |
|
|
429 |
|
#define passillum(m, r) (m->otype==MAT_ILLUM && \ |
430 |
|
!(r->rsrc>=0&&source[r->rsrc].so==r->ro)) |
431 |
|
|
432 |
+ |
#define srcignore(m, r) (directinvis && !(r->crtype&SHADOW) && \ |
433 |
+ |
!distglow(m, r)) |
434 |
|
|
435 |
+ |
|
436 |
|
m_light(m, r) /* ray hit a light source */ |
437 |
|
register OBJREC *m; |
438 |
|
register RAY *r; |
442 |
|
return; |
443 |
|
/* check for passed illum */ |
444 |
|
if (passillum(m, r)) { |
390 |
– |
|
445 |
|
if (m->oargs.nsargs < 1 || !strcmp(m->oargs.sarg[0], VOIDID)) |
446 |
|
raytrans(r); |
447 |
|
else |
448 |
|
rayshade(r, modifier(m->oargs.sarg[0])); |
449 |
< |
|
450 |
< |
/* otherwise treat as source */ |
451 |
< |
} else { |
449 |
> |
return; |
450 |
> |
} |
451 |
> |
/* otherwise treat as source */ |
452 |
|
/* check for behind */ |
453 |
< |
if (r->rod < 0.0) |
454 |
< |
return; |
453 |
> |
if (r->rod < 0.0) |
454 |
> |
return; |
455 |
> |
/* check for invisibility */ |
456 |
> |
if (srcignore(m, r)) |
457 |
> |
return; |
458 |
|
/* get distribution pattern */ |
459 |
< |
raytexture(r, m->omod); |
459 |
> |
raytexture(r, m->omod); |
460 |
|
/* get source color */ |
461 |
< |
setcolor(r->rcol, m->oargs.farg[0], |
462 |
< |
m->oargs.farg[1], |
463 |
< |
m->oargs.farg[2]); |
461 |
> |
setcolor(r->rcol, m->oargs.farg[0], |
462 |
> |
m->oargs.farg[1], |
463 |
> |
m->oargs.farg[2]); |
464 |
|
/* modify value */ |
465 |
< |
multcolor(r->rcol, r->pcol); |
409 |
< |
} |
465 |
> |
multcolor(r->rcol, r->pcol); |
466 |
|
} |