1 |
– |
/* Copyright (c) 1990 Regents of the University of California */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* t_data.c - routine for stored textures |
9 |
– |
* |
10 |
– |
* 6/4/86 |
6 |
|
*/ |
7 |
|
|
8 |
+ |
#include "copyright.h" |
9 |
+ |
|
10 |
|
#include "ray.h" |
11 |
|
|
12 |
|
#include "data.h" |
13 |
|
|
14 |
+ |
#include "func.h" |
15 |
+ |
|
16 |
|
/* |
17 |
|
* A stored texture is specified as follows: |
18 |
|
* |
35 |
|
register OBJREC *m; |
36 |
|
RAY *r; |
37 |
|
{ |
39 |
– |
extern double varvalue(), funvalue(), datavalue(); |
40 |
– |
extern int errno; |
38 |
|
int nv; |
39 |
< |
FVECT dval, disp; |
40 |
< |
double pt[MAXDIM]; |
39 |
> |
FVECT disp; |
40 |
> |
double dval[3], pt[MAXDIM]; |
41 |
|
double d; |
42 |
|
DATARRAY *dp; |
43 |
< |
register FULLXF *mxf; |
47 |
< |
register char **sa; |
43 |
> |
register MFUNC *mf; |
44 |
|
register int i; |
45 |
|
|
46 |
|
if (m->oargs.nsargs < 8) |
47 |
|
objerror(m, USER, "bad # arguments"); |
48 |
< |
sa = m->oargs.sarg; |
49 |
< |
|
50 |
< |
for (i = 7; i < m->oargs.nsargs && sa[i][0] != '-'; i++) |
51 |
< |
; |
56 |
< |
nv = i-7; |
57 |
< |
if ((mxf = (FULLXF *)m->os) == NULL) { |
58 |
< |
mxf = (FULLXF *)malloc(sizeof(FULLXF)); |
59 |
< |
if (mxf == NULL) |
60 |
< |
goto memerr; |
61 |
< |
if (fullxf(mxf, m->oargs.nsargs-i, sa+i) != m->oargs.nsargs-i) |
62 |
< |
objerror(m, USER, "bad transform"); |
63 |
< |
if (mxf->f.sca < 0.0) |
64 |
< |
mxf->f.sca = -mxf->f.sca; |
65 |
< |
if (mxf->b.sca < 0.0) |
66 |
< |
mxf->b.sca = -mxf->b.sca; |
67 |
< |
m->os = (char *)mxf; |
68 |
< |
} |
69 |
< |
|
70 |
< |
setmap(m, r, &mxf->b); |
71 |
< |
|
72 |
< |
if (nv > MAXDIM) |
73 |
< |
goto dimerr; |
74 |
< |
if (!vardefined(sa[7])) |
75 |
< |
loadfunc(sa[6]); |
48 |
> |
dp = getdata(m->oargs.sarg[3]); |
49 |
> |
i = (1 << (nv = dp->nd)) - 1; |
50 |
> |
mf = getfunc(m, 6, i<<7, 1); |
51 |
> |
setfunc(m, r); |
52 |
|
errno = 0; |
53 |
|
for (i = 0; i < nv; i++) |
54 |
< |
pt[i] = varvalue(sa[i+7]); |
54 |
> |
pt[i] = evalue(mf->ep[i]); |
55 |
|
if (errno) |
56 |
|
goto computerr; |
57 |
< |
for (i = 0; i < 3; i++) { |
58 |
< |
dp = getdata(sa[i+3]); |
57 |
> |
dval[0] = datavalue(dp, pt); |
58 |
> |
for (i = 1; i < 3; i++) { |
59 |
> |
dp = getdata(m->oargs.sarg[i+3]); |
60 |
|
if (dp->nd != nv) |
61 |
< |
goto dimerr; |
61 |
> |
objerror(m, USER, "dimension error"); |
62 |
|
dval[i] = datavalue(dp, pt); |
63 |
|
} |
64 |
|
errno = 0; |
65 |
|
for (i = 0; i < 3; i++) |
66 |
< |
disp[i] = funvalue(sa[i], 3, dval); |
66 |
> |
disp[i] = funvalue(m->oargs.sarg[i], 3, dval); |
67 |
|
if (errno) |
68 |
|
goto computerr; |
69 |
< |
|
70 |
< |
multv3(disp, disp, mxf->f.xfm); |
69 |
> |
if (mf->f != &unitxf) |
70 |
> |
multv3(disp, disp, mf->f->xfm); |
71 |
|
if (r->rox != NULL) { |
72 |
|
multv3(disp, disp, r->rox->f.xfm); |
73 |
< |
d = 1.0 / (mxf->f.sca * r->rox->f.sca); |
73 |
> |
d = 1.0 / (mf->f->sca * r->rox->f.sca); |
74 |
|
} else |
75 |
< |
d = 1.0 / mxf->f.sca; |
75 |
> |
d = 1.0 / mf->f->sca; |
76 |
|
for (i = 0; i < 3; i++) |
77 |
|
r->pert[i] += disp[i] * d; |
78 |
< |
return; |
102 |
< |
dimerr: |
103 |
< |
objerror(m, USER, "dimension error"); |
104 |
< |
memerr: |
105 |
< |
error(SYSTEM, "out of memory in t_data"); |
78 |
> |
return(0); |
79 |
|
computerr: |
80 |
|
objerror(m, WARNING, "compute error"); |
81 |
< |
return; |
81 |
> |
return(0); |
82 |
|
} |