quat.hpp 1.6 KB

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