]>
Dogcows Code - chaz/yoink/blob - src/Moof/cml/mathlib/matrix_translation.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_translation_h
14 #define matrix_translation_h
16 #include <cml/mathlib/checking.h>
18 /* Functions for getting and setting the translation of a 3D or 2D affine
24 //////////////////////////////////////////////////////////////////////////////
25 // Functions for setting the translation of a 3D or 2D affine transform matrix
26 //////////////////////////////////////////////////////////////////////////////
28 /** Set the translation of a 3D affine transform */
29 template < typename E
, class A
, class B
, class L
> void
30 matrix_set_translation(matrix
<E
,A
,B
,L
>& m
, E x
, E y
, E z
)
33 detail::CheckMatAffine3D(m
);
35 m
.set_basis_element(3,0,x
);
36 m
.set_basis_element(3,1,y
);
37 m
.set_basis_element(3,2,z
);
40 /** Set the translation of a 3D affine transform with z set to 0 */
41 template < typename E
, class A
, class B
, class L
> void
42 matrix_set_translation(matrix
<E
,A
,B
,L
>& m
, E x
, E y
)
44 typedef matrix
<E
,A
,B
,L
> matrix_type
;
45 typedef typename
matrix_type::value_type value_type
;
47 matrix_set_translation(m
, x
, y
, value_type(0));
50 /** Set the translation of a 3D affine transform from a 3D or 2D vector */
51 template < typename E
, class A
, class B
, class L
, class VecT
> void
52 matrix_set_translation(matrix
<E
,A
,B
,L
>& m
, const VecT
& translation
)
55 detail::CheckVec2Or3(translation
);
57 if (translation
.size() == 3) {
58 matrix_set_translation(
59 m
,translation
[0], translation
[1], translation
[2]);
60 } else { // translation.size() == 2
61 matrix_set_translation(m
, translation
[0], translation
[1]);
65 /** Set the translation of a 2D affine transform */
66 template < typename E
, class A
, class B
, class L
> void
67 matrix_set_translation_2D(matrix
<E
,A
,B
,L
>& m
, E x
, E y
)
70 detail::CheckMatAffine2D(m
);
72 m
.set_basis_element(2,0,x
);
73 m
.set_basis_element(2,1,y
);
76 /** Set the translation of a 2D affine transform from a 2D vector */
77 template < typename E
, class A
, class B
, class L
, class VecT
> void
78 matrix_set_translation_2D(matrix
<E
,A
,B
,L
>& m
, const VecT
& translation
)
81 detail::CheckVec2(translation
);
83 matrix_set_translation_2D(m
, translation
[0], translation
[1]);
86 //////////////////////////////////////////////////////////////////////////////
87 // Functions for getting the translation of a 3D or 2D affine transform matrix
88 //////////////////////////////////////////////////////////////////////////////
90 /** Get the translation of a 3D affine transform */
91 template < class MatT
> vector
< typename
MatT::value_type
, fixed
<3> >
92 matrix_get_translation(const MatT
& m
)
94 typedef typename
MatT::value_type value_type
;
95 typedef vector
< value_type
, fixed
<3> > vector_type
;
98 detail::CheckMatAffine3D(m
);
101 m
.basis_element(3,0),
102 m
.basis_element(3,1),
107 /** Get the translation of a 2D affine transform */
108 template < class MatT
> vector
< typename
MatT::value_type
, fixed
<2> >
109 matrix_get_translation_2D(const MatT
& m
)
111 typedef typename
MatT::value_type value_type
;
112 typedef vector
< value_type
, fixed
<2> > vector_type
;
115 detail::CheckMatAffine2D(m
);
117 return vector_type(m
.basis_element(2,0), m
.basis_element(2,1));
120 //////////////////////////////////////////////////////////////////////////////
121 // Function for getting the translation of a 3D view matrix
122 //////////////////////////////////////////////////////////////////////////////
124 /** Get the translation of a 3D affine transform */
125 template < class MatT
> vector
< typename
MatT::value_type
, fixed
<3> >
126 matrix_get_view_translation(const MatT
& m
)
128 typedef typename
MatT::value_type value_type
;
129 typedef vector
< value_type
, fixed
<3> > vector_type
;
132 matrix_get_basis_vectors(m
,x
,y
,z
);
133 vector_type p
= matrix_get_translation(m
);
134 return vector_type(-dot(p
,x
),-dot(p
,y
),-dot(p
,z
));
This page took 0.045317 seconds and 4 git commands to generate.