]> Dogcows Code - chaz/yoink/blob - src/moof/cml/mathlib/matrix_basis.h
bugfix: win32 packaging script temp directories
[chaz/yoink] / src / moof / cml / mathlib / matrix_basis.h
1 /* -*- C++ -*- ------------------------------------------------------------
2
3 Copyright (c) 2007 Jesse Anders and Demian Nave http://cmldev.net/
4
5 The Configurable Math Library (CML) is distributed under the terms of the
6 Boost Software License, v1.0 (see cml/LICENSE for details).
7
8 *-----------------------------------------------------------------------*/
9 /** @file
10 * @brief
11 */
12
13 #ifndef matrix_basis_h
14 #define matrix_basis_h
15
16 #include <cml/mathlib/checking.h>
17
18 /* This file contains functions for setting and retrieving the basis vectors
19 * or transposed basis vectors of a matrix representing a 3D or 2D transform,
20 * either by index (0,1,2) or name (x,y,z).
21 *
22 * In addition to being a convenience for the user, the functions are also
23 * in support of other matrix functions which are best implemented in vector
24 * form (such as orthogonalization and construction of orthonormal bases).
25 *
26 * Note that matrix expression arguments are allowed to have dimensions larger
27 * than the minimum requirement. For example, matrix_get_basis_vector() can be
28 * called on any NxM matrix with N,M >= 3.
29 *
30 * As with other matrix functions, the following template argument notation is
31 * used for conciseness:
32 *
33 * E = vector or matrix element type
34 * A = vector or matrix array storage type
35 * B = matrix basis orientation type
36 * L = matrix layout type
37 */
38
39 namespace cml {
40
41 //////////////////////////////////////////////////////////////////////////////
42 // Functions for setting the basis vectors of a 3D or 2D transform matrix
43 //////////////////////////////////////////////////////////////////////////////
44
45 /** Set the i'th basis vector of a 3D transform */
46 template < typename E, class A, class B, class L, class VecT > void
47 matrix_set_basis_vector(matrix<E,A,B,L>& m, size_t i, const VecT& v)
48 {
49 /* Checking */
50 detail::CheckMatLinear3D(m);
51 detail::CheckVec3(v);
52 detail::CheckIndex3(i);
53
54 m.set_basis_element(i,0,v[0]);
55 m.set_basis_element(i,1,v[1]);
56 m.set_basis_element(i,2,v[2]);
57 }
58
59 /** Set the i'th transposed basis vector of a 3D transform */
60 template < typename E, class A, class B, class L, class VecT > void
61 matrix_set_transposed_basis_vector(matrix<E,A,B,L>& m,size_t i,const VecT& v)
62 {
63 /* Checking */
64 detail::CheckMatLinear3D(m);
65 detail::CheckVec3(v);
66 detail::CheckIndex3(i);
67
68 m.set_basis_element(0,i,v[0]);
69 m.set_basis_element(1,i,v[1]);
70 m.set_basis_element(2,i,v[2]);
71 }
72
73 /** Set the i'th basis vector of a 2D transform */
74 template < typename E, class A, class B, class L, class VecT > void
75 matrix_set_basis_vector_2D(matrix<E,A,B,L>& m, size_t i, const VecT& v)
76 {
77 /* Checking */
78 detail::CheckMatLinear2D(m);
79 detail::CheckVec2(v);
80 detail::CheckIndex2(i);
81
82 m.set_basis_element(i,0,v[0]);
83 m.set_basis_element(i,1,v[1]);
84 }
85
86 /** Set the i'th transposed basis vector of a 2D transform */
87 template < typename E, class A, class B, class L, class VecT > void
88 matrix_set_transposed_basis_vector_2D(
89 matrix<E,A,B,L>& m, size_t i, const VecT& v)
90 {
91 /* Checking */
92 detail::CheckMatLinear2D(m);
93 detail::CheckVec2(v);
94 detail::CheckIndex2(i);
95
96 m.set_basis_element(0,i,v[0]);
97 m.set_basis_element(1,i,v[1]);
98 }
99
100 /** Set the x basis vector of a 3D transform */
101 template < typename E, class A, class B, class L, class VecT > void
102 matrix_set_x_basis_vector(matrix<E,A,B,L>& m, const VecT& x) {
103 matrix_set_basis_vector(m,0,x);
104 }
105
106 /** Set the y basis vector of a 3D transform */
107 template < typename E, class A, class B, class L, class VecT > void
108 matrix_set_y_basis_vector(matrix<E,A,B,L>& m, const VecT& y) {
109 matrix_set_basis_vector(m,1,y);
110 }
111
112 /** Set the z basis vector of a 3D transform */
113 template < typename E, class A, class B, class L, class VecT > void
114 matrix_set_z_basis_vector(matrix<E,A,B,L>& m, const VecT& z) {
115 matrix_set_basis_vector(m,2,z);
116 }
117
118 /** Set the transposed x basis vector of a 3D transform */
119 template < typename E, class A, class B, class L, class VecT > void
120 matrix_set_transposed_x_basis_vector(matrix<E,A,B,L>& m, const VecT& x) {
121 matrix_set_transposed_basis_vector(m,0,x);
122 }
123
124 /** Set the transposed y basis vector of a 3D transform */
125 template < typename E, class A, class B, class L, class VecT > void
126 matrix_set_transposed_y_basis_vector(matrix<E,A,B,L>& m, const VecT& y) {
127 matrix_set_transposed_basis_vector(m,1,y);
128 }
129
130 /** Set the transposed z basis vector of a 3D transform */
131 template < typename E, class A, class B, class L, class VecT > void
132 matrix_set_transposed_z_basis_vector(matrix<E,A,B,L>& m, const VecT& z) {
133 matrix_set_transposed_basis_vector(m,2,z);
134 }
135
136 /** Set the x basis vector of a 2D transform */
137 template < typename E, class A, class B, class L, class VecT > void
138 matrix_set_x_basis_vector_2D(matrix<E,A,B,L>& m, const VecT& x) {
139 matrix_set_basis_vector_2D(m,0,x);
140 }
141
142 /** Set the y basis vector of a 2D transform */
143 template < typename E, class A, class B, class L, class VecT > void
144 matrix_set_y_basis_vector_2D(matrix<E,A,B,L>& m, const VecT& y) {
145 matrix_set_basis_vector_2D(m,1,y);
146 }
147
148 /** Set the transposed x basis vector of a 2D transform */
149 template < typename E, class A, class B, class L, class VecT > void
150 matrix_set_transposed_x_basis_vector_2D(matrix<E,A,B,L>& m,const VecT& x) {
151 matrix_set_transposed_basis_vector_2D(m,0,x);
152 }
153
154 /** Set the transposed y basis vector of a 2D transform */
155 template < typename E, class A, class B, class L, class VecT > void
156 matrix_set_transposed_y_basis_vector_2D(matrix<E,A,B,L>& m,const VecT& y) {
157 matrix_set_transposed_basis_vector_2D(m,1,y);
158 }
159
160 /** Set the basis vectors of a 3D transform */
161 template < typename E, class A, class B, class L,
162 class VecT_1, class VecT_2, class VecT_3 > void
163 matrix_set_basis_vectors(
164 matrix<E,A,B,L>& m, const VecT_1& x, const VecT_2& y, const VecT_3& z)
165 {
166 matrix_set_x_basis_vector(m,x);
167 matrix_set_y_basis_vector(m,y);
168 matrix_set_z_basis_vector(m,z);
169 }
170
171 /** Set the transposed basis vectors of a 3D transform */
172 template < typename E, class A, class B, class L,
173 class VecT_1, class VecT_2, class VecT_3 > void
174 matrix_set_transposed_basis_vectors(
175 matrix<E,A,B,L>& m, const VecT_1& x, const VecT_2& y, const VecT_3& z)
176 {
177 matrix_set_transposed_x_basis_vector(m,x);
178 matrix_set_transposed_y_basis_vector(m,y);
179 matrix_set_transposed_z_basis_vector(m,z);
180 }
181
182 /** Set the basis vectors of a 2D transform */
183 template < typename E,class A,class B,class L,class VecT_1,class VecT_2 > void
184 matrix_set_basis_vectors_2D(
185 matrix<E,A,B,L>& m, const VecT_1& x, const VecT_2& y)
186 {
187 matrix_set_x_basis_vector_2D(m,x);
188 matrix_set_y_basis_vector_2D(m,y);
189 }
190
191 /** Set the transposed basis vectors of a 2D transform */
192 template < typename E,class A,class B,class L,class VecT_1,class VecT_2 > void
193 matrix_set_transposed_basis_vectors_2D(
194 matrix<E,A,B,L>& m, const VecT_1& x, const VecT_2& y)
195 {
196 matrix_set_transposed_x_basis_vector_2D(m,x);
197 matrix_set_transposed_y_basis_vector_2D(m,y);
198 }
199
200 //////////////////////////////////////////////////////////////////////////////
201 // Functions for getting the basis vectors of a 3D or 2D transform matrix
202 //////////////////////////////////////////////////////////////////////////////
203
204 #define TEMP_VEC3 vector< typename MatT::value_type, fixed<3> >
205 #define TEMP_VEC2 vector< typename MatT::value_type, fixed<2> >
206
207 /** Get the i'th basis vector of a 3D transform */
208 template < class MatT > TEMP_VEC3
209 matrix_get_basis_vector(const MatT& m, size_t i)
210 {
211 typedef TEMP_VEC3 vector_type;
212
213 /* Checking */
214 detail::CheckMatLinear3D(m);
215 detail::CheckIndex3(i);
216
217 return vector_type(
218 m.basis_element(i,0), m.basis_element(i,1), m.basis_element(i,2));
219 }
220
221 /** Get the i'th transposed basis vector of a 3D transform */
222 template < class MatT > TEMP_VEC3
223 matrix_get_transposed_basis_vector(const MatT& m, size_t i)
224 {
225 typedef typename MatT::value_type value_type;
226 typedef vector< value_type, fixed<3> > vector_type;
227
228 /* Checking */
229 detail::CheckMatLinear3D(m);
230 detail::CheckIndex3(i);
231
232 return vector_type(
233 m.basis_element(0,i), m.basis_element(1,i), m.basis_element(2,i));
234 }
235
236 /** Get the i'th basis vector of a 2D transform */
237 template < class MatT > TEMP_VEC2
238 matrix_get_basis_vector_2D(const MatT& m, size_t i)
239 {
240 typedef TEMP_VEC2 vector_type;
241
242 /* Checking */
243 detail::CheckMatLinear2D(m);
244 detail::CheckIndex2(i);
245
246 return vector_type(m.basis_element(i,0), m.basis_element(i,1));
247 }
248
249 /** Get the i'th transposed basis vector of a 2D transform */
250 template < class MatT > TEMP_VEC2
251 matrix_get_transposed_basis_vector_2D(const MatT& m, size_t i)
252 {
253 typedef TEMP_VEC2 vector_type;
254
255 /* Checking */
256 detail::CheckMatLinear2D(m);
257 detail::CheckIndex2(i);
258
259 return vector_type(m.basis_element(0,i), m.basis_element(1,i));
260 }
261
262 /** Get the x basis vector of a 3D transform */
263 template < class MatT > TEMP_VEC3
264 matrix_get_x_basis_vector(const MatT& m) {
265 return matrix_get_basis_vector(m,0);
266 }
267
268 /** Get the y basis vector of a 3D transform */
269 template < class MatT > TEMP_VEC3
270 matrix_get_y_basis_vector(const MatT& m) {
271 return matrix_get_basis_vector(m,1);
272 }
273
274 /** Get the z basis vector of a 3D transform */
275 template < class MatT > TEMP_VEC3
276 matrix_get_z_basis_vector(const MatT& m) {
277 return matrix_get_basis_vector(m,2);
278 }
279
280 /** Get the transposed x basis vector of a 3D transform */
281 template < class MatT > TEMP_VEC3
282 matrix_get_transposed_x_basis_vector(const MatT& m) {
283 return matrix_get_transposed_basis_vector(m,0);
284 }
285
286 /** Get the transposed y basis vector of a 3D transform */
287 template < class MatT > TEMP_VEC3
288 matrix_get_transposed_y_basis_vector(const MatT& m) {
289 return matrix_get_transposed_basis_vector(m,1);
290 }
291
292 /** Get the transposed z basis vector of a 3D transform */
293 template < class MatT > TEMP_VEC3
294 matrix_get_transposed_z_basis_vector(const MatT& m) {
295 return matrix_get_transposed_basis_vector(m,2);
296 }
297
298 /** Get the x basis vector of a 2D transform */
299 template < class MatT > TEMP_VEC2
300 matrix_get_x_basis_vector_2D(const MatT& m) {
301 return matrix_get_basis_vector_2D(m,0);
302 }
303
304 /** Get the y basis vector of a 2D transform */
305 template < class MatT > TEMP_VEC2
306 matrix_get_y_basis_vector_2D(const MatT& m) {
307 return matrix_get_basis_vector_2D(m,1);
308 }
309
310 /** Get the transposed x basis vector of a 2D transform */
311 template < class MatT > TEMP_VEC2
312 matrix_get_transposed_x_basis_vector_2D(const MatT& m) {
313 return matrix_get_transposed_basis_vector_2D(m,0);
314 }
315
316 /** Get the transposed y basis vector of a 2D transform */
317 template < class MatT > TEMP_VEC2
318 matrix_get_transposed_y_basis_vector_2D(const MatT& m) {
319 return matrix_get_transposed_basis_vector_2D(m,1);
320 }
321
322 /** Get the basis vectors of a 3D transform */
323 template < class MatT, class E, class A > void
324 matrix_get_basis_vectors(
325 const MatT& m, vector<E,A>& x, vector<E,A>& y, vector<E,A>& z)
326 {
327 x = matrix_get_x_basis_vector(m);
328 y = matrix_get_y_basis_vector(m);
329 z = matrix_get_z_basis_vector(m);
330 }
331
332 /** Get the transposed basis vectors of a 3D transform */
333 template < class MatT, typename E, class A > void
334 matrix_get_transposed_basis_vectors(
335 const MatT& m, vector<E,A>& x, vector<E,A>& y, vector<E,A>& z)
336 {
337 x = matrix_get_transposed_x_basis_vector(m);
338 y = matrix_get_transposed_y_basis_vector(m);
339 z = matrix_get_transposed_z_basis_vector(m);
340 }
341
342 /** Get the basis vectors of a 2D transform */
343 template < class MatT, typename E, class A > void
344 matrix_get_basis_vectors_2D(const MatT& m,vector<E,A>& x,vector<E,A>& y)
345 {
346 x = matrix_get_x_basis_vector_2D(m);
347 y = matrix_get_y_basis_vector_2D(m);
348 }
349
350 /** Get the transposed basis vectors of a 2D transform */
351 template < class MatT, typename E, class A > void
352 matrix_get_transposed_basis_vectors_2D(
353 const MatT& m, vector<E,A>& x, vector<E,A>& y)
354 {
355 x = matrix_get_transposed_x_basis_vector_2D(m);
356 y = matrix_get_transposed_y_basis_vector_2D(m);
357 }
358
359 #undef TEMP_VEC3
360 #undef TEMP_VEC2
361
362 } // namespace cml
363
364 #endif
This page took 0.05574 seconds and 4 git commands to generate.