ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/t_func.c
Revision: 1.7
Committed: Thu Oct 5 07:23:20 1989 UTC (34 years, 7 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.6: +0 -4 lines
Log Message:
Eliminated need to initialize matrix for call to xf() and invxf()

File Contents

# Content
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 double d;
47 register XFORM *mxf;
48 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 if ((mxf = (XFORM *)m->os) == NULL) {
56 mxf = (XFORM *)malloc(sizeof(XFORM));
57 if (mxf == NULL)
58 goto memerr;
59 if (xf(mxf->fore.xfm, &mxf->fore.sca,
60 m->oargs.nsargs-4, sa+4) != m->oargs.nsargs-4)
61 objerror(m, USER, "bad transform");
62 if (mxf->fore.sca < 0.0)
63 mxf->fore.sca = -mxf->fore.sca;
64 invxf(mxf->back.xfm, &mxf->back.sca,
65 m->oargs.nsargs-4, sa+4);
66 if (mxf->back.sca < 0.0)
67 mxf->back.sca = -mxf->back.sca;
68 m->os = (char *)mxf;
69 }
70
71 setmap(m, r, mxf->back.xfm, mxf->back.sca);
72
73 if (!vardefined(sa[0]))
74 loadfunc(sa[3]);
75 errno = 0;
76 for (i = 0; i < 3; i++)
77 disp[i] = varvalue(sa[i]);
78 if (errno) {
79 objerror(m, WARNING, "compute error");
80 return;
81 }
82 multv3(disp, disp, mxf->fore.xfm);
83 multv3(disp, disp, r->rofx);
84 d = 1.0 / (mxf->fore.sca * r->rofs);
85 for (i = 0; i < 3; i++)
86 r->pert[i] += disp[i] * d;
87 return;
88 memerr:
89 error(SYSTEM, "out of memory in t_func");
90 }