| 1 | 
greg | 
1.1 | 
/* Copyright (c) 1988 Regents of the University of California */ | 
| 2 | 
  | 
  | 
 | 
| 3 | 
  | 
  | 
#ifndef lint | 
| 4 | 
  | 
  | 
static char SCCSid[] = "$SunId$ LBL"; | 
| 5 | 
  | 
  | 
#endif | 
| 6 | 
  | 
  | 
 | 
| 7 | 
  | 
  | 
/* | 
| 8 | 
  | 
  | 
 *  mx_func.c - routine for mixture functions. | 
| 9 | 
  | 
  | 
 * | 
| 10 | 
  | 
  | 
 *     11/2/88 | 
| 11 | 
  | 
  | 
 */ | 
| 12 | 
  | 
  | 
 | 
| 13 | 
  | 
  | 
#include  "ray.h" | 
| 14 | 
  | 
  | 
 | 
| 15 | 
  | 
  | 
/* | 
| 16 | 
  | 
  | 
 *      A mixture function is specified: | 
| 17 | 
  | 
  | 
 * | 
| 18 | 
  | 
  | 
 *      modifier mixfunc name | 
| 19 | 
  | 
  | 
 *      4+ foremod backmod varname vfname xf | 
| 20 | 
  | 
  | 
 *      0 | 
| 21 | 
  | 
  | 
 *      n A1 A2 .. | 
| 22 | 
  | 
  | 
 * | 
| 23 | 
  | 
  | 
 *  Vfname is the name of the file where the variable definition | 
| 24 | 
  | 
  | 
 *  can be found.  The list of real arguments can be accessed by | 
| 25 | 
  | 
  | 
 *  definitions in the file.  The xf is a transformation | 
| 26 | 
  | 
  | 
 *  to get from the original coordinates to the current coordinates. | 
| 27 | 
  | 
  | 
 */ | 
| 28 | 
  | 
  | 
 | 
| 29 | 
  | 
  | 
 | 
| 30 | 
  | 
  | 
mx_func(m, r)                   /* compute mixture function */ | 
| 31 | 
  | 
  | 
register OBJREC  *m; | 
| 32 | 
  | 
  | 
RAY  *r; | 
| 33 | 
  | 
  | 
{ | 
| 34 | 
  | 
  | 
        extern double  varvalue(); | 
| 35 | 
  | 
  | 
        extern int  errno; | 
| 36 | 
  | 
  | 
        register int  i; | 
| 37 | 
  | 
  | 
        double  coef; | 
| 38 | 
  | 
  | 
        OBJECT  mod[2]; | 
| 39 | 
  | 
  | 
        register char  **sa; | 
| 40 | 
  | 
  | 
 | 
| 41 | 
  | 
  | 
        setfunc(m, r); | 
| 42 | 
  | 
  | 
 | 
| 43 | 
  | 
  | 
        sa = m->oargs.sarg; | 
| 44 | 
  | 
  | 
 | 
| 45 | 
  | 
  | 
        if (m->oargs.nsargs < 4) | 
| 46 | 
  | 
  | 
                objerror(m, USER, "bad # arguments"); | 
| 47 | 
  | 
  | 
        for (i = 0; i < 2; i++) | 
| 48 | 
  | 
  | 
                if (!strcmp(sa[i], VOIDID)) | 
| 49 | 
  | 
  | 
                        mod[i] = OVOID; | 
| 50 | 
  | 
  | 
                else if ((mod[i] = modifier(sa[i])) == OVOID) { | 
| 51 | 
  | 
  | 
                        sprintf(errmsg, "undefined modifier \"%s\"", sa[i]); | 
| 52 | 
  | 
  | 
                        objerror(m, USER, errmsg); | 
| 53 | 
  | 
  | 
                } | 
| 54 | 
  | 
  | 
        if (!vardefined(sa[2])) | 
| 55 | 
  | 
  | 
                loadfunc(sa[3]); | 
| 56 | 
  | 
  | 
        errno = 0; | 
| 57 | 
  | 
  | 
        coef = varvalue(sa[2]); | 
| 58 | 
  | 
  | 
        if (errno) { | 
| 59 | 
  | 
  | 
                objerror(m, WARNING, "compute error"); | 
| 60 | 
  | 
  | 
                return; | 
| 61 | 
  | 
  | 
        } | 
| 62 | 
  | 
  | 
        raymixture(r, mod[0], mod[1], coef); | 
| 63 | 
  | 
  | 
} |