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_func.c - routine for procedural textures. |
9 |
– |
* |
10 |
– |
* 4/8/86 |
6 |
|
*/ |
7 |
|
|
8 |
+ |
#include "copyright.h" |
9 |
+ |
|
10 |
|
#include "ray.h" |
11 |
+ |
#include "func.h" |
12 |
+ |
#include "rtotypes.h" |
13 |
|
|
14 |
|
/* |
15 |
|
* A procedural texture perturbs the surface normal |
28 |
|
*/ |
29 |
|
|
30 |
|
|
31 |
< |
t_func(m, r) /* compute texture for ray */ |
32 |
< |
register OBJREC *m; |
33 |
< |
register RAY *r; |
31 |
> |
int |
32 |
> |
t_func( /* compute texture for ray */ |
33 |
> |
OBJREC *m, |
34 |
> |
RAY *r |
35 |
> |
) |
36 |
|
{ |
36 |
– |
extern double varvalue(); |
37 |
– |
extern int errno; |
37 |
|
FVECT disp; |
38 |
|
double d; |
39 |
< |
register FULLXF *mxf; |
40 |
< |
register int i; |
42 |
< |
register char **sa; |
39 |
> |
MFUNC *mf; |
40 |
> |
int i; |
41 |
|
|
42 |
|
if (m->oargs.nsargs < 4) |
43 |
|
objerror(m, USER, "bad # arguments"); |
44 |
< |
sa = m->oargs.sarg; |
45 |
< |
|
48 |
< |
if ((mxf = (FULLXF *)m->os) == NULL) { |
49 |
< |
mxf = (FULLXF *)malloc(sizeof(FULLXF)); |
50 |
< |
if (mxf == NULL) |
51 |
< |
goto memerr; |
52 |
< |
if (fullxf(mxf, m->oargs.nsargs-4, sa+4) != m->oargs.nsargs-4) |
53 |
< |
objerror(m, USER, "bad transform"); |
54 |
< |
if (mxf->f.sca < 0.0) |
55 |
< |
mxf->f.sca = -mxf->f.sca; |
56 |
< |
if (mxf->b.sca < 0.0) |
57 |
< |
mxf->b.sca = -mxf->b.sca; |
58 |
< |
m->os = (char *)mxf; |
59 |
< |
} |
60 |
< |
|
61 |
< |
setmap(m, r, &mxf->b); |
62 |
< |
|
63 |
< |
if (!vardefined(sa[0])) |
64 |
< |
loadfunc(sa[3]); |
44 |
> |
mf = getfunc(m, 3, 0x7, 1); |
45 |
> |
setfunc(m, r); |
46 |
|
errno = 0; |
47 |
< |
for (i = 0; i < 3; i++) |
48 |
< |
disp[i] = varvalue(sa[i]); |
49 |
< |
if (errno) { |
50 |
< |
objerror(m, WARNING, "compute error"); |
51 |
< |
return; |
47 |
> |
for (i = 0; i < 3; i++) { |
48 |
> |
disp[i] = evalue(mf->ep[i]); |
49 |
> |
if ((errno == EDOM) | (errno == ERANGE)) { |
50 |
> |
objerror(m, WARNING, "compute error"); |
51 |
> |
return(0); |
52 |
> |
} |
53 |
|
} |
54 |
< |
multv3(disp, disp, mxf->f.xfm); |
54 |
> |
if (mf->fxp != &unitxf) |
55 |
> |
multv3(disp, disp, mf->fxp->xfm); |
56 |
|
if (r->rox != NULL) { |
57 |
|
multv3(disp, disp, r->rox->f.xfm); |
58 |
< |
d = 1.0 / (mxf->f.sca * r->rox->f.sca); |
58 |
> |
d = 1.0 / (mf->fxp->sca * r->rox->f.sca); |
59 |
|
} else |
60 |
< |
d = 1.0 / mxf->f.sca; |
61 |
< |
for (i = 0; i < 3; i++) |
62 |
< |
r->pert[i] += disp[i] * d; |
80 |
< |
return; |
81 |
< |
memerr: |
82 |
< |
error(SYSTEM, "out of memory in t_func"); |
60 |
> |
d = 1.0 / mf->fxp->sca; |
61 |
> |
VSUM(r->pert, r->pert, disp, d); |
62 |
> |
return(0); |
63 |
|
} |