quat_vec_operations.hpp 1.9 KB

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