💿🐜 Antkeeper source code https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

111 lines
3.0 KiB

  1. /*
  2. * Copyright (C) 2021 Christopher J. Howard
  3. *
  4. * This file is part of Antkeeper source code.
  5. *
  6. * Antkeeper source code is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Antkeeper source code is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef ANTKEEPER_MATH_QUATERNION_OPERATORS_HPP
  20. #define ANTKEEPER_MATH_QUATERNION_OPERATORS_HPP
  21. #include "math/quaternion-type.hpp"
  22. #include "math/quaternion-functions.hpp"
  23. namespace math {
  24. namespace quaternion_operators {
  25. /// @addtogroup quaternion
  26. /// @{
  27. /// @copydoc add(const quaternion<T>&, const quaternion<T>&)
  28. template <class T>
  29. quaternion<T> operator+(const quaternion<T>& x, const quaternion<T>& y);
  30. /// @copydoc div(const quaternion<T>&, T)
  31. template <class T>
  32. quaternion<T> operator/(const quaternion<T>& q, T s);
  33. /// @copydoc mul(const quaternion<T>&, const quaternion<T>&)
  34. template <class T>
  35. quaternion<T> operator*(const quaternion<T>& x, const quaternion<T>& y);
  36. /// @copydoc mul(const quaternion<T>&, T)
  37. template <class T>
  38. quaternion<T> operator*(const quaternion<T>& q, T s);
  39. /// @copydoc mul(const quaternion<T>&, const vector<T, 3>&)
  40. template <class T>
  41. vector<T, 3> operator*(const quaternion<T>& q, const vector<T, 3>& v);
  42. /// @copydoc sub(const quaternion<T>&, const quaternion<T>&)
  43. template <class T>
  44. quaternion<T> operator-(const quaternion<T>& x, const quaternion<T>& y);
  45. /// @copydoc negate(const quaternion<T>&)
  46. template <class T, std::size_t N>
  47. quaternion<T> operator-(const quaternion<T>& x);
  48. template <class T>
  49. inline quaternion<T> operator+(const quaternion<T>& x, const quaternion<T>& y)
  50. {
  51. return add(x, y);
  52. }
  53. template <class T>
  54. inline quaternion<T> operator/(const quaternion<T>& q, T s)
  55. {
  56. return div(q, s);
  57. }
  58. template <class T>
  59. inline quaternion<T> operator*(const quaternion<T>& x, const quaternion<T>& y)
  60. {
  61. return mul(x, y);
  62. }
  63. template <class T>
  64. inline quaternion<T> operator*(const quaternion<T>& q, T s)
  65. {
  66. return mul(q, s);
  67. }
  68. template <class T>
  69. inline vector<T, 3> operator*(const quaternion<T>& q, const vector<T, 3>& v)
  70. {
  71. return mul(q, v);
  72. }
  73. template <class T>
  74. inline quaternion<T> operator-(const quaternion<T>& x, const quaternion<T>& y)
  75. {
  76. return sub(x, y);
  77. }
  78. template <class T, std::size_t N>
  79. inline quaternion<T> operator-(const quaternion<T>& x)
  80. {
  81. return negate(x);
  82. }
  83. /// @}
  84. } // namespace quaternion_operators
  85. } // namespace math
  86. /// Bring quaternion operators into global namespace
  87. using namespace math::quaternion_operators;
  88. #endif // ANTKEEPER_MATH_QUATERNION_OPERATORS_HPP