quat.hpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #ifndef BOOST_QVM_QUAT_HPP_INCLUDED
  2. #define BOOST_QVM_QUAT_HPP_INCLUDED
  3. /// Copyright (c) 2008-2021 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. operator R() const
  17. {
  18. R r;
  19. assign(r,*this);
  20. return r;
  21. }
  22. };
  23. template <class Q>
  24. struct quat_traits;
  25. template <class T>
  26. struct
  27. quat_traits< quat<T> >
  28. {
  29. typedef quat<T> this_quaternion;
  30. typedef T scalar_type;
  31. template <int I>
  32. static
  33. BOOST_QVM_INLINE_CRITICAL
  34. scalar_type
  35. read_element( this_quaternion const & x )
  36. {
  37. BOOST_QVM_STATIC_ASSERT(I>=0);
  38. BOOST_QVM_STATIC_ASSERT(I<4);
  39. return x.a[I];
  40. }
  41. template <int I>
  42. static
  43. BOOST_QVM_INLINE_CRITICAL
  44. scalar_type &
  45. write_element( this_quaternion & x )
  46. {
  47. BOOST_QVM_STATIC_ASSERT(I>=0);
  48. BOOST_QVM_STATIC_ASSERT(I<4);
  49. return x.a[I];
  50. }
  51. };
  52. } }
  53. #endif