//Copyright (c) 2008-2016 Emil Dotchevski and Reverge Studios, Inc. //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) #ifndef UUID_A61EC088D31511DFA59D2B03E0D72085 #define UUID_A61EC088D31511DFA59D2B03E0D72085 #include #include #include namespace boost { namespace qvm { //////////////////////////////////////////////// namespace qvm_detail { template struct mul_mv_defined { static bool const value=false; }; } template BOOST_QVM_INLINE_OPERATIONS typename lazy_enable_if_c< is_mat::value && is_vec::value && mat_traits::cols==vec_traits::dim && !qvm_detail::mul_mv_defined::rows,mat_traits::cols>::value, deduce_vec2::rows> >::type operator*( A const & a, B const & b ) { typedef typename deduce_vec2::rows>::type R; R r; for( int i=0; i::rows; ++i ) { typedef typename vec_traits::scalar_type Tr; Tr x(scalar_traits::value(0)); for( int j=0; j::cols; ++j ) x += mat_traits::read_element_idx(i,j,a)*vec_traits::read_element_idx(j,b); vec_traits::write_element_idx(i,r) = x; } return r; } namespace qvm_detail { template struct mul_vm_defined { static bool const value=false; }; } template BOOST_QVM_INLINE_OPERATIONS typename lazy_enable_if_c< is_vec::value && is_mat::value && vec_traits::dim==mat_traits::rows && !qvm_detail::mul_vm_defined::rows,mat_traits::cols>::value, deduce_vec2::cols> >::type operator*( A const & a, B const & b ) { typedef typename deduce_vec2::cols>::type R; R r; for( int i=0; i::cols; ++i ) { typedef typename vec_traits::scalar_type Tr; Tr x(scalar_traits::value(0)); for( int j=0; j::rows; ++j ) x += vec_traits::read_element_idx(j,a)*mat_traits::read_element_idx(j,i,b); vec_traits::write_element_idx(i,r) = x; } return r; } //////////////////////////////////////////////// template BOOST_QVM_INLINE_OPERATIONS typename lazy_enable_if_c< mat_traits::rows==4 && mat_traits::cols==4 && vec_traits::dim==3, deduce_vec2 >::type transform_point( A const & a, B const & b ) { typedef typename mat_traits::scalar_type Ta; typedef typename vec_traits::scalar_type Tb; Ta const a00 = mat_traits::template read_element<0,0>(a); Ta const a01 = mat_traits::template read_element<0,1>(a); Ta const a02 = mat_traits::template read_element<0,2>(a); Ta const a03 = mat_traits::template read_element<0,3>(a); Ta const a10 = mat_traits::template read_element<1,0>(a); Ta const a11 = mat_traits::template read_element<1,1>(a); Ta const a12 = mat_traits::template read_element<1,2>(a); Ta const a13 = mat_traits::template read_element<1,3>(a); Ta const a20 = mat_traits::template read_element<2,0>(a); Ta const a21 = mat_traits::template read_element<2,1>(a); Ta const a22 = mat_traits::template read_element<2,2>(a); Ta const a23 = mat_traits::template read_element<2,3>(a); Tb const b0 = vec_traits::template read_element<0>(b); Tb const b1 = vec_traits::template read_element<1>(b); Tb const b2 = vec_traits::template read_element<2>(b); typedef typename deduce_vec2::type R; BOOST_QVM_STATIC_ASSERT(vec_traits::dim==3); R r; vec_traits::template write_element<0>(r)=a00*b0+a01*b1+a02*b2+a03; vec_traits::template write_element<1>(r)=a10*b0+a11*b1+a12*b2+a13; vec_traits::template write_element<2>(r)=a20*b0+a21*b1+a22*b2+a23; return r; } template BOOST_QVM_INLINE_OPERATIONS typename lazy_enable_if_c< mat_traits::rows==4 && mat_traits::cols==4 && vec_traits::dim==3, deduce_vec2 >::type transform_vector( A const & a, B const & b ) { typedef typename mat_traits::scalar_type Ta; typedef typename vec_traits::scalar_type Tb; Ta const a00 = mat_traits::template read_element<0,0>(a); Ta const a01 = mat_traits::template read_element<0,1>(a); Ta const a02 = mat_traits::template read_element<0,2>(a); Ta const a10 = mat_traits::template read_element<1,0>(a); Ta const a11 = mat_traits::template read_element<1,1>(a); Ta const a12 = mat_traits::template read_element<1,2>(a); Ta const a20 = mat_traits::template read_element<2,0>(a); Ta const a21 = mat_traits::template read_element<2,1>(a); Ta const a22 = mat_traits::template read_element<2,2>(a); Tb const b0 = vec_traits::template read_element<0>(b); Tb const b1 = vec_traits::template read_element<1>(b); Tb const b2 = vec_traits::template read_element<2>(b); typedef typename deduce_vec2::type R; BOOST_QVM_STATIC_ASSERT(vec_traits::dim==3); R r; vec_traits::template write_element<0>(r)=a00*b0+a01*b1+a02*b2; vec_traits::template write_element<1>(r)=a10*b0+a11*b1+a12*b2; vec_traits::template write_element<2>(r)=a20*b0+a21*b1+a22*b2; return r; } //////////////////////////////////////////////// namespace sfinae { using ::boost::qvm::operator*; using ::boost::qvm::transform_point; using ::boost::qvm::transform_vector; } //////////////////////////////////////////////// } } #endif