ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/xf.c
Revision: 1.1
Committed: Thu Feb 2 10:34:41 1989 UTC (35 years, 3 months ago) by greg
Content type: text/plain
Branch: MAIN
Log Message:
Initial revision

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 * xf.c - routines to convert transform arguments into 4X4 matrix.
9 *
10 * 1/28/86
11 */
12
13
14 #define PI 3.14159265358979323846
15
16
17 int
18 xf(xfmat, xfsca, ac, av) /* get transform specification */
19 double xfmat[4][4];
20 double *xfsca;
21 int ac;
22 char *av[];
23 {
24 double atof(), sin(), cos();
25 double m4[4][4];
26 double theta;
27 int i;
28
29 for (i = 0; i < ac && av[i][0] == '-'; i++) {
30
31 setident4(m4);
32
33 switch (av[i][1]) {
34
35 case 't': /* translate */
36 m4[3][0] = atof(av[++i]);
37 m4[3][1] = atof(av[++i]);
38 m4[3][2] = atof(av[++i]);
39 break;
40
41 case 'r': /* rotate */
42 switch (av[i][2]) {
43 case 'x':
44 theta = PI/180.0 * atof(av[++i]);
45 m4[1][1] = m4[2][2] = cos(theta);
46 m4[2][1] = -(m4[1][2] = sin(theta));
47 break;
48 case 'y':
49 theta = PI/180 * atof(av[++i]);
50 m4[0][0] = m4[2][2] = cos(theta);
51 m4[0][2] = -(m4[2][0] = sin(theta));
52 break;
53 case 'z':
54 theta = PI/180 * atof(av[++i]);
55 m4[0][0] = m4[1][1] = cos(theta);
56 m4[1][0] = -(m4[0][1] = sin(theta));
57 break;
58 default:
59 return(i);
60 }
61 break;
62
63 case 's': /* scale */
64 *xfsca *=
65 m4[0][0] =
66 m4[1][1] =
67 m4[2][2] = atof(av[++i]);
68 break;
69
70 case 'm': /* mirror */
71 switch (av[i][2]) {
72 case 'x':
73 *xfsca *=
74 m4[0][0] = -1.0;
75 break;
76 case 'y':
77 *xfsca *=
78 m4[1][1] = -1.0;
79 break;
80 case 'z':
81 *xfsca *=
82 m4[2][2] = -1.0;
83 break;
84 default:
85 return(i);
86 }
87 break;
88
89 default:
90 return(i);
91
92 }
93 multmat4(xfmat, xfmat, m4);
94 }
95 return(i);
96 }
97
98
99 #ifdef INVXF
100 int
101 invxf(xfmat, xfsca, ac, av) /* invert transform specification */
102 double xfmat[4][4];
103 double *xfsca;
104 int ac;
105 char *av[];
106 {
107 double atof(), sin(), cos();
108 double m4[4][4];
109 double theta;
110 int i;
111
112 for (i = 0; i < ac && av[i][0] == '-'; i++) {
113
114 setident4(m4);
115
116 switch (av[i][1]) {
117
118 case 't': /* translate */
119 m4[3][0] = -atof(av[++i]);
120 m4[3][1] = -atof(av[++i]);
121 m4[3][2] = -atof(av[++i]);
122 break;
123
124 case 'r': /* rotate */
125 switch (av[i][2]) {
126 case 'x':
127 theta = -PI/180.0 * atof(av[++i]);
128 m4[1][1] = m4[2][2] = cos(theta);
129 m4[2][1] = -(m4[1][2] = sin(theta));
130 break;
131 case 'y':
132 theta = -PI/180.0 * atof(av[++i]);
133 m4[0][0] = m4[2][2] = cos(theta);
134 m4[0][2] = -(m4[2][0] = sin(theta));
135 break;
136 case 'z':
137 theta = -PI/180.0 * atof(av[++i]);
138 m4[0][0] = m4[1][1] = cos(theta);
139 m4[1][0] = -(m4[0][1] = sin(theta));
140 break;
141 default:
142 return(i);
143 }
144 break;
145
146 case 's': /* scale */
147 *xfsca *=
148 m4[0][0] =
149 m4[1][1] =
150 m4[2][2] = 1.0 / atof(av[++i]);
151 break;
152
153 case 'm': /* mirror */
154 switch (av[i][2]) {
155 case 'x':
156 *xfsca *=
157 m4[0][0] = -1.0;
158 break;
159 case 'y':
160 *xfsca *=
161 m4[1][1] = -1.0;
162 break;
163 case 'z':
164 *xfsca *=
165 m4[2][2] = -1.0;
166 break;
167 default:
168 return(i);
169 }
170 break;
171
172 default:
173 return(i);
174
175 }
176 multmat4(xfmat, m4, xfmat); /* left multiply */
177 }
178 return(i);
179 }
180 #endif