matrix_translation.h

Go to the documentation of this file.
00001 /* -*- C++ -*- ------------------------------------------------------------
00002  
00003 Copyright (c) 2007 Jesse Anders and Demian Nave http://cmldev.net/
00004 
00005 The Configurable Math Library (CML) is distributed under the terms of the
00006 Boost Software License, v1.0 (see cml/LICENSE for details).
00007 
00008  *-----------------------------------------------------------------------*/
00013 #ifndef matrix_translation_h
00014 #define matrix_translation_h
00015 
00016 #include <cml/mathlib/checking.h>
00017 
00018 /* Functions for getting and setting the translation of a 3D or 2D affine
00019  * transform.
00020  */
00021 
00022 namespace cml {
00023 
00025 // Functions for setting the translation of a 3D or 2D affine transform matrix
00027 
00029 template < typename E, class A, class B, class L > void
00030 matrix_set_translation(matrix<E,A,B,L>& m, E x, E y, E z)
00031 {
00032     /* Checking */
00033     detail::CheckMatAffine3D(m);
00034     
00035     m.set_basis_element(3,0,x);
00036     m.set_basis_element(3,1,y);
00037     m.set_basis_element(3,2,z);
00038 }
00039 
00041 template < typename E, class A, class B, class L > void
00042 matrix_set_translation(matrix<E,A,B,L>& m, E x, E y)
00043 {
00044     typedef matrix<E,A,B,L> matrix_type;
00045     typedef typename matrix_type::value_type value_type;
00046     
00047     matrix_set_translation(m, x, y, value_type(0));
00048 }
00049 
00051 template < typename E, class A, class B, class L, class VecT > void
00052 matrix_set_translation(matrix<E,A,B,L>& m, const VecT& translation)
00053 {
00054     /* Checking */
00055     detail::CheckVec2Or3(translation);
00056     
00057     if (translation.size() == 3) {
00058         matrix_set_translation(
00059             m,translation[0], translation[1], translation[2]);
00060     } else { // translation.size() == 2
00061         matrix_set_translation(m, translation[0], translation[1]);
00062     }
00063 }
00064 
00066 template < typename E, class A, class B, class L > void
00067 matrix_set_translation_2D(matrix<E,A,B,L>& m, E x, E y)
00068 {
00069     /* Checking */
00070     detail::CheckMatAffine2D(m);
00071     
00072     m.set_basis_element(2,0,x);
00073     m.set_basis_element(2,1,y);
00074 }
00075 
00077 template < typename E, class A, class B, class L, class VecT > void
00078 matrix_set_translation_2D(matrix<E,A,B,L>& m, const VecT& translation)
00079 {
00080     /* Checking */
00081     detail::CheckVec2(translation);
00082     
00083     matrix_set_translation_2D(m, translation[0], translation[1]);
00084 }
00085 
00087 // Functions for getting the translation of a 3D or 2D affine transform matrix
00089 
00091 template < class MatT > vector< typename MatT::value_type, fixed<3> >
00092 matrix_get_translation(const MatT& m)
00093 {
00094     typedef typename MatT::value_type value_type;
00095     typedef vector< value_type, fixed<3> > vector_type;
00096 
00097     /* Checking */
00098     detail::CheckMatAffine3D(m);
00099     
00100     return vector_type(
00101         m.basis_element(3,0),
00102         m.basis_element(3,1),
00103         m.basis_element(3,2)
00104     );
00105 }
00106 
00108 template < class MatT > void
00109 matrix_get_translation(
00110     const MatT& m,
00111     typename MatT::value_type& t1,
00112     typename MatT::value_type& t2,
00113     typename MatT::value_type& t3
00114     )
00115 {
00116     typedef typename MatT::value_type value_type;
00117     typedef vector< value_type, fixed<3> > vector_type;
00118 
00119     /* Checking */
00120     detail::CheckMatAffine3D(m);
00121     
00122     t1 = m.basis_element(3,0);
00123     t2 = m.basis_element(3,1);
00124     t3 = m.basis_element(3,2);
00125 }
00126 
00128 template < class MatT > vector< typename MatT::value_type, fixed<2> >
00129 matrix_get_translation_2D(const MatT& m)
00130 {
00131     typedef typename MatT::value_type value_type;
00132     typedef vector< value_type, fixed<2> > vector_type;
00133 
00134     /* Checking */
00135     detail::CheckMatAffine2D(m);
00136     
00137     return vector_type(m.basis_element(2,0), m.basis_element(2,1));
00138 }
00139 
00141 template < class MatT > void
00142 matrix_get_translation_2D(
00143     const MatT& m,
00144     typename MatT::value_type& t1,
00145     typename MatT::value_type& t2
00146     )
00147 {
00148     typedef typename MatT::value_type value_type;
00149     typedef vector< value_type, fixed<2> > vector_type;
00150 
00151     /* Checking */
00152     detail::CheckMatAffine2D(m);
00153     
00154     t1 = m.basis_element(2,0);
00155     t2 = m.basis_element(2,1);
00156 }
00157 
00159 // Function for getting the translation of a 3D view matrix
00161 
00163 template < class MatT > vector< typename MatT::value_type, fixed<3> >
00164 matrix_get_view_translation(const MatT& m)
00165 {
00166     typedef typename MatT::value_type value_type;
00167     typedef vector< value_type, fixed<3> > vector_type;
00168     
00169     vector_type x, y, z;
00170     matrix_get_basis_vectors(m,x,y,z);
00171     vector_type p = matrix_get_translation(m);
00172     return vector_type(-dot(p,x),-dot(p,y),-dot(p,z));
00173 }
00174 
00175 } // namespace cml
00176 
00177 #endif

Generated on Sat Jul 18 19:35:22 2009 for CML 1.0 by  doxygen 1.5.9