]>
Dogcows Code - chaz/yoink/blob - src/moof/cml/mathlib/matrix_basis.h
1 /* -*- C++ -*- ------------------------------------------------------------
3 Copyright (c) 2007 Jesse Anders and Demian Nave http://cmldev.net/
5 The Configurable Math Library (CML) is distributed under the terms of the
6 Boost Software License, v1.0 (see cml/LICENSE for details).
8 *-----------------------------------------------------------------------*/
13 #ifndef matrix_basis_h
14 #define matrix_basis_h
16 #include <cml/mathlib/checking.h>
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).
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).
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.
30 * As with other matrix functions, the following template argument notation is
31 * used for conciseness:
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
41 //////////////////////////////////////////////////////////////////////////////
42 // Functions for setting the basis vectors of a 3D or 2D transform matrix
43 //////////////////////////////////////////////////////////////////////////////
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
)
50 detail::CheckMatLinear3D(m
);
52 detail::CheckIndex3(i
);
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]);
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
)
64 detail::CheckMatLinear3D(m
);
66 detail::CheckIndex3(i
);
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]);
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
)
78 detail::CheckMatLinear2D(m
);
80 detail::CheckIndex2(i
);
82 m
.set_basis_element(i
,0,v
[0]);
83 m
.set_basis_element(i
,1,v
[1]);
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
)
92 detail::CheckMatLinear2D(m
);
94 detail::CheckIndex2(i
);
96 m
.set_basis_element(0,i
,v
[0]);
97 m
.set_basis_element(1,i
,v
[1]);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
)
166 matrix_set_x_basis_vector(m
,x
);
167 matrix_set_y_basis_vector(m
,y
);
168 matrix_set_z_basis_vector(m
,z
);
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
)
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
);
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
)
187 matrix_set_x_basis_vector_2D(m
,x
);
188 matrix_set_y_basis_vector_2D(m
,y
);
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
)
196 matrix_set_transposed_x_basis_vector_2D(m
,x
);
197 matrix_set_transposed_y_basis_vector_2D(m
,y
);
200 //////////////////////////////////////////////////////////////////////////////
201 // Functions for getting the basis vectors of a 3D or 2D transform matrix
202 //////////////////////////////////////////////////////////////////////////////
204 #define TEMP_VEC3 vector< typename MatT::value_type, fixed<3> >
205 #define TEMP_VEC2 vector< typename MatT::value_type, fixed<2> >
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
)
211 typedef TEMP_VEC3 vector_type
;
214 detail::CheckMatLinear3D(m
);
215 detail::CheckIndex3(i
);
218 m
.basis_element(i
,0), m
.basis_element(i
,1), m
.basis_element(i
,2));
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
)
225 typedef typename
MatT::value_type value_type
;
226 typedef vector
< value_type
, fixed
<3> > vector_type
;
229 detail::CheckMatLinear3D(m
);
230 detail::CheckIndex3(i
);
233 m
.basis_element(0,i
), m
.basis_element(1,i
), m
.basis_element(2,i
));
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
)
240 typedef TEMP_VEC2 vector_type
;
243 detail::CheckMatLinear2D(m
);
244 detail::CheckIndex2(i
);
246 return vector_type(m
.basis_element(i
,0), m
.basis_element(i
,1));
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
)
253 typedef TEMP_VEC2 vector_type
;
256 detail::CheckMatLinear2D(m
);
257 detail::CheckIndex2(i
);
259 return vector_type(m
.basis_element(0,i
), m
.basis_element(1,i
));
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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
)
327 x
= matrix_get_x_basis_vector(m
);
328 y
= matrix_get_y_basis_vector(m
);
329 z
= matrix_get_z_basis_vector(m
);
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
)
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
);
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
)
346 x
= matrix_get_x_basis_vector_2D(m
);
347 y
= matrix_get_y_basis_vector_2D(m
);
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
)
355 x
= matrix_get_transposed_x_basis_vector_2D(m
);
356 y
= matrix_get_transposed_y_basis_vector_2D(m
);
This page took 0.05574 seconds and 4 git commands to generate.