1 |
#ifndef lint |
2 |
static const char RCSid[] = "$Id: mx_func.c,v 2.9 2014/07/08 18:25:00 greg Exp $"; |
3 |
#endif |
4 |
/* |
5 |
* mx_func.c - routine for mixture functions. |
6 |
*/ |
7 |
|
8 |
#include "copyright.h" |
9 |
|
10 |
#include "ray.h" |
11 |
#include "func.h" |
12 |
#include "rtotypes.h" |
13 |
|
14 |
/* |
15 |
* A mixture function is specified: |
16 |
* |
17 |
* modifier mixfunc name |
18 |
* 4+ foremod backmod varname vfname xf |
19 |
* 0 |
20 |
* n A1 A2 .. |
21 |
* |
22 |
* Vfname is the name of the file where the variable definition |
23 |
* can be found. The list of real arguments can be accessed by |
24 |
* definitions in the file. The xf is a transformation |
25 |
* to get from the original coordinates to the current coordinates. |
26 |
*/ |
27 |
|
28 |
|
29 |
int |
30 |
mx_func( /* compute mixture function */ |
31 |
OBJREC *m, |
32 |
RAY *r |
33 |
) |
34 |
{ |
35 |
OBJECT obj; |
36 |
int i; |
37 |
double coef; |
38 |
OBJECT mod[2]; |
39 |
MFUNC *mf; |
40 |
|
41 |
if (m->oargs.nsargs < 4) |
42 |
objerror(m, USER, "bad # arguments"); |
43 |
obj = objndx(m); |
44 |
for (i = 0; i < 2; i++) |
45 |
if (!strcmp(m->oargs.sarg[i], VOIDID)) |
46 |
mod[i] = OVOID; |
47 |
else if ((mod[i] = lastmod(obj, m->oargs.sarg[i])) == OVOID) { |
48 |
sprintf(errmsg, "undefined modifier \"%s\"", |
49 |
m->oargs.sarg[i]); |
50 |
objerror(m, USER, errmsg); |
51 |
} |
52 |
mf = getfunc(m, 3, 0x4, 0); |
53 |
setfunc(m, r); |
54 |
errno = 0; |
55 |
coef = evalue(mf->ep[0]); |
56 |
if ((errno == EDOM) | (errno == ERANGE)) { |
57 |
objerror(m, WARNING, "compute error"); |
58 |
return(0); |
59 |
} |
60 |
if (raymixture(r, mod[0], mod[1], coef)) { |
61 |
if (m->omod != OVOID) |
62 |
objerror(m, USER, "inappropriate modifier"); |
63 |
return(1); |
64 |
} |
65 |
return(0); |
66 |
} |