1 #ifndef BOOST_QVM_QUAT_VEC_OPERATIONS_HPP_INCLUDED
2 #define BOOST_QVM_QUAT_VEC_OPERATIONS_HPP_INCLUDED
4 // Copyright 2008-2022 Emil Dotchevski and Reverge Studios, Inc.
6 // Distributed under the Boost Software License, Version 1.0. (See accompanying
7 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 #include <boost/qvm/quat_traits.hpp>
10 #include <boost/qvm/deduce_vec.hpp>
11 #include <boost/qvm/inline.hpp>
12 #include <boost/qvm/enable_if.hpp>
14 namespace boost { namespace qvm {
16 template <class A,class B>
17 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_OPERATIONS
18 typename lazy_enable_if_c<
20 is_vec<B>::value && vec_traits<B>::dim==3,
21 deduce_vec2<A,B,3> >::type
22 operator*( A const & a, B const & b )
24 typedef typename deduce_vec2<A,B,3>::type R;
25 typedef typename quat_traits<A>::scalar_type TA;
26 typedef typename vec_traits<B>::scalar_type TB;
27 TA const aa = quat_traits<A>::template read_element<0>(a);
28 TA const ab = quat_traits<A>::template read_element<1>(a);
29 TA const ac = quat_traits<A>::template read_element<2>(a);
30 TA const ad = quat_traits<A>::template read_element<3>(a);
39 TA const t10 = -ad*ad;
40 TB const bx = vec_traits<B>::template read_element<0>(b);
41 TB const by = vec_traits<B>::template read_element<1>(b);
42 TB const bz = vec_traits<B>::template read_element<2>(b);
44 vec_traits<R>::template write_element<0>(r) = 2*((t8+t10)*bx + (t6-t4)*by + (t3+t7)*bz) + bx;
45 vec_traits<R>::template write_element<1>(r) = 2*((t4+t6)*bx + (t5+t10)*by + (t9-t2)*bz) + by;
46 vec_traits<R>::template write_element<2>(r) = 2*((t7-t3)*bx + (t2+t9)*by + (t5+t8)*bz) + bz;
53 using ::boost::qvm::operator*;