// This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0.If a copy of the MPL was not distributed with this // file, You can obtain one at https ://mozilla.org/MPL/2.0/. #ifndef SWINGTWIST_H #define SWINGTWIST_H #include "Angle.h" #include "Direction.h" #include "Quaternion.h" #include "Spherical.h" namespace Passer { namespace LinearAlgebra { /// @brief An orientation using swing and twist angles in various /// representations /// @tparam T The implmentation type used for the representation of the angles template class SwingTwistOf { public: DirectionOf swing; AngleOf twist; SwingTwistOf(); SwingTwistOf(DirectionOf swing, AngleOf twist); SwingTwistOf(AngleOf horizontal, AngleOf vertical, AngleOf twist); static SwingTwistOf Degrees(float horizontal, float vertical = 0, float twist = 0); Quaternion ToQuaternion() const; static SwingTwistOf FromQuaternion(Quaternion q); SphericalOf ToAngleAxis() const; static SwingTwistOf FromAngleAxis(SphericalOf aa); const static SwingTwistOf identity; bool operator==(const SwingTwistOf d) const; /// /// Rotate a vector using this rotation /// /// The vector to rotate /// The rotated vector SphericalOf operator*(const SphericalOf &vector) const; /// /// Multiply this rotation with another rotation /// /// The swing/twist rotation to multiply with /// The resulting swing/twist rotation /// The result will be this rotation rotated according to /// the give rotation. SwingTwistOf operator*(const SwingTwistOf &rotation) const; SwingTwistOf operator*=(const SwingTwistOf &rotation); static SwingTwistOf Inverse(SwingTwistOf rotation); /// /// Convert an angle/axis representation to a swingt /// /// The angle /// The axis /// The resulting quaternion static SwingTwistOf AngleAxis(float angle, const DirectionOf &axis); static AngleOf Angle(const SwingTwistOf &r1, const SwingTwistOf &r2); void Normalize(); }; using SwingTwistSingle = SwingTwistOf; using SwingTwist16 = SwingTwistOf; } // namespace LinearAlgebra } // namespace Passer using namespace Passer::LinearAlgebra; #endif