// 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 DIRECTION_H #define DIRECTION_H #include "Angle.h" namespace Passer { namespace LinearAlgebra { struct Vector3; /// @brief A direction using angles in various representations /// @tparam T The implementation type used for the representation of the angles /// A direction is represented using two angles: /// * The horizontal angle ranging from -180 (inclusive) to 180 (exclusive) /// degrees which is a rotation in the horizontal plane /// * A vertical angle ranging from -90 (inclusive) to 90 (exclusive) degrees /// which is the rotation in the up/down direction applied after the horizontal /// rotation has been applied. /// The angles are automatically normalized to stay within the abovenmentioned /// ranges. template class DirectionOf { public: /// @brief horizontal angle, range= (-180..180] AngleOf horizontal; /// @brief vertical angle, range in degrees = (-90..90] AngleOf vertical; /// @brief Create a new direction with zero angles DirectionOf(); /// @brief Create a new direction /// @param horizontal The horizontal angle /// @param vertical The vertical angle. DirectionOf(AngleOf horizontal, AngleOf vertical); /// @brief Convert the direction into a carthesian vector /// @return The carthesian vector corresponding to this direction. Vector3 ToVector3() const; /// @brief Convert a carthesian vector into a direction /// @param v The carthesian vector /// @return The direction. /// @note Information about the length of the carthesian vector is not /// included in this transformation. static DirectionOf FromVector3(Vector3 vector); /// @brief Create a direction using angle values in degrees /// @param horizontal The horizontal angle in degrees /// @param vertical The vertical angle in degrees /// @return The direction static DirectionOf Degrees(float horizontal, float vertical); /// @brief Create a direction using angle values in radians /// @param horizontal The horizontal angle in radians /// @param vertical The vertical angle in radians /// @return The direction static DirectionOf Radians(float horizontal, float vertical); /// @brief A forward direction with zero for both angles const static DirectionOf forward; /// @brief A backward direction with horizontal angle -180 and zero vertical /// angle const static DirectionOf back; /// @brief A upward direction with zero horizontal angle and vertical angle 90 const static DirectionOf up; /// @brief A downward direction with zero horizontal angle and vertical angle /// -90 const static DirectionOf down; /// @brief A left-pointing direction with horizontal angle -90 and zero /// vertical angle const static DirectionOf left; /// @brief A right-pointing direction with horizontal angle 90 and zero /// vertical angle const static DirectionOf right; /// @brief Test whether this direction is equal to another direction /// @param direction The direction to compare to /// @return True when the direction angles are equal, false otherwise. bool operator==(const DirectionOf direction) const; /// @brief Negate/reverse the direction /// @return The reversed direction. DirectionOf operator-() const; protected: /// @brief Normalize this vector to the specified ranges void Normalize(); }; using DirectionSingle = DirectionOf; using Direction16 = DirectionOf; } // namespace LinearAlgebra } // namespace Passer using namespace Passer::LinearAlgebra; #endif