| 9 |
|
*/ |
| 10 |
|
|
| 11 |
|
#include <stdio.h> |
| 12 |
+ |
#include <math.h> |
| 13 |
|
#include <string.h> |
| 14 |
|
#include "fvect.h" |
| 15 |
|
#include "object.h" |
| 18 |
|
|
| 19 |
|
#define PI 3.14159265358979323846 |
| 20 |
|
|
| 21 |
+ |
#define C_1SIDEDTHICK 0.005 |
| 22 |
+ |
|
| 23 |
|
int o_face(), o_cone(), o_sphere(), o_ring(), o_cylinder(); |
| 24 |
|
int o_instance(), o_source(), o_illum(); |
| 25 |
< |
int o_plastic(), o_metal(), o_glass(), o_mirror(), o_trans(), o_light(); |
| 25 |
> |
int o_plastic(), o_metal(), o_glass(), o_dielectric(), |
| 26 |
> |
o_mirror(), o_trans(), o_light(); |
| 27 |
|
|
| 28 |
|
extern void free(); |
| 29 |
|
extern char *malloc(); |
| 43 |
|
* Stuff for tracking and reusing vertices: |
| 44 |
|
*/ |
| 45 |
|
|
| 46 |
< |
char VKFMT[] = "%+1.9e %+1.9e %+1.9e"; |
| 46 |
> |
char VKFMT[] = "%+16.9e %+16.9e %+16.9e"; |
| 47 |
|
#define VKLEN 64 |
| 48 |
|
|
| 49 |
|
#define mkvkey(k,v) sprintf(k, VKFMT, (v)[0], (v)[1], (v)[2]) |
| 50 |
|
|
| 51 |
|
#define NVERTS 256 |
| 52 |
|
|
| 53 |
< |
long clock; /* incremented at each vertex request */ |
| 53 |
> |
long vclock; /* incremented at each vertex request */ |
| 54 |
|
|
| 55 |
|
struct vert { |
| 56 |
|
long lused; /* when last used (0 if unassigned) */ |
| 288 |
|
add2dispatch("metal", o_metal); |
| 289 |
|
add2dispatch("metal2", o_metal); |
| 290 |
|
add2dispatch("glass", o_glass); |
| 291 |
+ |
add2dispatch("dielectric", o_dielectric); |
| 292 |
|
add2dispatch("trans", o_trans); |
| 293 |
|
add2dispatch("trans2", o_trans); |
| 294 |
|
add2dispatch("mirror", o_mirror); |
| 348 |
|
char *vname; |
| 349 |
|
FVECT vp; |
| 350 |
|
{ |
| 351 |
< |
char vkey[VKLEN]; |
| 351 |
> |
static char vkey[VKLEN]; |
| 352 |
|
register LUENT *lp; |
| 353 |
|
register int i, vndx; |
| 354 |
|
|
| 355 |
< |
clock++; /* increment counter */ |
| 355 |
> |
vclock++; /* increment counter */ |
| 356 |
|
mkvkey(vkey, vp); |
| 357 |
|
if ((lp = lu_find(&vertab, vkey)) == NULL) |
| 358 |
|
goto memerr; |
| 378 |
|
lp->data = (char *)&vert[vndx]; /* set it */ |
| 379 |
|
} else |
| 380 |
|
vndx = (struct vert *)lp->data - vert; |
| 381 |
< |
vert[vndx].lused = clock; /* record this use */ |
| 381 |
> |
vert[vndx].lused = vclock; /* record this use */ |
| 382 |
|
sprintf(vname, "v%d", vndx); |
| 383 |
|
return(vname); |
| 384 |
|
memerr: |
| 629 |
|
newmat(id, NULL); |
| 630 |
|
if (fa->nfargs == 4) |
| 631 |
|
nrfr = fa->farg[3]; |
| 632 |
+ |
printf("\tir %f 0\n", nrfr); |
| 633 |
|
F = (1. - nrfr)/(1. + nrfr); /* use normal incidence */ |
| 634 |
|
F *= F; |
| 635 |
|
for (i = 0; i < 3; i++) { |
| 644 |
|
if (d > FTINY) |
| 645 |
|
printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d); |
| 646 |
|
printf("\trs %.4f 0\n", cxyz[1]); |
| 647 |
+ |
rgb_cie(cxyz, trgb); /* put transmitted component */ |
| 648 |
+ |
puts("\tc"); |
| 649 |
+ |
d = cxyz[0] + cxyz[1] + cxyz[2]; |
| 650 |
+ |
if (d > FTINY) |
| 651 |
+ |
printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d); |
| 652 |
+ |
printf("\tts %.4f 0\n", cxyz[1]); |
| 653 |
+ |
return(0); |
| 654 |
+ |
} |
| 655 |
+ |
|
| 656 |
+ |
|
| 657 |
+ |
int |
| 658 |
+ |
o_dielectric(mod, typ, id, fa) /* convert a dielectric material */ |
| 659 |
+ |
char *mod, *typ, *id; |
| 660 |
+ |
register FUNARGS *fa; |
| 661 |
+ |
{ |
| 662 |
+ |
COLOR cxyz, trgb; |
| 663 |
+ |
double F, d; |
| 664 |
+ |
register int i; |
| 665 |
+ |
|
| 666 |
+ |
if (fa->nfargs != 5) |
| 667 |
+ |
return(-1); |
| 668 |
+ |
newmat(id, NULL); |
| 669 |
+ |
F = (1. - fa->farg[3])/(1. + fa->farg[3]); /* normal incidence */ |
| 670 |
+ |
F *= F; |
| 671 |
+ |
for (i = 0; i < 3; i++) |
| 672 |
+ |
trgb[i] = (1. - F)*pow(fa->farg[i], C_1SIDEDTHICK/unit_mult); |
| 673 |
+ |
printf("\tir %f 0\n", fa->farg[3]); /* put index of refraction */ |
| 674 |
+ |
printf("\tsides 1\n"); |
| 675 |
+ |
puts("\tc"); /* put reflected component */ |
| 676 |
+ |
printf("\trs %.4f 0\n", F); |
| 677 |
|
rgb_cie(cxyz, trgb); /* put transmitted component */ |
| 678 |
|
puts("\tc"); |
| 679 |
|
d = cxyz[0] + cxyz[1] + cxyz[2]; |