| 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(); | 
| 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); | 
| 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]; |