ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/t_func.c
Revision: 1.9
Committed: Thu Aug 8 11:29:51 1991 UTC (32 years, 9 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.8: +1 -2 lines
Log Message:
added contexts to function files

File Contents

# User Rev Content
1 greg 1.8 /* Copyright (c) 1990 Regents of the University of California */
2 greg 1.1
3     #ifndef lint
4     static char SCCSid[] = "$SunId$ LBL";
5     #endif
6    
7     /*
8     * t_func.c - routine for procedural textures.
9     *
10     * 4/8/86
11     */
12    
13     #include "ray.h"
14    
15     /*
16     * A procedural texture perturbs the surface normal
17     * at the point of intersection with an object. It has
18     * the form:
19     *
20     * modifier texfunc name
21     * 4+ xvarname yvarname zvarname filename xf
22     * 0
23     * n A1 A2 ..
24     *
25     * Filename is the name of the file where the variable definitions
26     * can be found. The list of real arguments can be accessed by
27     * definitions in the file. The xf is a transformation to get
28     * from the original coordinates to the current coordinates.
29     */
30    
31    
32     t_func(m, r) /* compute texture for ray */
33     register OBJREC *m;
34     register RAY *r;
35     {
36     extern double varvalue();
37     extern int errno;
38     FVECT disp;
39 greg 1.6 double d;
40 greg 1.8 register FULLXF *mxf;
41 greg 1.1 register int i;
42     register char **sa;
43    
44     if (m->oargs.nsargs < 4)
45     objerror(m, USER, "bad # arguments");
46     sa = m->oargs.sarg;
47    
48 greg 1.8 if ((mxf = (FULLXF *)m->os) == NULL) {
49     mxf = (FULLXF *)malloc(sizeof(FULLXF));
50 greg 1.1 if (mxf == NULL)
51     goto memerr;
52 greg 1.8 if (fullxf(mxf, m->oargs.nsargs-4, sa+4) != m->oargs.nsargs-4)
53 greg 1.1 objerror(m, USER, "bad transform");
54 greg 1.8 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 greg 1.2 m->os = (char *)mxf;
59 greg 1.1 }
60    
61 greg 1.8 setmap(m, r, &mxf->b);
62 greg 1.1
63 greg 1.9 funcfile(sa[3]);
64 greg 1.1 errno = 0;
65     for (i = 0; i < 3; i++)
66     disp[i] = varvalue(sa[i]);
67     if (errno) {
68     objerror(m, WARNING, "compute error");
69     return;
70     }
71 greg 1.8 multv3(disp, disp, mxf->f.xfm);
72     if (r->rox != NULL) {
73     multv3(disp, disp, r->rox->f.xfm);
74     d = 1.0 / (mxf->f.sca * r->rox->f.sca);
75     } else
76     d = 1.0 / mxf->f.sca;
77 greg 1.4 for (i = 0; i < 3; i++)
78 greg 1.6 r->pert[i] += disp[i] * d;
79 greg 1.1 return;
80     memerr:
81     error(SYSTEM, "out of memory in t_func");
82     }