1 |
/* Copyright (c) 1992 Regents of the University of California */ |
2 |
|
3 |
#ifndef lint |
4 |
static char SCCSid[] = "$SunId$ LBL"; |
5 |
#endif |
6 |
|
7 |
/* |
8 |
* t_data.c - routine for stored textures |
9 |
* |
10 |
* 6/4/86 |
11 |
*/ |
12 |
|
13 |
#include "ray.h" |
14 |
|
15 |
#include "data.h" |
16 |
|
17 |
#include "func.h" |
18 |
|
19 |
/* |
20 |
* A stored texture is specified as follows: |
21 |
* |
22 |
* modifier texdata name |
23 |
* 8+ xfunc yfunc zfunc xdfname ydfname zdfname vfname v0 v1 .. xf |
24 |
* 0 |
25 |
* n A1 A2 .. An |
26 |
* |
27 |
* Vfname is the name of the file where the variable definitions |
28 |
* can be found. The list of real arguments can be accessed by |
29 |
* definitions in the file. The dfnames are the data file |
30 |
* names. The dimensions of the data files and the number |
31 |
* of variables must match. The funcs take three arguments to produce |
32 |
* interpolated values from the file. The xf is a transformation |
33 |
* to get from the original coordinates to the current coordinates. |
34 |
*/ |
35 |
|
36 |
|
37 |
t_data(m, r) /* interpolate texture data */ |
38 |
register OBJREC *m; |
39 |
RAY *r; |
40 |
{ |
41 |
int nv; |
42 |
FVECT disp; |
43 |
double dval[3], pt[MAXDIM]; |
44 |
double d; |
45 |
DATARRAY *dp; |
46 |
register MFUNC *mf; |
47 |
register int i; |
48 |
|
49 |
if (m->oargs.nsargs < 8) |
50 |
objerror(m, USER, "bad # arguments"); |
51 |
dp = getdata(m->oargs.sarg[3]); |
52 |
i = (1 << (nv = dp->nd)) - 1; |
53 |
mf = getfunc(m, 6, i<<7, 1); |
54 |
setfunc(m, r); |
55 |
errno = 0; |
56 |
for (i = 0; i < nv; i++) |
57 |
pt[i] = evalue(mf->ep[i]); |
58 |
if (errno) |
59 |
goto computerr; |
60 |
dval[0] = datavalue(dp, pt); |
61 |
for (i = 1; i < 3; i++) { |
62 |
dp = getdata(m->oargs.sarg[i+3]); |
63 |
if (dp->nd != nv) |
64 |
objerror(m, USER, "dimension error"); |
65 |
dval[i] = datavalue(dp, pt); |
66 |
} |
67 |
errno = 0; |
68 |
for (i = 0; i < 3; i++) |
69 |
disp[i] = funvalue(m->oargs.sarg[i], 3, dval); |
70 |
if (errno) |
71 |
goto computerr; |
72 |
if (mf->f != &unitxf) |
73 |
multv3(disp, disp, mf->f->xfm); |
74 |
if (r->rox != NULL) { |
75 |
multv3(disp, disp, r->rox->f.xfm); |
76 |
d = 1.0 / (mf->f->sca * r->rox->f.sca); |
77 |
} else |
78 |
d = 1.0 / mf->f->sca; |
79 |
for (i = 0; i < 3; i++) |
80 |
r->pert[i] += disp[i] * d; |
81 |
return; |
82 |
computerr: |
83 |
objerror(m, WARNING, "compute error"); |
84 |
return; |
85 |
} |