home *** CD-ROM | disk | FTP | other *** search
- /* Copyright (c) 1992 Regents of the University of California */
-
- #ifndef lint
- static char SCCSid[] = "@(#)t_data.c 2.3 6/30/92 LBL";
- #endif
-
- /*
- * t_data.c - routine for stored textures
- *
- * 6/4/86
- */
-
- #include "ray.h"
-
- #include "data.h"
-
- #include "func.h"
-
- /*
- * A stored texture is specified as follows:
- *
- * modifier texdata name
- * 8+ xfunc yfunc zfunc xdfname ydfname zdfname vfname v0 v1 .. xf
- * 0
- * n A1 A2 .. An
- *
- * Vfname is the name of the file where the variable definitions
- * can be found. The list of real arguments can be accessed by
- * definitions in the file. The dfnames are the data file
- * names. The dimensions of the data files and the number
- * of variables must match. The funcs take three arguments to produce
- * interpolated values from the file. The xf is a transformation
- * to get from the original coordinates to the current coordinates.
- */
-
-
- t_data(m, r) /* interpolate texture data */
- register OBJREC *m;
- RAY *r;
- {
- int nv;
- FVECT disp;
- double dval[3], pt[MAXDIM];
- double d;
- DATARRAY *dp;
- register MFUNC *mf;
- register int i;
-
- if (m->oargs.nsargs < 8)
- objerror(m, USER, "bad # arguments");
- dp = getdata(m->oargs.sarg[3]);
- i = (1 << (nv = dp->nd)) - 1;
- mf = getfunc(m, 6, i<<7, 1);
- setfunc(m, r);
- errno = 0;
- for (i = 0; i < nv; i++)
- pt[i] = evalue(mf->ep[i]);
- if (errno)
- goto computerr;
- dval[0] = datavalue(dp, pt);
- for (i = 1; i < 3; i++) {
- dp = getdata(m->oargs.sarg[i+3]);
- if (dp->nd != nv)
- objerror(m, USER, "dimension error");
- dval[i] = datavalue(dp, pt);
- }
- errno = 0;
- for (i = 0; i < 3; i++)
- disp[i] = funvalue(m->oargs.sarg[i], 3, dval);
- if (errno)
- goto computerr;
- if (mf->f != &unitxf)
- multv3(disp, disp, mf->f->xfm);
- if (r->rox != NULL) {
- multv3(disp, disp, r->rox->f.xfm);
- d = 1.0 / (mf->f->sca * r->rox->f.sca);
- } else
- d = 1.0 / mf->f->sca;
- for (i = 0; i < 3; i++)
- r->pert[i] += disp[i] * d;
- return;
- computerr:
- objerror(m, WARNING, "compute error");
- return;
- }
-