| 1 | #ifndef BOOST_QVM_QUAT_VEC_OPERATIONS_HPP_INCLUDED |
| 2 | #define BOOST_QVM_QUAT_VEC_OPERATIONS_HPP_INCLUDED |
| 3 | |
| 4 | // Copyright 2008-2022 Emil Dotchevski and Reverge Studios, Inc. |
| 5 | |
| 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) |
| 8 | |
| 9 | #include <boost/qvm/quat_traits.hpp> |
| 10 | #include <boost/qvm/deduce_vec.hpp> |
| 11 | #include <boost/qvm/config.hpp> |
| 12 | #include <boost/qvm/enable_if.hpp> |
| 13 | |
| 14 | namespace boost { namespace qvm { |
| 15 | |
| 16 | template <class A,class B> |
| 17 | BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_OPERATIONS |
| 18 | typename lazy_enable_if_c< |
| 19 | is_quat<A>::value && |
| 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 ) |
| 23 | { |
| 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); |
| 31 | TA const t2 = aa*ab; |
| 32 | TA const t3 = aa*ac; |
| 33 | TA const t4 = aa*ad; |
| 34 | TA const t5 = -ab*ab; |
| 35 | TA const t6 = ab*ac; |
| 36 | TA const t7 = ab*ad; |
| 37 | TA const t8 = -ac*ac; |
| 38 | TA const t9 = ac*ad; |
| 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); |
| 43 | R r; |
| 44 | write_vec_element<0>(r, 2*((t8+t10)*bx + (t6-t4)*by + (t3+t7)*bz) + bx); |
| 45 | write_vec_element<1>(r, 2*((t4+t6)*bx + (t5+t10)*by + (t9-t2)*bz) + by); |
| 46 | write_vec_element<2>(r, 2*((t7-t3)*bx + (t2+t9)*by + (t5+t8)*bz) + bz); |
| 47 | return r; |
| 48 | } |
| 49 | |
| 50 | namespace |
| 51 | sfinae |
| 52 | { |
| 53 | using ::boost::qvm::operator*; |
| 54 | } |
| 55 | |
| 56 | } } |
| 57 | |
| 58 | #endif |
| 59 | |