quat_access.hpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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_8AC84A2217C411E0A7AF3A1BDFD72085
  5. #define UUID_8AC84A2217C411E0A7AF3A1BDFD72085
  6. #include <boost/qvm/inline.hpp>
  7. #include <boost/qvm/quat_traits.hpp>
  8. #include <boost/qvm/deduce_vec.hpp>
  9. #include <boost/qvm/static_assert.hpp>
  10. #include <boost/qvm/enable_if.hpp>
  11. namespace
  12. boost
  13. {
  14. namespace
  15. qvm
  16. {
  17. ////////////////////////////////////////////////
  18. namespace
  19. qvm_detail
  20. {
  21. template <class Q>
  22. struct
  23. quat_v_
  24. {
  25. template <class R>
  26. operator R() const
  27. {
  28. R r;
  29. assign(r,*this);
  30. return r;
  31. }
  32. private:
  33. quat_v_( quat_v_ const & );
  34. quat_v_ const & operator=( quat_v_ const & );
  35. ~quat_v_();
  36. };
  37. }
  38. template <class V>
  39. struct vec_traits;
  40. template <class Q>
  41. struct
  42. vec_traits< qvm_detail::quat_v_<Q> >
  43. {
  44. typedef qvm_detail::quat_v_<Q> this_vector;
  45. typedef typename quat_traits<Q>::scalar_type scalar_type;
  46. static int const dim=3;
  47. template <int I>
  48. BOOST_QVM_INLINE_CRITICAL
  49. static
  50. scalar_type
  51. read_element( this_vector const & q )
  52. {
  53. BOOST_QVM_STATIC_ASSERT(I>=0);
  54. BOOST_QVM_STATIC_ASSERT(I<dim);
  55. return quat_traits<Q>::template read_element<I+1>( reinterpret_cast<Q const &>(q) );
  56. }
  57. template <int I>
  58. BOOST_QVM_INLINE_CRITICAL
  59. static
  60. scalar_type &
  61. write_element( this_vector & q )
  62. {
  63. BOOST_QVM_STATIC_ASSERT(I>=0);
  64. BOOST_QVM_STATIC_ASSERT(I<dim);
  65. return quat_traits<Q>::template write_element<I+1>( reinterpret_cast<Q &>(q) );
  66. }
  67. };
  68. template <class Q,int D>
  69. struct
  70. deduce_vec<qvm_detail::quat_v_<Q>,D>
  71. {
  72. typedef vec<typename quat_traits<Q>::scalar_type,D> type;
  73. };
  74. template <class Q,int D>
  75. struct
  76. deduce_vec2<qvm_detail::quat_v_<Q>,qvm_detail::quat_v_<Q>,D>
  77. {
  78. typedef vec<typename quat_traits<Q>::scalar_type,D> type;
  79. };
  80. template <class Q>
  81. BOOST_QVM_INLINE_TRIVIAL
  82. typename enable_if_c<
  83. is_quat<Q>::value,
  84. qvm_detail::quat_v_<Q> const &>::type
  85. V( Q const & a )
  86. {
  87. return reinterpret_cast<qvm_detail::quat_v_<Q> const &>(a);
  88. }
  89. template <class Q>
  90. BOOST_QVM_INLINE_TRIVIAL
  91. typename enable_if_c<
  92. is_quat<Q>::value,
  93. qvm_detail::quat_v_<Q> &>::type
  94. V( Q & a )
  95. {
  96. return reinterpret_cast<qvm_detail::quat_v_<Q> &>(a);
  97. }
  98. template <class Q> BOOST_QVM_INLINE_TRIVIAL typename enable_if_c<is_quat<Q>::value,typename quat_traits<Q>::scalar_type>::type S( Q const & a ) { return quat_traits<Q>::template read_element<0>(a); }
  99. template <class Q> BOOST_QVM_INLINE_TRIVIAL typename enable_if_c<is_quat<Q>::value,typename quat_traits<Q>::scalar_type>::type X( Q const & a ) { return quat_traits<Q>::template read_element<1>(a); }
  100. template <class Q> BOOST_QVM_INLINE_TRIVIAL typename enable_if_c<is_quat<Q>::value,typename quat_traits<Q>::scalar_type>::type Y( Q const & a ) { return quat_traits<Q>::template read_element<2>(a); }
  101. template <class Q> BOOST_QVM_INLINE_TRIVIAL typename enable_if_c<is_quat<Q>::value,typename quat_traits<Q>::scalar_type>::type Z( Q const & a ) { return quat_traits<Q>::template read_element<3>(a); }
  102. template <class Q> BOOST_QVM_INLINE_TRIVIAL typename enable_if_c<is_quat<Q>::value,typename quat_traits<Q>::scalar_type &>::type S( Q & a ) { return quat_traits<Q>::template write_element<0>(a); }
  103. template <class Q> BOOST_QVM_INLINE_TRIVIAL typename enable_if_c<is_quat<Q>::value,typename quat_traits<Q>::scalar_type &>::type X( Q & a ) { return quat_traits<Q>::template write_element<1>(a); }
  104. template <class Q> BOOST_QVM_INLINE_TRIVIAL typename enable_if_c<is_quat<Q>::value,typename quat_traits<Q>::scalar_type &>::type Y( Q & a ) { return quat_traits<Q>::template write_element<2>(a); }
  105. template <class Q> BOOST_QVM_INLINE_TRIVIAL typename enable_if_c<is_quat<Q>::value,typename quat_traits<Q>::scalar_type &>::type Z( Q & a ) { return quat_traits<Q>::template write_element<3>(a); }
  106. ////////////////////////////////////////////////
  107. }
  108. }
  109. #endif