123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460 |
- #ifndef BOOST_QVM_MAT_OPERATIONS_HPP_INCLUDED
- #define BOOST_QVM_MAT_OPERATIONS_HPP_INCLUDED
- /// Copyright (c) 2008-2021 Emil Dotchevski and Reverge Studios, Inc.
- /// Copyright (c) 2019 agate-pris
- /// Distributed under the Boost Software License, Version 1.0. (See accompanying
- /// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
- #include <boost/qvm/detail/mat_assign.hpp>
- #include <boost/qvm/mat_operations2.hpp>
- #include <boost/qvm/mat_operations3.hpp>
- #include <boost/qvm/mat_operations4.hpp>
- #include <boost/qvm/math.hpp>
- #include <boost/qvm/detail/determinant_impl.hpp>
- #include <boost/qvm/detail/cofactor_impl.hpp>
- #include <boost/qvm/detail/transp_impl.hpp>
- #include <boost/qvm/scalar_traits.hpp>
- #include <string>
- namespace boost { namespace qvm {
- namespace
- qvm_detail
- {
- BOOST_QVM_INLINE_CRITICAL
- void const *
- get_valid_ptr_mat_operations()
- {
- static int const obj=0;
- return &obj;
- }
- }
- ////////////////////////////////////////////////
- namespace
- qvm_to_string_detail
- {
- template <class T>
- std::string to_string( T const & x );
- }
- namespace
- qvm_detail
- {
- template <int R,int C>
- struct
- to_string_m_defined
- {
- static bool const value=false;
- };
- template <int I,int SizeMinusOne>
- struct
- to_string_matrix_elements
- {
- template <class A>
- static
- std::string
- f( A const & a )
- {
- using namespace qvm_to_string_detail;
- return
- ( (I%mat_traits<A>::cols)==0 ? '(' : ',' ) +
- to_string(mat_traits<A>::template read_element<I/mat_traits<A>::cols,I%mat_traits<A>::cols>(a)) +
- ( (I%mat_traits<A>::cols)==mat_traits<A>::cols-1 ? ")" : "" ) +
- to_string_matrix_elements<I+1,SizeMinusOne>::f(a);
- }
- };
- template <int SizeMinusOne>
- struct
- to_string_matrix_elements<SizeMinusOne,SizeMinusOne>
- {
- template <class A>
- static
- std::string
- f( A const & a )
- {
- using namespace qvm_to_string_detail;
- return
- ( (SizeMinusOne%mat_traits<A>::cols)==0 ? '(' : ',' ) +
- to_string(mat_traits<A>::template read_element<SizeMinusOne/mat_traits<A>::cols,SizeMinusOne%mat_traits<A>::cols>(a)) +
- ')';
- }
- };
- }
- template <class A>
- inline
- typename enable_if_c<
- is_mat<A>::value &&
- !qvm_detail::to_string_m_defined<mat_traits<A>::rows,mat_traits<A>::cols>::value,
- std::string>::type
- to_string( A const & a )
- {
- return "("+qvm_detail::to_string_matrix_elements<0,mat_traits<A>::rows*mat_traits<A>::cols-1>::f(a)+')';
- }
- ////////////////////////////////////////////////
- template <class A,class B,class Cmp>
- BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value && is_mat<B>::value &&
- mat_traits<A>::rows==mat_traits<B>::rows &&
- mat_traits<A>::cols==mat_traits<B>::cols,
- bool>::type
- cmp( A const & a, B const & b, Cmp f )
- {
- for( int i=0; i!=mat_traits<A>::rows; ++i )
- for( int j=0; j!=mat_traits<A>::cols; ++j )
- if( !f(
- mat_traits<A>::read_element_idx(i, j, a),
- mat_traits<B>::read_element_idx(i, j, b)) )
- return false;
- return true;
- }
- ////////////////////////////////////////////////
- namespace
- qvm_detail
- {
- template <int M,int N>
- struct
- convert_to_m_defined
- {
- static bool const value=false;
- };
- }
- template <class R,class A>
- BOOST_QVM_INLINE_TRIVIAL
- typename enable_if_c<
- is_mat<R>::value && is_mat<A>::value &&
- mat_traits<R>::rows==mat_traits<A>::rows &&
- mat_traits<R>::cols==mat_traits<A>::cols &&
- !qvm_detail::convert_to_m_defined<mat_traits<A>::rows,mat_traits<A>::cols>::value,
- R>::type
- convert_to( A const & a )
- {
- R r; assign(r,a);
- return r;
- }
- ////////////////////////////////////////////////
- namespace
- qvm_detail
- {
- template <int D>
- struct
- determinant_defined
- {
- static bool const value=false;
- };
- }
- template <class A>
- BOOST_QVM_INLINE_TRIVIAL
- typename enable_if_c<
- is_mat<A>::value &&
- mat_traits<A>::rows==mat_traits<A>::cols &&
- !qvm_detail::determinant_defined<mat_traits<A>::rows>::value,
- typename mat_traits<A>::scalar_type>::type
- determinant( A const & a )
- {
- return qvm_detail::determinant_impl(a);
- }
- ////////////////////////////////////////////////
- namespace
- qvm_detail
- {
- template <class T,int Dim>
- class
- identity_mat_
- {
- identity_mat_( identity_mat_ const & );
- identity_mat_ & operator=( identity_mat_ const & );
- ~identity_mat_();
- public:
- template <class R>
- BOOST_QVM_INLINE_TRIVIAL
- operator R() const
- {
- R r;
- assign(r,*this);
- return r;
- }
- };
- }
- template <class T,int Dim>
- struct
- mat_traits< qvm_detail::identity_mat_<T,Dim> >
- {
- typedef qvm_detail::identity_mat_<T,Dim> this_matrix;
- typedef T scalar_type;
- static int const rows=Dim;
- static int const cols=Dim;
- template <int Row,int Col>
- static
- BOOST_QVM_INLINE_CRITICAL
- scalar_type
- read_element( this_matrix const & /*x*/ )
- {
- BOOST_QVM_STATIC_ASSERT(Row>=0);
- BOOST_QVM_STATIC_ASSERT(Row<Dim);
- BOOST_QVM_STATIC_ASSERT(Col>=0);
- BOOST_QVM_STATIC_ASSERT(Col<Dim);
- return scalar_traits<scalar_type>::value(Row==Col);
- }
- static
- BOOST_QVM_INLINE_CRITICAL
- scalar_type
- read_element_idx( int row, int col, this_matrix const & /*x*/ )
- {
- BOOST_QVM_ASSERT(row>=0);
- BOOST_QVM_ASSERT(row<Dim);
- BOOST_QVM_ASSERT(col>=0);
- BOOST_QVM_ASSERT(col<Dim);
- return scalar_traits<scalar_type>::value(row==col);
- }
- };
- template <class T,int Dim>
- BOOST_QVM_INLINE_TRIVIAL
- qvm_detail::identity_mat_<T,Dim> const &
- identity_mat()
- {
- return *(qvm_detail::identity_mat_<T,Dim> const *)qvm_detail::get_valid_ptr_mat_operations();
- }
- template <class A>
- BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value &&
- mat_traits<A>::rows==mat_traits<A>::cols,
- void>::type
- set_identity( A & a )
- {
- assign(a,identity_mat<typename mat_traits<A>::scalar_type,mat_traits<A>::rows>());
- }
- ////////////////////////////////////////////////
- namespace
- qvm_detail
- {
- template <class T>
- struct
- projection_
- {
- T const _00;
- T const _11;
- T const _22;
- T const _23;
- T const _32;
- BOOST_QVM_INLINE_TRIVIAL
- projection_( T _00, T _11, T _22, T _23, T _32 ):
- _00(_00),
- _11(_11),
- _22(_22),
- _23(_23),
- _32(_32)
- {
- }
- template <class R>
- BOOST_QVM_INLINE_TRIVIAL
- operator R() const
- {
- R r;
- assign(r,*this);
- return r;
- }
- };
- template <int Row,int Col>
- struct
- projection_get
- {
- template <class T>
- static
- BOOST_QVM_INLINE_CRITICAL
- T
- get( projection_<T> const & )
- {
- return scalar_traits<T>::value(0);
- }
- };
- template <> struct projection_get<0,0> { template <class T> static BOOST_QVM_INLINE_CRITICAL T get( projection_<T> const & m ) { return m._00; } };
- template <> struct projection_get<1,1> { template <class T> static BOOST_QVM_INLINE_CRITICAL T get( projection_<T> const & m ) { return m._11; } };
- template <> struct projection_get<2,2> { template <class T> static BOOST_QVM_INLINE_CRITICAL T get( projection_<T> const & m ) { return m._22; } };
- template <> struct projection_get<2,3> { template <class T> static BOOST_QVM_INLINE_CRITICAL T get( projection_<T> const & m ) { return m._23; } };
- template <> struct projection_get<3,2> { template <class T> static BOOST_QVM_INLINE_CRITICAL T get( projection_<T> const & m ) { return m._32; } };
- }
- template <class T>
- struct
- mat_traits< qvm_detail::projection_<T> >
- {
- typedef qvm_detail::projection_<T> this_matrix;
- typedef T scalar_type;
- static int const rows=4;
- static int const cols=4;
- template <int Row,int Col>
- static
- BOOST_QVM_INLINE_CRITICAL
- scalar_type
- read_element( this_matrix const & x )
- {
- BOOST_QVM_STATIC_ASSERT(Row>=0);
- BOOST_QVM_STATIC_ASSERT(Row<rows);
- BOOST_QVM_STATIC_ASSERT(Col>=0);
- BOOST_QVM_STATIC_ASSERT(Col<cols);
- return qvm_detail::projection_get<Row,Col>::get(x);
- }
- };
- template <class T>
- qvm_detail::projection_<T>
- BOOST_QVM_INLINE_OPERATIONS
- perspective_lh( T fov_y, T aspect_ratio, T z_near, T z_far )
- {
- T const one = scalar_traits<T>::value(1);
- T const ys = one/tan<T>(fov_y/scalar_traits<T>::value(2));
- T const xs = ys/aspect_ratio;
- T const zd = z_far-z_near;
- T const z1 = z_far/zd;
- T const z2 = -z_near*z1;
- return qvm_detail::projection_<T>(xs,ys,z1,z2,one);
- }
- template <class T>
- qvm_detail::projection_<T>
- BOOST_QVM_INLINE_OPERATIONS
- perspective_rh( T fov_y, T aspect_ratio, T z_near, T z_far )
- {
- T const one = scalar_traits<T>::value(1);
- T const ys = one/tan<T>(fov_y/scalar_traits<T>::value(2));
- T const xs = ys/aspect_ratio;
- T const zd = z_near-z_far;
- T const z1 = z_far/zd;
- T const z2 = z_near*z1;
- return qvm_detail::projection_<T>(xs,ys,z1,z2,-one);
- }
- ////////////////////////////////////////////////
- namespace
- qvm_detail
- {
- template <class OriginalType,class Scalar>
- class
- matrix_scalar_cast_
- {
- matrix_scalar_cast_( matrix_scalar_cast_ const & );
- matrix_scalar_cast_ & operator=( matrix_scalar_cast_ const & );
- ~matrix_scalar_cast_();
- public:
- template <class T>
- BOOST_QVM_INLINE_TRIVIAL
- matrix_scalar_cast_ &
- operator=( T const & x )
- {
- assign(*this,x);
- return *this;
- }
- template <class R>
- BOOST_QVM_INLINE_TRIVIAL
- operator R() const
- {
- R r;
- assign(r,*this);
- return r;
- }
- };
- template <bool> struct scalar_cast_matrix_filter { };
- template <> struct scalar_cast_matrix_filter<true> { typedef int type; };
- }
- template <class OriginalType,class Scalar>
- struct
- mat_traits< qvm_detail::matrix_scalar_cast_<OriginalType,Scalar> >
- {
- typedef Scalar scalar_type;
- typedef qvm_detail::matrix_scalar_cast_<OriginalType,Scalar> this_matrix;
- static int const rows=mat_traits<OriginalType>::rows;
- static int const cols=mat_traits<OriginalType>::cols;
- template <int Row,int Col>
- static
- BOOST_QVM_INLINE_CRITICAL
- scalar_type
- read_element( this_matrix const & x )
- {
- BOOST_QVM_STATIC_ASSERT(Row>=0);
- BOOST_QVM_STATIC_ASSERT(Row<rows);
- BOOST_QVM_STATIC_ASSERT(Col>=0);
- BOOST_QVM_STATIC_ASSERT(Col<cols);
- return scalar_type(mat_traits<OriginalType>::template read_element<Row,Col>(reinterpret_cast<OriginalType const &>(x)));
- }
- static
- BOOST_QVM_INLINE_CRITICAL
- scalar_type
- read_element_idx( int row, int col, this_matrix const & x )
- {
- BOOST_QVM_ASSERT(row>=0);
- BOOST_QVM_ASSERT(row<rows);
- BOOST_QVM_ASSERT(col>=0);
- BOOST_QVM_ASSERT(col<cols);
- return scalar_type(mat_traits<OriginalType>::read_element_idx(col,row,reinterpret_cast<OriginalType const &>(x)));
- }
- };
- template <class OriginalType,class Scalar,int R,int C>
- struct
- deduce_mat<qvm_detail::matrix_scalar_cast_<OriginalType,Scalar>,R,C>
- {
- typedef mat<Scalar,R,C> type;
- };
- template <class Scalar,class T>
- BOOST_QVM_INLINE_TRIVIAL
- qvm_detail::matrix_scalar_cast_<T,Scalar> const &
- scalar_cast( T const & x, typename qvm_detail::scalar_cast_matrix_filter<is_mat<T>::value>::type=0 )
- {
- return reinterpret_cast<qvm_detail::matrix_scalar_cast_<T,Scalar> const &>(x);
- }
- ////////////////////////////////////////////////
- namespace
- qvm_detail
- {
- template <int M,int N>
- struct
- div_eq_ms_defined
- {
- static bool const value=false;
- };
- }
- template <class A,class B>
- BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value && is_scalar<B>::value &&
- !qvm_detail::div_eq_ms_defined<mat_traits<A>::rows,mat_traits<A>::cols>::value,
- A &>::type
- operator/=( A & a, B b )
- {
- for( int i=0; i!=mat_traits<A>::rows; ++i )
- for( int j=0; j!=mat_traits<A>::cols; ++j )
- mat_traits<A>::write_element_idx(i,j,a)/=b;
- return a;
- }
- ////////////////////////////////////////////////
- namespace
- qvm_detail
- {
- template <int M,int N>
- struct
- div_ms_defined
- {
- static bool const value=false;
- };
- }
- template <class A,class B>
- BOOST_QVM_INLINE_OPERATIONS
- typename lazy_enable_if_c<
- is_mat<A>::value && is_scalar<B>::value &&
- !qvm_detail::div_ms_defined<mat_traits<A>::rows,mat_traits<A>::cols>::value,
- deduce_mat2<A,B,mat_traits<A>::rows,mat_traits<A>::cols> >::type
- operator/( A const & a, B b )
- {
- typedef typename deduce_mat2<A,B,mat_traits<A>::rows,mat_traits<A>::cols>::type R;
- R r;
- for( int i=0; i!=mat_traits<A>::rows; ++i )
- for( int j=0; j!=mat_traits<A>::cols; ++j )
- mat_traits<R>::write_element_idx(i,j,r)=mat_traits<A>::read_element_idx(i,j,a)/b;
- return r;
- }
- ////////////////////////////////////////////////
- namespace
- qvm_detail
- {
- template <int M,int N>
- struct
- eq_mm_defined
- {
- static bool const value=false;
- };
- }
- template <class A,class B>
- BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value && is_mat<B>::value &&
- mat_traits<A>::rows==mat_traits<B>::rows &&
- mat_traits<A>::cols==mat_traits<B>::cols &&
- !qvm_detail::eq_mm_defined<mat_traits<A>::rows,mat_traits<A>::cols>::value,
- bool>::type
- operator==( A const & a, B const & b )
- {
- for( int i=0; i!=mat_traits<A>::rows; ++i )
- for( int j=0; j!=mat_traits<A>::cols; ++j )
- if( mat_traits<A>::read_element_idx(i,j,a)!=mat_traits<B>::read_element_idx(i,j,b) )
- return false;
- return true;
- }
- ////////////////////////////////////////////////
- namespace
- qvm_detail
- {
- template <int M,int N>
- struct
- minus_eq_mm_defined
- {
- static bool const value=false;
- };
- }
- template <class A,class B>
- BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value && is_mat<B>::value &&
- mat_traits<A>::rows==mat_traits<B>::rows &&
- mat_traits<A>::cols==mat_traits<B>::cols &&
- !qvm_detail::minus_eq_mm_defined<mat_traits<A>::rows,mat_traits<A>::cols>::value,
- A &>::type
- operator-=( A & a, B const & b )
- {
- for( int i=0; i!=mat_traits<A>::rows; ++i )
- for( int j=0; j!=mat_traits<A>::cols; ++j )
- mat_traits<A>::write_element_idx(i,j,a)-=mat_traits<B>::read_element_idx(i,j,b);
- return a;
- }
- ////////////////////////////////////////////////
- namespace
- qvm_detail
- {
- template <int M,int N>
- struct
- minus_m_defined
- {
- static bool const value=false;
- };
- }
- template <class A>
- BOOST_QVM_INLINE_OPERATIONS
- typename lazy_enable_if_c<
- is_mat<A>::value &&
- !qvm_detail::minus_m_defined<mat_traits<A>::rows,mat_traits<A>::cols>::value,
- deduce_mat<A> >::type
- operator-( A const & a )
- {
- typedef typename deduce_mat<A>::type R;
- R r;
- for( int i=0; i!=mat_traits<A>::rows; ++i )
- for( int j=0; j!=mat_traits<A>::cols; ++j )
- mat_traits<R>::write_element_idx(i,j,r)=-mat_traits<A>::read_element_idx(i,j,a);
- return r;
- }
- ////////////////////////////////////////////////
- namespace
- qvm_detail
- {
- template <int M,int N>
- struct
- minus_mm_defined
- {
- static bool const value=false;
- };
- }
- template <class A,class B>
- BOOST_QVM_INLINE_OPERATIONS
- typename lazy_enable_if_c<
- is_mat<A>::value && is_mat<B>::value &&
- mat_traits<A>::rows==mat_traits<B>::rows &&
- mat_traits<A>::cols==mat_traits<B>::cols &&
- !qvm_detail::minus_mm_defined<mat_traits<A>::rows,mat_traits<A>::cols>::value,
- deduce_mat2<A,B,mat_traits<A>::rows,mat_traits<A>::cols> >::type
- operator-( A const & a, B const & b )
- {
- typedef typename deduce_mat2<A,B,mat_traits<A>::rows,mat_traits<A>::cols>::type R;
- R r;
- for( int i=0; i!=mat_traits<A>::rows; ++i )
- for( int j=0; j!=mat_traits<A>::cols; ++j )
- mat_traits<R>::write_element_idx(i,j,r)=mat_traits<A>::read_element_idx(i,j,a)-mat_traits<B>::read_element_idx(i,j,b);
- return r;
- }
- ////////////////////////////////////////////////
- namespace
- qvm_detail
- {
- template <int D>
- struct
- mul_eq_mm_defined
- {
- static bool const value=false;
- };
- }
- template <class A,class B>
- BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value &&
- is_mat<B>::value &&
- mat_traits<A>::rows==mat_traits<A>::cols &&
- mat_traits<A>::rows==mat_traits<B>::rows &&
- mat_traits<A>::cols==mat_traits<B>::cols &&
- !qvm_detail::mul_eq_mm_defined<mat_traits<A>::rows>::value,
- A &>::type
- operator*=( A & r, B const & b )
- {
- typedef typename mat_traits<A>::scalar_type Ta;
- Ta a[mat_traits<A>::rows][mat_traits<A>::cols];
- for( int i=0; i<mat_traits<A>::rows; ++i )
- for( int j=0; j<mat_traits<B>::cols; ++j )
- a[i][j]=mat_traits<A>::read_element_idx(i,j,r);
- for( int i=0; i<mat_traits<A>::rows; ++i )
- for( int j=0; j<mat_traits<B>::cols; ++j )
- {
- Ta x(scalar_traits<Ta>::value(0));
- for( int k=0; k<mat_traits<A>::cols; ++k )
- x += a[i][k]*mat_traits<B>::read_element_idx(k,j,b);
- mat_traits<A>::write_element_idx(i,j,r) = x;
- }
- return r;
- }
- ////////////////////////////////////////////////
- namespace
- qvm_detail
- {
- template <int M,int N>
- struct
- mul_eq_ms_defined
- {
- static bool const value=false;
- };
- }
- template <class A,class B>
- BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value && is_scalar<B>::value &&
- !qvm_detail::mul_eq_ms_defined<mat_traits<A>::rows,mat_traits<A>::cols>::value,
- A &>::type
- operator*=( A & a, B b )
- {
- for( int i=0; i!=mat_traits<A>::rows; ++i )
- for( int j=0; j!=mat_traits<A>::cols; ++j )
- mat_traits<A>::write_element_idx(i,j,a)*=b;
- return a;
- }
- ////////////////////////////////////////////////
- namespace
- qvm_detail
- {
- template <int R,int /*CR*/,int C>
- struct
- mul_mm_defined
- {
- static bool const value=false;
- };
- }
- template <class A,class B>
- BOOST_QVM_INLINE_OPERATIONS
- typename lazy_enable_if_c<
- is_mat<A>::value && is_mat<B>::value &&
- mat_traits<A>::cols==mat_traits<B>::rows &&
- !qvm_detail::mul_mm_defined<mat_traits<A>::rows,mat_traits<A>::cols,mat_traits<B>::cols>::value,
- deduce_mat2<A,B,mat_traits<A>::rows,mat_traits<B>::cols> >::type
- operator*( A const & a, B const & b )
- {
- typedef typename deduce_mat2<A,B,mat_traits<A>::rows,mat_traits<B>::cols>::type R;
- R r;
- for( int i=0; i<mat_traits<A>::rows; ++i )
- for( int j=0; j<mat_traits<B>::cols; ++j )
- {
- typedef typename mat_traits<A>::scalar_type Ta;
- Ta x(scalar_traits<Ta>::value(0));
- for( int k=0; k<mat_traits<A>::cols; ++k )
- x += mat_traits<A>::read_element_idx(i,k,a)*mat_traits<B>::read_element_idx(k,j,b);
- mat_traits<R>::write_element_idx(i,j,r) = x;
- }
- return r;
- }
- ////////////////////////////////////////////////
- namespace
- qvm_detail
- {
- template <int M,int N>
- struct
- mul_ms_defined
- {
- static bool const value=false;
- };
- }
- template <class A,class B>
- BOOST_QVM_INLINE_OPERATIONS
- typename lazy_enable_if_c<
- is_mat<A>::value && is_scalar<B>::value &&
- !qvm_detail::mul_ms_defined<mat_traits<A>::rows,mat_traits<A>::cols>::value,
- deduce_mat2<A,B,mat_traits<A>::rows,mat_traits<A>::cols> >::type
- operator*( A const & a, B b )
- {
- typedef typename deduce_mat2<A,B,mat_traits<A>::rows,mat_traits<A>::cols>::type R;
- R r;
- for( int i=0; i!=mat_traits<A>::rows; ++i )
- for( int j=0; j!=mat_traits<A>::cols; ++j )
- mat_traits<R>::write_element_idx(i,j,r)=mat_traits<A>::read_element_idx(i,j,a)*b;
- return r;
- }
- ////////////////////////////////////////////////
- namespace
- qvm_detail
- {
- template <int M,int N>
- struct
- mul_sm_defined
- {
- static bool const value=false;
- };
- }
- template <class A,class B>
- BOOST_QVM_INLINE_OPERATIONS
- typename lazy_enable_if_c<
- is_scalar<A>::value && is_mat<B>::value &&
- !qvm_detail::mul_sm_defined<mat_traits<B>::rows,mat_traits<B>::cols>::value,
- deduce_mat2<A,B,mat_traits<B>::rows,mat_traits<B>::cols> >::type
- operator*( A a, B const & b )
- {
- typedef typename deduce_mat2<A,B,mat_traits<B>::rows,mat_traits<B>::cols>::type R;
- R r;
- for( int i=0; i!=mat_traits<B>::rows; ++i )
- for( int j=0; j!=mat_traits<B>::cols; ++j )
- mat_traits<R>::write_element_idx(i,j,r)=a*mat_traits<B>::read_element_idx(i,j,b);
- return r;
- }
- ////////////////////////////////////////////////
- namespace
- qvm_detail
- {
- template <int M,int N>
- struct
- neq_mm_defined
- {
- static bool const value=false;
- };
- }
- template <class A,class B>
- BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value && is_mat<B>::value &&
- mat_traits<A>::rows==mat_traits<B>::rows &&
- mat_traits<A>::cols==mat_traits<B>::cols &&
- !qvm_detail::neq_mm_defined<mat_traits<A>::rows,mat_traits<A>::cols>::value,
- bool>::type
- operator!=( A const & a, B const & b )
- {
- for( int i=0; i!=mat_traits<A>::rows; ++i )
- for( int j=0; j!=mat_traits<A>::cols; ++j )
- if( mat_traits<A>::read_element_idx(i,j,a)!=mat_traits<B>::read_element_idx(i,j,b) )
- return true;
- return false;
- }
- ////////////////////////////////////////////////
- namespace
- qvm_detail
- {
- template <int M,int N>
- struct
- plus_eq_mm_defined
- {
- static bool const value=false;
- };
- }
- template <class A,class B>
- BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value && is_mat<B>::value &&
- mat_traits<A>::rows==mat_traits<B>::rows &&
- mat_traits<A>::cols==mat_traits<B>::cols &&
- !qvm_detail::plus_eq_mm_defined<mat_traits<A>::rows,mat_traits<A>::cols>::value,
- A &>::type
- operator+=( A & a, B const & b )
- {
- for( int i=0; i!=mat_traits<A>::rows; ++i )
- for( int j=0; j!=mat_traits<A>::cols; ++j )
- mat_traits<A>::write_element_idx(i,j,a)+=mat_traits<B>::read_element_idx(i,j,b);
- return a;
- }
- ////////////////////////////////////////////////
- namespace
- qvm_detail
- {
- template <int M,int N>
- struct
- plus_mm_defined
- {
- static bool const value=false;
- };
- }
- template <class A,class B>
- BOOST_QVM_INLINE_OPERATIONS
- typename lazy_enable_if_c<
- is_mat<A>::value && is_mat<B>::value &&
- mat_traits<A>::rows==mat_traits<B>::rows &&
- mat_traits<A>::cols==mat_traits<B>::cols &&
- !qvm_detail::plus_mm_defined<mat_traits<A>::rows,mat_traits<A>::cols>::value,
- deduce_mat2<A,B,mat_traits<A>::rows,mat_traits<A>::cols> >::type
- operator+( A const & a, B const & b )
- {
- typedef typename deduce_mat2<A,B,mat_traits<A>::rows,mat_traits<A>::cols>::type R;
- R r;
- for( int i=0; i!=mat_traits<A>::rows; ++i )
- for( int j=0; j!=mat_traits<A>::cols; ++j )
- mat_traits<R>::write_element_idx(i,j,r)=mat_traits<A>::read_element_idx(i,j,a)+mat_traits<B>::read_element_idx(i,j,b);
- return r;
- }
- ////////////////////////////////////////////////
- namespace
- qvm_detail
- {
- template <class T>
- class
- mref_
- {
- mref_( mref_ const & );
- mref_ & operator=( mref_ const & );
- ~mref_();
- public:
- template <class R>
- BOOST_QVM_INLINE_TRIVIAL
- mref_ &
- operator=( R const & x )
- {
- assign(*this,x);
- return *this;
- }
- template <class R>
- BOOST_QVM_INLINE_TRIVIAL
- operator R() const
- {
- R r;
- assign(r,*this);
- return r;
- }
- };
- }
- template <class M>
- struct
- mat_traits< qvm_detail::mref_<M> >
- {
- typedef typename mat_traits<M>::scalar_type scalar_type;
- typedef qvm_detail::mref_<M> this_matrix;
- static int const rows=mat_traits<M>::rows;
- static int const cols=mat_traits<M>::cols;
- template <int Row,int Col>
- static
- BOOST_QVM_INLINE_CRITICAL
- scalar_type
- read_element( this_matrix const & x )
- {
- BOOST_QVM_STATIC_ASSERT(Row>=0);
- BOOST_QVM_STATIC_ASSERT(Row<rows);
- BOOST_QVM_STATIC_ASSERT(Col>=0);
- BOOST_QVM_STATIC_ASSERT(Col<cols);
- return mat_traits<M>::template read_element<Row,Col>(reinterpret_cast<M const &>(x));
- }
- template <int Row,int Col>
- static
- BOOST_QVM_INLINE_CRITICAL
- scalar_type &
- write_element( this_matrix & x )
- {
- BOOST_QVM_STATIC_ASSERT(Row>=0);
- BOOST_QVM_STATIC_ASSERT(Row<rows);
- BOOST_QVM_STATIC_ASSERT(Col>=0);
- BOOST_QVM_STATIC_ASSERT(Col<cols);
- return mat_traits<M>::template write_element<Row,Col>(reinterpret_cast<M &>(x));
- }
- static
- BOOST_QVM_INLINE_CRITICAL
- scalar_type
- read_element_idx( int row, int col, this_matrix const & x )
- {
- BOOST_QVM_ASSERT(row>=0);
- BOOST_QVM_ASSERT(row<rows);
- BOOST_QVM_ASSERT(col>=0);
- BOOST_QVM_ASSERT(col<cols);
- return mat_traits<M>::read_element_idx(row,col,reinterpret_cast<M const &>(x));
- }
- static
- BOOST_QVM_INLINE_CRITICAL
- scalar_type &
- write_element_idx( int row, int col, this_matrix & x )
- {
- BOOST_QVM_ASSERT(row>=0);
- BOOST_QVM_ASSERT(row<rows);
- BOOST_QVM_ASSERT(col>=0);
- BOOST_QVM_ASSERT(col<cols);
- return mat_traits<M>::write_element_idx(row,col,reinterpret_cast<M &>(x));
- }
- };
- template <class M,int R,int C>
- struct
- deduce_mat<qvm_detail::mref_<M>,R,C>
- {
- typedef mat<typename mat_traits<M>::scalar_type,R,C> type;
- };
- template <class M>
- BOOST_QVM_INLINE_TRIVIAL
- typename enable_if_c<
- is_mat<M>::value,
- qvm_detail::mref_<M> const &>::type
- mref( M const & a )
- {
- return reinterpret_cast<qvm_detail::mref_<M> const &>(a);
- }
- template <class M>
- BOOST_QVM_INLINE_TRIVIAL
- typename enable_if_c<
- is_mat<M>::value,
- qvm_detail::mref_<M> &>::type
- mref( M & a )
- {
- return reinterpret_cast<qvm_detail::mref_<M> &>(a);
- }
- ////////////////////////////////////////////////
- namespace
- qvm_detail
- {
- template <class T,int Rows,int Cols>
- class
- zero_mat_
- {
- zero_mat_( zero_mat_ const & );
- zero_mat_ & operator=( zero_mat_ const & );
- ~zero_mat_();
- public:
- template <class R>
- BOOST_QVM_INLINE_TRIVIAL
- operator R() const
- {
- R r;
- assign(r,*this);
- return r;
- }
- };
- }
- template <class T,int Rows,int Cols>
- struct
- mat_traits< qvm_detail::zero_mat_<T,Rows,Cols> >
- {
- typedef qvm_detail::zero_mat_<T,Rows,Cols> this_matrix;
- typedef T scalar_type;
- static int const rows=Rows;
- static int const cols=Cols;
- template <int Row,int Col>
- static
- BOOST_QVM_INLINE_CRITICAL
- scalar_type
- read_element( this_matrix const & )
- {
- BOOST_QVM_STATIC_ASSERT(Row>=0);
- BOOST_QVM_STATIC_ASSERT(Row<Rows);
- BOOST_QVM_STATIC_ASSERT(Col>=0);
- BOOST_QVM_STATIC_ASSERT(Col<Cols);
- return scalar_traits<scalar_type>::value(0);
- }
- static
- BOOST_QVM_INLINE_CRITICAL
- scalar_type
- read_element_idx( int row, int col, this_matrix const & )
- {
- BOOST_QVM_ASSERT(row>=0);
- BOOST_QVM_ASSERT(row<rows);
- BOOST_QVM_ASSERT(col>=0);
- BOOST_QVM_ASSERT(col<cols);
- return scalar_traits<scalar_type>::value(0);
- }
- };
- template <class T,int Rows,int Cols,int R,int C>
- struct
- deduce_mat<qvm_detail::zero_mat_<T,Rows,Cols>,R,C>
- {
- typedef mat<T,R,C> type;
- };
- template <class T,int Rows,int Cols>
- BOOST_QVM_INLINE_TRIVIAL
- qvm_detail::zero_mat_<T,Rows,Cols> const &
- zero_mat()
- {
- return *(qvm_detail::zero_mat_<T,Rows,Cols> const *)qvm_detail::get_valid_ptr_mat_operations();
- }
- template <class T,int Dim>
- BOOST_QVM_INLINE_TRIVIAL
- qvm_detail::zero_mat_<T,Dim,Dim> const &
- zero_mat()
- {
- return *(qvm_detail::zero_mat_<T,Dim,Dim> const *)qvm_detail::get_valid_ptr_mat_operations();
- }
- template <class A>
- BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value,
- void>::type
- set_zero( A & a )
- {
- assign(a,zero_mat<typename mat_traits<A>::scalar_type,mat_traits<A>::rows,mat_traits<A>::cols>());
- }
- ////////////////////////////////////////////////
- namespace
- qvm_detail
- {
- template <int D,class S>
- struct
- rot_mat_
- {
- typedef S scalar_type;
- scalar_type a[3][3];
- BOOST_QVM_INLINE
- rot_mat_(
- scalar_type a00, scalar_type a01, scalar_type a02,
- scalar_type a10, scalar_type a11, scalar_type a12,
- scalar_type a20, scalar_type a21, scalar_type a22 )
- {
- a[0][0] = a00;
- a[0][1] = a01;
- a[0][2] = a02;
- a[1][0] = a10;
- a[1][1] = a11;
- a[1][2] = a12;
- a[2][0] = a20;
- a[2][1] = a21;
- a[2][2] = a22;
- }
- template <class R>
- BOOST_QVM_INLINE_TRIVIAL
- operator R() const
- {
- R r;
- assign(r,*this);
- return r;
- }
- };
- template <int Row,int Col>
- struct
- rot_m_get
- {
- template <class T>
- static
- BOOST_QVM_INLINE_CRITICAL
- T
- get( T const (&)[3][3] )
- {
- return scalar_traits<T>::value(Row==Col);
- }
- };
- template <> struct rot_m_get<0,0> { template <class T> static BOOST_QVM_INLINE_CRITICAL T get( T const (&a)[3][3] ) { return a[0][0]; } };
- template <> struct rot_m_get<0,1> { template <class T> static BOOST_QVM_INLINE_CRITICAL T get( T const (&a)[3][3] ) { return a[0][1]; } };
- template <> struct rot_m_get<0,2> { template <class T> static BOOST_QVM_INLINE_CRITICAL T get( T const (&a)[3][3] ) { return a[0][2]; } };
- template <> struct rot_m_get<1,0> { template <class T> static BOOST_QVM_INLINE_CRITICAL T get( T const (&a)[3][3] ) { return a[1][0]; } };
- template <> struct rot_m_get<1,1> { template <class T> static BOOST_QVM_INLINE_CRITICAL T get( T const (&a)[3][3] ) { return a[1][1]; } };
- template <> struct rot_m_get<1,2> { template <class T> static BOOST_QVM_INLINE_CRITICAL T get( T const (&a)[3][3] ) { return a[1][2]; } };
- template <> struct rot_m_get<2,0> { template <class T> static BOOST_QVM_INLINE_CRITICAL T get( T const (&a)[3][3] ) { return a[2][0]; } };
- template <> struct rot_m_get<2,1> { template <class T> static BOOST_QVM_INLINE_CRITICAL T get( T const (&a)[3][3] ) { return a[2][1]; } };
- template <> struct rot_m_get<2,2> { template <class T> static BOOST_QVM_INLINE_CRITICAL T get( T const (&a)[3][3] ) { return a[2][2]; } };
- }
- template <class M>
- struct mat_traits;
- template <int D,class S>
- struct
- mat_traits< qvm_detail::rot_mat_<D,S> >
- {
- typedef qvm_detail::rot_mat_<D,S> this_matrix;
- typedef typename this_matrix::scalar_type scalar_type;
- static int const rows=D;
- static int const cols=D;
- template <int Row,int Col>
- static
- BOOST_QVM_INLINE_CRITICAL
- scalar_type
- read_element( this_matrix const & x )
- {
- BOOST_QVM_STATIC_ASSERT(Row>=0);
- BOOST_QVM_STATIC_ASSERT(Row<D);
- BOOST_QVM_STATIC_ASSERT(Col>=0);
- BOOST_QVM_STATIC_ASSERT(Col<D);
- return qvm_detail::rot_m_get<Row,Col>::get(x.a);
- }
- static
- BOOST_QVM_INLINE_CRITICAL
- scalar_type
- read_element_idx( int row, int col, this_matrix const & x )
- {
- BOOST_QVM_ASSERT(row>=0);
- BOOST_QVM_ASSERT(row<D);
- BOOST_QVM_ASSERT(col>=0);
- BOOST_QVM_ASSERT(col<D);
- return row<3 && col<3?
- x.a[row][col] :
- scalar_traits<scalar_type>::value(row==col);
- }
- };
- template <int Dim,class V,class Angle>
- BOOST_QVM_INLINE
- typename enable_if_c<
- is_vec<V>::value && vec_traits<V>::dim==3,
- qvm_detail::rot_mat_<Dim,Angle> >::type
- rot_mat( V const & axis, Angle angle )
- {
- typedef Angle scalar_type;
- scalar_type const x=vec_traits<V>::template read_element<0>(axis);
- scalar_type const y=vec_traits<V>::template read_element<1>(axis);
- scalar_type const z=vec_traits<V>::template read_element<2>(axis);
- scalar_type const m2=x*x+y*y+z*z;
- if( m2==scalar_traits<scalar_type>::value(0) )
- BOOST_QVM_THROW_EXCEPTION(zero_magnitude_error());
- scalar_type const s = sin<scalar_type>(angle);
- scalar_type const c = cos<scalar_type>(angle);
- scalar_type const x2 = x*x;
- scalar_type const y2 = y*y;
- scalar_type const z2 = z*z;
- scalar_type const xy = x*y;
- scalar_type const xz = x*z;
- scalar_type const yz = y*z;
- scalar_type const xs = x*s;
- scalar_type const ys = y*s;
- scalar_type const zs = z*s;
- scalar_type const one = scalar_traits<scalar_type>::value(1);
- scalar_type const c1 = one-c;
- return qvm_detail::rot_mat_<Dim,Angle>(
- x2+(one-x2)*c, xy*c1-zs, xz*(one-c)+ys,
- xy*c1+zs, y2+(one-y2)*c, yz*c1-xs,
- xz*c1-ys, yz*c1+xs, z2+(one-z2)*c );
- }
- template <class A,class B,class Angle>
- BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value &&
- mat_traits<A>::rows==mat_traits<A>::cols &&
- mat_traits<A>::rows>=3 &&
- is_vec<B>::value && vec_traits<B>::dim==3,
- void>::type
- set_rot( A & a, B const & axis, Angle angle )
- {
- assign(a,rot_mat<mat_traits<A>::rows>(axis,angle));
- }
- template <class A,class B,class Angle>
- BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value &&
- mat_traits<A>::rows==mat_traits<A>::cols &&
- mat_traits<A>::rows>=3 &&
- is_vec<B>::value && vec_traits<B>::dim==3,
- void>::type
- rotate( A & a, B const & axis, Angle angle )
- {
- a *= rot_mat<mat_traits<A>::rows>(axis,angle);
- }
- ////////////////////////////////////////////////
- template <int Dim,class Angle>
- BOOST_QVM_INLINE
- qvm_detail::rot_mat_<Dim,Angle>
- rot_mat_xzy( Angle x1, Angle z2, Angle y3 )
- {
- typedef Angle scalar_type;
- scalar_type const c1 = cos<scalar_type>(x1);
- scalar_type const s1 = sin<scalar_type>(x1);
- scalar_type const c2 = cos<scalar_type>(z2);
- scalar_type const s2 = sin<scalar_type>(z2);
- scalar_type const c3 = cos<scalar_type>(y3);
- scalar_type const s3 = sin<scalar_type>(y3);
- return qvm_detail::rot_mat_<Dim,Angle>(
- c2*c3, -s2, c2*s3,
- s1*s3 + c1*c3*s2, c1*c2, c1*s2*s3 - c3*s1,
- c3*s1*s2 - c1*s3, c2*s1, c1*c3 + s1*s2*s3 );
- }
- template <class A,class Angle>
- BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value &&
- mat_traits<A>::rows==mat_traits<A>::cols &&
- mat_traits<A>::rows>=3,
- void>::type
- set_rot_xzy( A & a, Angle x1, Angle z2, Angle y3 )
- {
- assign(a,rot_mat_xzy<mat_traits<A>::rows>(x1,z2,y3));
- }
- template <class A,class Angle>
- BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value &&
- mat_traits<A>::rows==mat_traits<A>::cols &&
- mat_traits<A>::rows>=3,
- void>::type
- rotate_xzy( A & a, Angle x1, Angle z2, Angle y3 )
- {
- a *= rot_mat_xzy<mat_traits<A>::rows>(x1,z2,y3);
- }
- ////////////////////////////////////////////////
- template <int Dim,class Angle>
- BOOST_QVM_INLINE
- qvm_detail::rot_mat_<Dim,Angle>
- rot_mat_xyz( Angle x1, Angle y2, Angle z3 )
- {
- typedef Angle scalar_type;
- scalar_type const c1 = cos<scalar_type>(x1);
- scalar_type const s1 = sin<scalar_type>(x1);
- scalar_type const c2 = cos<scalar_type>(y2);
- scalar_type const s2 = sin<scalar_type>(y2);
- scalar_type const c3 = cos<scalar_type>(z3);
- scalar_type const s3 = sin<scalar_type>(z3);
- return qvm_detail::rot_mat_<Dim,Angle>(
- c2*c3, -c2*s3, s2,
- c1*s3 + c3*s1*s2, c1*c3 - s1*s2*s3, -c2*s1,
- s1*s3 - c1*c3*s2, c3*s1 + c1*s2*s3, c1*c2 );
- }
- template <class A,class Angle>
- BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value &&
- mat_traits<A>::rows==mat_traits<A>::cols &&
- mat_traits<A>::rows>=3,
- void>::type
- set_rot_xyz( A & a, Angle x1, Angle y2, Angle z3 )
- {
- assign(a,rot_mat_xyz<mat_traits<A>::rows>(x1,y2,z3));
- }
- template <class A,class Angle>
- BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value &&
- mat_traits<A>::rows==mat_traits<A>::cols &&
- mat_traits<A>::rows>=3,
- void>::type
- rotate_xyz( A & a, Angle x1, Angle y2, Angle z3 )
- {
- a *= rot_mat_xyz<mat_traits<A>::rows>(x1,y2,z3);
- }
- ////////////////////////////////////////////////
- template <int Dim,class Angle>
- BOOST_QVM_INLINE
- qvm_detail::rot_mat_<Dim,Angle>
- rot_mat_yxz( Angle y1, Angle x2, Angle z3 )
- {
- typedef Angle scalar_type;
- scalar_type const c1 = cos<scalar_type>(y1);
- scalar_type const s1 = sin<scalar_type>(y1);
- scalar_type const c2 = cos<scalar_type>(x2);
- scalar_type const s2 = sin<scalar_type>(x2);
- scalar_type const c3 = cos<scalar_type>(z3);
- scalar_type const s3 = sin<scalar_type>(z3);
- return qvm_detail::rot_mat_<Dim,Angle>(
- c1*c3 + s1*s2*s3, c3*s1*s2 - c1*s3, c2*s1,
- c2*s3, c2*c3, -s2,
- c1*s2*s3 - c3*s1, c1*c3*s2 + s1*s3, c1*c2 );
- }
- template <class A,class Angle>
- BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value &&
- mat_traits<A>::rows==mat_traits<A>::cols &&
- mat_traits<A>::rows>=3,
- void>::type
- set_rot_yxz( A & a, Angle y1, Angle x2, Angle z3 )
- {
- assign(a,rot_mat_yxz<mat_traits<A>::rows>(y1,x2,z3));
- }
- template <class A,class Angle>
- BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value &&
- mat_traits<A>::rows==mat_traits<A>::cols &&
- mat_traits<A>::rows>=3,
- void>::type
- rotate_yxz( A & a, Angle y1, Angle x2, Angle z3 )
- {
- a *= rot_mat_yxz<mat_traits<A>::rows>(y1,x2,z3);
- }
- ////////////////////////////////////////////////
- template <int Dim,class Angle>
- BOOST_QVM_INLINE
- qvm_detail::rot_mat_<Dim,Angle>
- rot_mat_yzx( Angle y1, Angle z2, Angle x3 )
- {
- typedef Angle scalar_type;
- scalar_type const c1 = cos<scalar_type>(y1);
- scalar_type const s1 = sin<scalar_type>(y1);
- scalar_type const c2 = cos<scalar_type>(z2);
- scalar_type const s2 = sin<scalar_type>(z2);
- scalar_type const c3 = cos<scalar_type>(x3);
- scalar_type const s3 = sin<scalar_type>(x3);
- return qvm_detail::rot_mat_<Dim,Angle>(
- c1*c2, s1*s3 - c1*c3*s2, c3*s1 + c1*s2*s3,
- s2, c2*c3, -c2*s3,
- -c2*s1, c1*s3 + c3*s1*s2, c1*c3 - s1*s2*s3 );
- }
- template <class A,class Angle>
- BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value &&
- mat_traits<A>::rows==mat_traits<A>::cols &&
- mat_traits<A>::rows>=3,
- void>::type
- set_rot_yzx( A & a, Angle y1, Angle z2, Angle x3 )
- {
- assign(a,rot_mat_yzx<mat_traits<A>::rows>(y1,z2,x3));
- }
- template <class A,class Angle>
- BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value &&
- mat_traits<A>::rows==mat_traits<A>::cols &&
- mat_traits<A>::rows>=3,
- void>::type
- rotate_yzx( A & a, Angle y1, Angle z2, Angle x3 )
- {
- a *= rot_mat_yzx<mat_traits<A>::rows>(y1,z2,x3);
- }
- ////////////////////////////////////////////////
- template <int Dim,class Angle>
- BOOST_QVM_INLINE
- qvm_detail::rot_mat_<Dim,Angle>
- rot_mat_zyx( Angle z1, Angle y2, Angle x3 )
- {
- typedef Angle scalar_type;
- scalar_type const c1 = cos<scalar_type>(z1);
- scalar_type const s1 = sin<scalar_type>(z1);
- scalar_type const c2 = cos<scalar_type>(y2);
- scalar_type const s2 = sin<scalar_type>(y2);
- scalar_type const c3 = cos<scalar_type>(x3);
- scalar_type const s3 = sin<scalar_type>(x3);
- return qvm_detail::rot_mat_<Dim,Angle>(
- c1*c2, c1*s2*s3 - c3*s1, s1*s3 + c1*c3*s2,
- c2*s1, c1*c3 + s1*s2*s3, c3*s1*s2 - c1*s3,
- -s2, c2*s3, c2*c3 );
- }
- template <class A,class Angle>
- BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value &&
- mat_traits<A>::rows==mat_traits<A>::cols &&
- mat_traits<A>::rows>=3,
- void>::type
- set_rot_zyx( A & a, Angle z1, Angle y2, Angle x3 )
- {
- assign(a,rot_mat_zyx<mat_traits<A>::rows>(z1,y2,x3));
- }
- template <class A,class Angle>
- BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value &&
- mat_traits<A>::rows==mat_traits<A>::cols &&
- mat_traits<A>::rows>=3,
- void>::type
- rotate_zyx( A & a, Angle z1, Angle y2, Angle x3 )
- {
- a *= rot_mat_zyx<mat_traits<A>::rows>(z1,y2,x3);
- }
- ////////////////////////////////////////////////
- template <int Dim,class Angle>
- BOOST_QVM_INLINE
- qvm_detail::rot_mat_<Dim,Angle>
- rot_mat_zxy( Angle z1, Angle x2, Angle y3 )
- {
- typedef Angle scalar_type;
- scalar_type const c1 = cos<scalar_type>(z1);
- scalar_type const s1 = sin<scalar_type>(z1);
- scalar_type const c2 = cos<scalar_type>(x2);
- scalar_type const s2 = sin<scalar_type>(x2);
- scalar_type const c3 = cos<scalar_type>(y3);
- scalar_type const s3 = sin<scalar_type>(y3);
- return qvm_detail::rot_mat_<Dim,Angle>(
- c1*c3 - s1*s2*s3, -c2*s1, c1*s3 + c3*s1*s2,
- c3*s1 + c1*s2*s3, c1*c2, s1*s3 - c1*c3*s2,
- -c2*s3, s2, c2*c3 );
- }
- template <class A,class Angle>
- BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value &&
- mat_traits<A>::rows==mat_traits<A>::cols &&
- mat_traits<A>::rows>=3,
- void>::type
- set_rot_zxy( A & a, Angle z1, Angle x2, Angle y3 )
- {
- assign(a,rot_mat_zxy<mat_traits<A>::rows>(z1,x2,y3));
- }
- template <class A,class Angle>
- BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value &&
- mat_traits<A>::rows==mat_traits<A>::cols &&
- mat_traits<A>::rows>=3,
- void>::type
- rotate_zxy( A & a, Angle z1, Angle x2, Angle y3 )
- {
- a *= rot_mat_zxy<mat_traits<A>::rows>(z1,x2,y3);
- }
- ////////////////////////////////////////////////
- template <int Dim,class Angle>
- BOOST_QVM_INLINE
- qvm_detail::rot_mat_<Dim,Angle>
- rot_mat_xzx( Angle x1, Angle z2, Angle x3 )
- {
- typedef Angle scalar_type;
- scalar_type const c1 = cos<scalar_type>(x1);
- scalar_type const s1 = sin<scalar_type>(x1);
- scalar_type const c2 = cos<scalar_type>(z2);
- scalar_type const s2 = sin<scalar_type>(z2);
- scalar_type const c3 = cos<scalar_type>(x3);
- scalar_type const s3 = sin<scalar_type>(x3);
- return qvm_detail::rot_mat_<Dim,Angle>(
- c2, -c3*s2, s2*s3,
- c1*s2, c1*c2*c3 - s1*s3, -c3*s1 - c1*c2*s3,
- s1*s2, c1*s3 + c2*c3*s1, c1*c3 - c2*s1*s3 );
- }
- template <class A,class Angle>
- BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value &&
- mat_traits<A>::rows==mat_traits<A>::cols &&
- mat_traits<A>::rows>=3,
- void>::type
- set_rot_xzx( A & a, Angle x1, Angle z2, Angle x3 )
- {
- assign(a,rot_mat_xzx<mat_traits<A>::rows>(x1,z2,x3));
- }
- template <class A,class Angle>
- BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value &&
- mat_traits<A>::rows==mat_traits<A>::cols &&
- mat_traits<A>::rows>=3,
- void>::type
- rotate_xzx( A & a, Angle x1, Angle z2, Angle x3 )
- {
- a *= rot_mat_xzx<mat_traits<A>::rows>(x1,z2,x3);
- }
- ////////////////////////////////////////////////
- template <int Dim,class Angle>
- BOOST_QVM_INLINE
- qvm_detail::rot_mat_<Dim,Angle>
- rot_mat_xyx( Angle x1, Angle y2, Angle x3 )
- {
- typedef Angle scalar_type;
- scalar_type const c1 = cos<scalar_type>(x1);
- scalar_type const s1 = sin<scalar_type>(x1);
- scalar_type const c2 = cos<scalar_type>(y2);
- scalar_type const s2 = sin<scalar_type>(y2);
- scalar_type const c3 = cos<scalar_type>(x3);
- scalar_type const s3 = sin<scalar_type>(x3);
- return qvm_detail::rot_mat_<Dim,Angle>(
- c2, s2*s3, c3*s2,
- s1*s2, c1*c3 - c2*s1*s3, -c1*s3 - c2*c3*s1,
- -c1*s2, c3*s1 + c1*c2*s3, c1*c2*c3 - s1*s3 );
- }
- template <class A,class Angle>
- BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value &&
- mat_traits<A>::rows==mat_traits<A>::cols &&
- mat_traits<A>::rows>=3,
- void>::type
- set_rot_xyx( A & a, Angle x1, Angle y2, Angle x3 )
- {
- assign(a,rot_mat_xyx<mat_traits<A>::rows>(x1,y2,x3));
- }
- template <class A,class Angle>
- BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value &&
- mat_traits<A>::rows==mat_traits<A>::cols &&
- mat_traits<A>::rows>=3,
- void>::type
- rotate_xyx( A & a, Angle x1, Angle y2, Angle x3 )
- {
- a *= rot_mat_xyx<mat_traits<A>::rows>(x1,y2,x3);
- }
- ////////////////////////////////////////////////
- template <int Dim,class Angle>
- BOOST_QVM_INLINE
- qvm_detail::rot_mat_<Dim,Angle>
- rot_mat_yxy( Angle y1, Angle x2, Angle y3 )
- {
- typedef Angle scalar_type;
- scalar_type const c1 = cos<scalar_type>(y1);
- scalar_type const s1 = sin<scalar_type>(y1);
- scalar_type const c2 = cos<scalar_type>(x2);
- scalar_type const s2 = sin<scalar_type>(x2);
- scalar_type const c3 = cos<scalar_type>(y3);
- scalar_type const s3 = sin<scalar_type>(y3);
- return qvm_detail::rot_mat_<Dim,Angle>(
- c1*c3 - c2*s1*s3, s1*s2, c1*s3 + c2*c3*s1,
- s2*s3, c2, -c3*s2,
- -c3*s1 - c1*c2*s3, c1*s2, c1*c2*c3 - s1*s3 );
- }
- template <class A,class Angle>
- BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value &&
- mat_traits<A>::rows==mat_traits<A>::cols &&
- mat_traits<A>::rows>=3,
- void>::type
- set_rot_yxy( A & a, Angle y1, Angle x2, Angle y3 )
- {
- assign(a,rot_mat_yxy<mat_traits<A>::rows>(y1,x2,y3));
- }
- template <class A,class Angle>
- BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value &&
- mat_traits<A>::rows==mat_traits<A>::cols &&
- mat_traits<A>::rows>=3,
- void>::type
- rotate_yxy( A & a, Angle y1, Angle x2, Angle y3 )
- {
- a *= rot_mat_yxy<mat_traits<A>::rows>(y1,x2,y3);
- }
- ////////////////////////////////////////////////
- template <int Dim,class Angle>
- BOOST_QVM_INLINE
- qvm_detail::rot_mat_<Dim,Angle>
- rot_mat_yzy( Angle y1, Angle z2, Angle y3 )
- {
- typedef Angle scalar_type;
- scalar_type const c1 = cos<scalar_type>(y1);
- scalar_type const s1 = sin<scalar_type>(y1);
- scalar_type const c2 = cos<scalar_type>(z2);
- scalar_type const s2 = sin<scalar_type>(z2);
- scalar_type const c3 = cos<scalar_type>(y3);
- scalar_type const s3 = sin<scalar_type>(y3);
- return qvm_detail::rot_mat_<Dim,Angle>(
- c1*c2*c3 - s1*s3, -c1*s2, c3*s1 + c1*c2*s3,
- c3*s2, c2, s2*s3,
- -c1*s3 - c2*c3*s1, s1*s2, c1*c3 - c2*s1*s3 );
- }
- template <class A,class Angle>
- BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value &&
- mat_traits<A>::rows==mat_traits<A>::cols &&
- mat_traits<A>::rows>=3,
- void>::type
- set_rot_yzy( A & a, Angle y1, Angle z2, Angle y3 )
- {
- assign(a,rot_mat_yzy<mat_traits<A>::rows>(y1,z2,y3));
- }
- template <class A,class Angle>
- BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value &&
- mat_traits<A>::rows==mat_traits<A>::cols &&
- mat_traits<A>::rows>=3,
- void>::type
- rotate_yzy( A & a, Angle y1, Angle z2, Angle y3 )
- {
- a *= rot_mat_yzy<mat_traits<A>::rows>(y1,z2,y3);
- }
- ////////////////////////////////////////////////
- template <int Dim,class Angle>
- BOOST_QVM_INLINE
- qvm_detail::rot_mat_<Dim,Angle>
- rot_mat_zyz( Angle z1, Angle y2, Angle z3 )
- {
- typedef Angle scalar_type;
- scalar_type const c1 = cos<scalar_type>(z1);
- scalar_type const s1 = sin<scalar_type>(z1);
- scalar_type const c2 = cos<scalar_type>(y2);
- scalar_type const s2 = sin<scalar_type>(y2);
- scalar_type const c3 = cos<scalar_type>(z3);
- scalar_type const s3 = sin<scalar_type>(z3);
- return qvm_detail::rot_mat_<Dim,Angle>(
- c1*c2*c3 - s1*s3, -c3*s1 - c1*c2*s3, c1*s2,
- c1*s3 + c2*c3*s1, c1*c3 - c2*s1*s3, s1*s2,
- -c3*s2, s2*s3, c2 );
- }
- template <class A,class Angle>
- BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value &&
- mat_traits<A>::rows==mat_traits<A>::cols &&
- mat_traits<A>::rows>=3,
- void>::type
- set_rot_zyz( A & a, Angle z1, Angle y2, Angle z3 )
- {
- assign(a,rot_mat_zyz<mat_traits<A>::rows>(z1,y2,z3));
- }
- template <class A,class Angle>
- BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value &&
- mat_traits<A>::rows==mat_traits<A>::cols &&
- mat_traits<A>::rows>=3,
- void>::type
- rotate_zyz( A & a, Angle z1, Angle y2, Angle z3 )
- {
- a *= rot_mat_zyz<mat_traits<A>::rows>(z1,y2,z3);
- }
- ////////////////////////////////////////////////
- template <int Dim,class Angle>
- BOOST_QVM_INLINE
- qvm_detail::rot_mat_<Dim,Angle>
- rot_mat_zxz( Angle z1, Angle x2, Angle z3 )
- {
- typedef Angle scalar_type;
- scalar_type const c1 = cos<scalar_type>(z1);
- scalar_type const s1 = sin<scalar_type>(z1);
- scalar_type const c2 = cos<scalar_type>(x2);
- scalar_type const s2 = sin<scalar_type>(x2);
- scalar_type const c3 = cos<scalar_type>(z3);
- scalar_type const s3 = sin<scalar_type>(z3);
- return qvm_detail::rot_mat_<Dim,Angle>(
- c1*c3 - c2*s1*s3, -c1*s3 - c2*c3*s1, s1*s2,
- c3*s1 + c1*c2*s3, c1*c2*c3 - s1*s3, -c1*s2,
- s2*s3, c3*s2, c2 );
- }
- template <class A,class Angle>
- BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value &&
- mat_traits<A>::rows==mat_traits<A>::cols &&
- mat_traits<A>::rows>=3,
- void>::type
- set_rot_zxz( A & a, Angle z1, Angle x2, Angle z3 )
- {
- assign(a,rot_mat_zxz<mat_traits<A>::rows>(z1,x2,z3));
- }
- template <class A,class Angle>
- BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value &&
- mat_traits<A>::rows==mat_traits<A>::cols &&
- mat_traits<A>::rows>=3,
- void>::type
- rotate_zxz( A & a, Angle z1, Angle x2, Angle z3 )
- {
- a *= rot_mat_zxz<mat_traits<A>::rows>(z1,x2,z3);
- }
- ////////////////////////////////////////////////
- namespace
- qvm_detail
- {
- template <int Dim,class Angle>
- struct
- rotx_mat_
- {
- BOOST_QVM_INLINE_TRIVIAL
- rotx_mat_()
- {
- }
- template <class R>
- BOOST_QVM_INLINE_TRIVIAL
- operator R() const
- {
- R r;
- assign(r,*this);
- return r;
- }
- private:
- rotx_mat_( rotx_mat_ const & );
- rotx_mat_ & operator=( rotx_mat_ const & );
- ~rotx_mat_();
- };
- template <int Row,int Col>
- struct
- rotx_m_get
- {
- template <class T>
- static
- BOOST_QVM_INLINE_CRITICAL
- T
- get( T const & )
- {
- return scalar_traits<T>::value(Row==Col);
- }
- };
- template <>
- struct
- rotx_m_get<1,1>
- {
- template <class T>
- static
- BOOST_QVM_INLINE_CRITICAL
- T
- get( T const & angle )
- {
- return cos<T>(angle);
- }
- };
- template <>
- struct
- rotx_m_get<1,2>
- {
- template <class T>
- static
- BOOST_QVM_INLINE_CRITICAL
- T
- get( T const & angle )
- {
- return -sin<T>(angle);
- }
- };
- template <>
- struct
- rotx_m_get<2,1>
- {
- template <class T>
- static
- BOOST_QVM_INLINE_CRITICAL
- T
- get( T const & angle )
- {
- return sin<T>(angle);
- }
- };
- template <>
- struct
- rotx_m_get<2,2>
- {
- template <class T>
- static
- BOOST_QVM_INLINE_CRITICAL
- T
- get( T const & angle )
- {
- return cos<T>(angle);
- }
- };
- }
- template <int Dim,class Angle>
- struct
- mat_traits< qvm_detail::rotx_mat_<Dim,Angle> >
- {
- typedef qvm_detail::rotx_mat_<Dim,Angle> this_matrix;
- typedef Angle scalar_type;
- static int const rows=Dim;
- static int const cols=Dim;
- template <int Row,int Col>
- static
- BOOST_QVM_INLINE_CRITICAL
- scalar_type
- read_element( this_matrix const & x )
- {
- BOOST_QVM_STATIC_ASSERT(Row>=0);
- BOOST_QVM_STATIC_ASSERT(Col>=0);
- BOOST_QVM_STATIC_ASSERT(Row<Dim);
- BOOST_QVM_STATIC_ASSERT(Col<Dim);
- return qvm_detail::rotx_m_get<Row,Col>::get(reinterpret_cast<Angle const &>(x));
- }
- static
- BOOST_QVM_INLINE_CRITICAL
- scalar_type
- read_element_idx( int row, int col, this_matrix const & x )
- {
- BOOST_QVM_ASSERT(row>=0);
- BOOST_QVM_ASSERT(col>=0);
- BOOST_QVM_ASSERT(row<Dim);
- BOOST_QVM_ASSERT(col<Dim);
- Angle const & a=reinterpret_cast<Angle const &>(x);
- if( row==1 )
- {
- if( col==1 )
- return cos<scalar_type>(a);
- if( col==2 )
- return -sin<scalar_type>(a);
- }
- if( row==2 )
- {
- if( col==1 )
- return sin<scalar_type>(a);
- if( col==2 )
- return cos<scalar_type>(a);
- }
- return scalar_traits<scalar_type>::value(row==col);
- }
- };
- template <int Dim,class Angle>
- struct
- deduce_mat<qvm_detail::rotx_mat_<Dim,Angle>,Dim,Dim>
- {
- typedef mat<Angle,Dim,Dim> type;
- };
- template <int Dim,class Angle>
- struct
- deduce_mat2<qvm_detail::rotx_mat_<Dim,Angle>,qvm_detail::rotx_mat_<Dim,Angle>,Dim,Dim>
- {
- typedef mat<Angle,Dim,Dim> type;
- };
- template <int Dim,class Angle>
- BOOST_QVM_INLINE_TRIVIAL
- qvm_detail::rotx_mat_<Dim,Angle> const &
- rotx_mat( Angle const & angle )
- {
- BOOST_QVM_STATIC_ASSERT(Dim>=3);
- return reinterpret_cast<qvm_detail::rotx_mat_<Dim,Angle> const &>(angle);
- }
- template <class A,class Angle>
- BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value &&
- mat_traits<A>::rows>=3 &&
- mat_traits<A>::rows==mat_traits<A>::cols,
- void>::type
- set_rotx( A & a, Angle angle )
- {
- assign(a,rotx_mat<mat_traits<A>::rows>(angle));
- }
- template <class A,class Angle>
- BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value &&
- mat_traits<A>::rows>=3 &&
- mat_traits<A>::rows==mat_traits<A>::cols,
- void>::type
- rotate_x( A & a, Angle angle )
- {
- a *= rotx_mat<mat_traits<A>::rows>(angle);
- }
- ////////////////////////////////////////////////
- namespace
- qvm_detail
- {
- template <int Dim,class Angle>
- struct
- roty_mat_
- {
- BOOST_QVM_INLINE_TRIVIAL
- roty_mat_()
- {
- }
- template <class R>
- BOOST_QVM_INLINE_TRIVIAL
- operator R() const
- {
- R r;
- assign(r,*this);
- return r;
- }
- private:
- roty_mat_( roty_mat_ const & );
- roty_mat_ & operator=( roty_mat_ const & );
- ~roty_mat_();
- };
- template <int Row,int Col>
- struct
- roty_m_get
- {
- template <class T>
- static
- BOOST_QVM_INLINE_CRITICAL
- T
- get( T const & )
- {
- return scalar_traits<T>::value(Row==Col);
- }
- };
- template <>
- struct
- roty_m_get<0,0>
- {
- template <class T>
- static
- BOOST_QVM_INLINE_CRITICAL
- T
- get( T const & angle )
- {
- return cos<T>(angle);
- }
- };
- template <>
- struct
- roty_m_get<0,2>
- {
- template <class T>
- static
- BOOST_QVM_INLINE_CRITICAL
- T
- get( T const & angle )
- {
- return sin<T>(angle);
- }
- };
- template <>
- struct
- roty_m_get<2,0>
- {
- template <class T>
- static
- BOOST_QVM_INLINE_CRITICAL
- T
- get( T const & angle )
- {
- return -sin<T>(angle);
- }
- };
- template <>
- struct
- roty_m_get<2,2>
- {
- template <class T>
- static
- BOOST_QVM_INLINE_CRITICAL
- T
- get( T const & angle )
- {
- return cos<T>(angle);
- }
- };
- }
- template <int Dim,class Angle>
- struct
- mat_traits< qvm_detail::roty_mat_<Dim,Angle> >
- {
- typedef qvm_detail::roty_mat_<Dim,Angle> this_matrix;
- typedef Angle scalar_type;
- static int const rows=Dim;
- static int const cols=Dim;
- template <int Row,int Col>
- static
- BOOST_QVM_INLINE_CRITICAL
- scalar_type
- read_element( this_matrix const & x )
- {
- BOOST_QVM_STATIC_ASSERT(Row>=0);
- BOOST_QVM_STATIC_ASSERT(Col>=0);
- BOOST_QVM_STATIC_ASSERT(Row<Dim);
- BOOST_QVM_STATIC_ASSERT(Col<Dim);
- return qvm_detail::roty_m_get<Row,Col>::get(reinterpret_cast<Angle const &>(x));
- }
- static
- BOOST_QVM_INLINE_CRITICAL
- scalar_type
- read_element_idx( int row, int col, this_matrix const & x )
- {
- BOOST_QVM_ASSERT(row>=0);
- BOOST_QVM_ASSERT(col>=0);
- BOOST_QVM_ASSERT(row<Dim);
- BOOST_QVM_ASSERT(col<Dim);
- Angle const & a=reinterpret_cast<Angle const &>(x);
- if( row==0 )
- {
- if( col==0 )
- return cos<scalar_type>(a);
- if( col==2 )
- return sin<scalar_type>(a);
- }
- if( row==2 )
- {
- if( col==0 )
- return -sin<scalar_type>(a);
- if( col==2 )
- return cos<scalar_type>(a);
- }
- return scalar_traits<scalar_type>::value(row==col);
- }
- };
- template <int Dim,class Angle>
- struct
- deduce_mat<qvm_detail::roty_mat_<Dim,Angle>,Dim,Dim>
- {
- typedef mat<Angle,Dim,Dim> type;
- };
- template <int Dim,class Angle>
- struct
- deduce_mat2<qvm_detail::roty_mat_<Dim,Angle>,qvm_detail::roty_mat_<Dim,Angle>,Dim,Dim>
- {
- typedef mat<Angle,Dim,Dim> type;
- };
- template <int Dim,class Angle>
- BOOST_QVM_INLINE_TRIVIAL
- qvm_detail::roty_mat_<Dim,Angle> const &
- roty_mat( Angle const & angle )
- {
- BOOST_QVM_STATIC_ASSERT(Dim>=3);
- return reinterpret_cast<qvm_detail::roty_mat_<Dim,Angle> const &>(angle);
- }
- template <class A,class Angle>
- BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value &&
- mat_traits<A>::rows>=2 &&
- mat_traits<A>::rows==mat_traits<A>::cols,
- void>::type
- set_roty( A & a, Angle angle )
- {
- assign(a,roty_mat<mat_traits<A>::rows>(angle));
- }
- template <class A,class Angle>
- BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value &&
- mat_traits<A>::rows>=3 &&
- mat_traits<A>::rows==mat_traits<A>::cols,
- void>::type
- rotate_y( A & a, Angle angle )
- {
- a *= roty_mat<mat_traits<A>::rows>(angle);
- }
- ////////////////////////////////////////////////
- namespace
- qvm_detail
- {
- template <int Dim,class Angle>
- struct
- rotz_mat_
- {
- BOOST_QVM_INLINE_TRIVIAL
- rotz_mat_()
- {
- }
- template <class R>
- BOOST_QVM_INLINE_TRIVIAL
- operator R() const
- {
- R r;
- assign(r,*this);
- return r;
- }
- private:
- rotz_mat_( rotz_mat_ const & );
- rotz_mat_ & operator=( rotz_mat_ const & );
- ~rotz_mat_();
- };
- template <int Row,int Col>
- struct
- rotz_m_get
- {
- template <class T>
- static
- BOOST_QVM_INLINE_CRITICAL
- T
- get( T const & )
- {
- return scalar_traits<T>::value(Row==Col);
- }
- };
- template <>
- struct
- rotz_m_get<0,0>
- {
- template <class T>
- static
- BOOST_QVM_INLINE_CRITICAL
- T
- get( T const & angle )
- {
- return cos<T>(angle);
- }
- };
- template <>
- struct
- rotz_m_get<0,1>
- {
- template <class T>
- static
- BOOST_QVM_INLINE_CRITICAL
- T
- get( T const & angle )
- {
- return -sin<T>(angle);
- }
- };
- template <>
- struct
- rotz_m_get<1,0>
- {
- template <class T>
- static
- BOOST_QVM_INLINE_CRITICAL
- T
- get( T const & angle )
- {
- return sin<T>(angle);
- }
- };
- template <>
- struct
- rotz_m_get<1,1>
- {
- template <class T>
- static
- BOOST_QVM_INLINE_CRITICAL
- T
- get( T const & angle )
- {
- return cos<T>(angle);
- }
- };
- }
- template <int Dim,class Angle>
- struct
- mat_traits< qvm_detail::rotz_mat_<Dim,Angle> >
- {
- typedef qvm_detail::rotz_mat_<Dim,Angle> this_matrix;
- typedef Angle scalar_type;
- static int const rows=Dim;
- static int const cols=Dim;
- template <int Row,int Col>
- static
- BOOST_QVM_INLINE_CRITICAL
- scalar_type
- read_element( this_matrix const & x )
- {
- BOOST_QVM_STATIC_ASSERT(Row>=0);
- BOOST_QVM_STATIC_ASSERT(Col>=0);
- BOOST_QVM_STATIC_ASSERT(Row<Dim);
- BOOST_QVM_STATIC_ASSERT(Col<Dim);
- return qvm_detail::rotz_m_get<Row,Col>::get(reinterpret_cast<Angle const &>(x));
- }
- static
- BOOST_QVM_INLINE_CRITICAL
- scalar_type
- read_element_idx( int row, int col, this_matrix const & x )
- {
- BOOST_QVM_ASSERT(row>=0);
- BOOST_QVM_ASSERT(col>=0);
- BOOST_QVM_ASSERT(row<Dim);
- BOOST_QVM_ASSERT(col<Dim);
- Angle const & a=reinterpret_cast<Angle const &>(x);
- if( row==0 )
- {
- if( col==0 )
- return cos<scalar_type>(a);
- if( col==1 )
- return -sin<scalar_type>(a);
- }
- if( row==1 )
- {
- if( col==0 )
- return sin<scalar_type>(a);
- if( col==1 )
- return cos<scalar_type>(a);
- }
- return scalar_traits<scalar_type>::value(row==col);
- }
- };
- template <int Dim,class Angle>
- struct
- deduce_mat<qvm_detail::rotz_mat_<Dim,Angle>,Dim,Dim>
- {
- typedef mat<Angle,Dim,Dim> type;
- };
- template <int Dim,class Angle,int R,int C>
- struct
- deduce_mat2<qvm_detail::rotz_mat_<Dim,Angle>,qvm_detail::rotz_mat_<Dim,Angle>,R,C>
- {
- typedef mat<Angle,R,C> type;
- };
- template <int Dim,class Angle>
- BOOST_QVM_INLINE_TRIVIAL
- qvm_detail::rotz_mat_<Dim,Angle> const &
- rotz_mat( Angle const & angle )
- {
- BOOST_QVM_STATIC_ASSERT(Dim>=2);
- return reinterpret_cast<qvm_detail::rotz_mat_<Dim,Angle> const &>(angle);
- }
- template <class A,class Angle>
- BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value &&
- mat_traits<A>::rows>=2 &&
- mat_traits<A>::rows==mat_traits<A>::cols,
- void>::type
- set_rotz( A & a, Angle angle )
- {
- assign(a,rotz_mat<mat_traits<A>::rows>(angle));
- }
- template <class A,class Angle>
- BOOST_QVM_INLINE_OPERATIONS
- typename enable_if_c<
- is_mat<A>::value &&
- mat_traits<A>::rows>=2 &&
- mat_traits<A>::rows==mat_traits<A>::cols,
- void>::type
- rotate_z( A & a, Angle angle )
- {
- a *= rotz_mat<mat_traits<A>::rows>(angle);
- }
- ////////////////////////////////////////////////
- namespace
- qvm_detail
- {
- template <int D>
- struct
- inverse_m_defined
- {
- static bool const value=false;
- };
- }
- template <class A,class B>
- BOOST_QVM_INLINE_TRIVIAL
- typename lazy_enable_if_c<
- is_mat<A>::value && is_scalar<B>::value &&
- mat_traits<A>::rows==mat_traits<A>::cols &&
- !qvm_detail::inverse_m_defined<mat_traits<A>::rows>::value,
- deduce_mat2<A,B,mat_traits<A>::rows,mat_traits<A>::cols> >::type
- inverse( A const & a, B det )
- {
- typedef typename mat_traits<A>::scalar_type T;
- BOOST_QVM_ASSERT(det!=scalar_traits<T>::value(0));
- T f=scalar_traits<T>::value(1)/det;
- typedef typename deduce_mat2<A,B,mat_traits<A>::rows,mat_traits<A>::cols>::type cofactor_return_type;
- cofactor_return_type c=qvm_detail::cofactor_impl(a);
- return reinterpret_cast<qvm_detail::transposed_<cofactor_return_type> const &>(c) * f;
- }
- template <class A>
- BOOST_QVM_INLINE_TRIVIAL
- typename lazy_enable_if_c<
- is_mat<A>::value &&
- mat_traits<A>::rows==mat_traits<A>::cols &&
- !qvm_detail::inverse_m_defined<mat_traits<A>::rows>::value,
- deduce_mat<A> >::type
- inverse( A const & a )
- {
- typedef typename mat_traits<A>::scalar_type T;
- T det=determinant(a);
- if( det==scalar_traits<T>::value(0) )
- BOOST_QVM_THROW_EXCEPTION(zero_determinant_error());
- return inverse(a,det);
- }
- ////////////////////////////////////////////////
- namespace
- sfinae
- {
- using ::boost::qvm::to_string;
- using ::boost::qvm::assign;
- using ::boost::qvm::determinant;
- using ::boost::qvm::cmp;
- using ::boost::qvm::convert_to;
- using ::boost::qvm::set_identity;
- using ::boost::qvm::set_zero;
- using ::boost::qvm::scalar_cast;
- using ::boost::qvm::operator/=;
- using ::boost::qvm::operator/;
- using ::boost::qvm::operator==;
- using ::boost::qvm::operator-=;
- using ::boost::qvm::operator-;
- using ::boost::qvm::operator*=;
- using ::boost::qvm::operator*;
- using ::boost::qvm::operator!=;
- using ::boost::qvm::operator+=;
- using ::boost::qvm::operator+;
- using ::boost::qvm::mref;
- using ::boost::qvm::rot_mat;
- using ::boost::qvm::set_rot;
- using ::boost::qvm::rotate;
- using ::boost::qvm::set_rotx;
- using ::boost::qvm::rotate_x;
- using ::boost::qvm::set_roty;
- using ::boost::qvm::rotate_y;
- using ::boost::qvm::set_rotz;
- using ::boost::qvm::rotate_z;
- using ::boost::qvm::inverse;
- }
- } }
- #endif
|