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