ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/t_func.c
Revision: 1.6
Committed: Wed Apr 19 21:20:29 1989 UTC (35 years ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.5: +3 -1 lines
Log Message:
added loop invariant

File Contents

# User Rev Content
1 greg 1.1 /* Copyright (c) 1986 Regents of the University of California */
2    
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     typedef struct {
32     struct {
33     double sca; /* scale factor */
34     double xfm[4][4]; /* transformation matrix */
35     } fore, back;
36     } XFORM;
37    
38    
39     t_func(m, r) /* compute texture for ray */
40     register OBJREC *m;
41     register RAY *r;
42     {
43     extern double varvalue();
44     extern int errno;
45     FVECT disp;
46 greg 1.6 double d;
47 greg 1.2 register XFORM *mxf;
48 greg 1.1 register int i;
49     register char **sa;
50    
51     if (m->oargs.nsargs < 4)
52     objerror(m, USER, "bad # arguments");
53     sa = m->oargs.sarg;
54    
55 greg 1.2 if ((mxf = (XFORM *)m->os) == NULL) {
56 greg 1.1 mxf = (XFORM *)malloc(sizeof(XFORM));
57     if (mxf == NULL)
58     goto memerr;
59     mxf->fore.sca = 1.0;
60     setident4(mxf->fore.xfm);
61     if (xf(mxf->fore.xfm, &mxf->fore.sca,
62     m->oargs.nsargs-4, sa+4) != m->oargs.nsargs-4)
63     objerror(m, USER, "bad transform");
64     if (mxf->fore.sca < 0.0)
65     mxf->fore.sca = -mxf->fore.sca;
66     mxf->back.sca = 1.0;
67     setident4(mxf->back.xfm);
68     invxf(mxf->back.xfm, &mxf->back.sca,
69     m->oargs.nsargs-4, sa+4);
70     if (mxf->back.sca < 0.0)
71     mxf->back.sca = -mxf->back.sca;
72 greg 1.2 m->os = (char *)mxf;
73 greg 1.1 }
74    
75 greg 1.3 setmap(m, r, mxf->back.xfm, mxf->back.sca);
76 greg 1.1
77     if (!vardefined(sa[0]))
78     loadfunc(sa[3]);
79     errno = 0;
80     for (i = 0; i < 3; i++)
81     disp[i] = varvalue(sa[i]);
82     if (errno) {
83     objerror(m, WARNING, "compute error");
84     return;
85     }
86 greg 1.5 multv3(disp, disp, mxf->fore.xfm);
87     multv3(disp, disp, r->rofx);
88 greg 1.6 d = 1.0 / (mxf->fore.sca * r->rofs);
89 greg 1.4 for (i = 0; i < 3; i++)
90 greg 1.6 r->pert[i] += disp[i] * d;
91 greg 1.1 return;
92     memerr:
93     error(SYSTEM, "out of memory in t_func");
94     }