quat_vec_operations.hpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. //Copyright (c) 2008-2016 Emil Dotchevski and Reverge Studios, Inc.
  2. //Distributed under the Boost Software License, Version 1.0. (See accompanying
  3. //file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  4. #ifndef UUID_51968952D30A11DFAFE78CE3DFD72085
  5. #define UUID_51968952D30A11DFAFE78CE3DFD72085
  6. #include <boost/qvm/quat_traits.hpp>
  7. #include <boost/qvm/deduce_vec.hpp>
  8. #include <boost/qvm/inline.hpp>
  9. #include <boost/qvm/enable_if.hpp>
  10. namespace
  11. boost
  12. {
  13. namespace
  14. qvm
  15. {
  16. template <class A,class B>
  17. 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. 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;
  47. return r;
  48. }
  49. namespace
  50. sfinae
  51. {
  52. using ::boost::qvm::operator*;
  53. }
  54. }
  55. }
  56. #endif