quat.hpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #ifndef BOOST_QVM_QUAT_HPP_INCLUDED
  2. #define BOOST_QVM_QUAT_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/detail/quat_assign.hpp>
  7. #include <boost/qvm/assert.hpp>
  8. #include <boost/qvm/static_assert.hpp>
  9. namespace boost { namespace qvm {
  10. template <class T>
  11. struct
  12. quat
  13. {
  14. T a[4];
  15. template <class R
  16. #if __cplusplus >= 201103L
  17. , class = typename enable_if<is_quat<R> >::type
  18. #endif
  19. >
  20. operator R() const
  21. {
  22. R r;
  23. assign(r,*this);
  24. return r;
  25. }
  26. };
  27. template <class Q>
  28. struct quat_traits;
  29. template <class T>
  30. struct
  31. quat_traits< quat<T> >
  32. {
  33. typedef quat<T> this_quaternion;
  34. typedef T scalar_type;
  35. template <int I>
  36. static
  37. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
  38. scalar_type
  39. read_element( this_quaternion const & x )
  40. {
  41. BOOST_QVM_STATIC_ASSERT(I>=0);
  42. BOOST_QVM_STATIC_ASSERT(I<4);
  43. return x.a[I];
  44. }
  45. template <int I>
  46. static
  47. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
  48. scalar_type &
  49. write_element( this_quaternion & x )
  50. {
  51. BOOST_QVM_STATIC_ASSERT(I>=0);
  52. BOOST_QVM_STATIC_ASSERT(I<4);
  53. return x.a[I];
  54. }
  55. };
  56. } }
  57. #endif