Math/Angle: Fix implicit conversion to Euler Angles/Quaternion

This commit is contained in:
Jérôme Leclercq 2018-09-06 13:24:29 +02:00
parent 8bcb8756f9
commit 46008531e0
6 changed files with 63 additions and 31 deletions

View File

@ -53,9 +53,6 @@ namespace Nz
Angle<AngleUnit::Radian, T> ToRadians() const;
String ToString() const;
operator EulerAngles<T>() const;
operator Quaternion<T>() const;
Angle& operator=(const Angle&) = default;
Angle operator+(const Angle& other) const;

View File

@ -319,30 +319,6 @@ namespace Nz
return Detail::AngleUtils<Unit>::ToString(angle);
}
/*!
* \brief Shortcut allowing implicit conversion to Euler angles
* \return Euler Angles representing a 2D rotation by this angle
*
* \see ToEulerAngles
*/
template<AngleUnit Unit, typename T>
Angle<Unit, T>::operator EulerAngles<T>() const
{
return ToEulerAngles();
}
/*!
* \brief Shortcut allowing implicit conversion to Quaternion
* \return Quaternion representing a 2D rotation by this angle
*
* \see ToQuaternion
*/
template<AngleUnit Unit, typename T>
Angle<Unit, T>::operator Quaternion<T>() const
{
return ToQuaternion();
}
/*!
* \brief Converts the angle to an Euler Angles representation
* \return A 2D rotation expressed in Euler angles

View File

@ -8,6 +8,7 @@
#define NAZARA_EULERANGLES_HPP
#include <Nazara/Core/String.hpp>
#include <Nazara/Math/Angle.hpp>
#include <Nazara/Math/Quaternion.hpp>
#include <Nazara/Math/Vector3.hpp>
@ -22,6 +23,7 @@ namespace Nz
EulerAngles() = default;
EulerAngles(T P, T Y, T R);
EulerAngles(const T angles[3]);
template<AngleUnit Unit> EulerAngles(const Angle<Unit, T>& angle);
//EulerAngles(const Matrix3<T>& mat);
EulerAngles(const Quaternion<T>& quat);
template<typename U> explicit EulerAngles(const EulerAngles<U>& angles);
@ -34,6 +36,7 @@ namespace Nz
EulerAngles& Set(T P, T Y, T R);
EulerAngles& Set(const T angles[3]);
template<AngleUnit Unit> EulerAngles& Set(const Angle<Unit, T>& angles);
EulerAngles& Set(const EulerAngles<T>& angles);
//EulerAngles& Set(const Matrix3<T>& mat);
EulerAngles& Set(const Quaternion<T>& quat);

View File

@ -50,12 +50,23 @@ namespace Nz
Set(angles);
}
/*!
* \brief Constructs a EulerAngles object from an angle
*
* \param angle Angle representing a 2D rotation
*/
template<typename T>
template<AngleUnit Unit>
EulerAngles<T>::EulerAngles(const Angle<Unit, T>& angle)
{
Set(angle);
}
/*!
* \brief Constructs a EulerAngles object from a quaternion
*
* \param quat Quaternion representing a rotation of space
*/
template<typename T>
EulerAngles<T>::EulerAngles(const Quaternion<T>& quat)
{
@ -142,13 +153,28 @@ namespace Nz
return *this;
}
/*!
* \brief Sets the components of the euler angle from a 2D rotation specified by an Angle
* \return A reference to this euler angle
*
* \param angle 2D angle
*
* \see Angle
*/
template<typename T>
template<AngleUnit Unit>
EulerAngles<T>& EulerAngles<T>::Set(const Angle<Unit, T>& angle)
{
return Set(angle.ToEulerAngles());
}
/*!
* \brief Sets the components of the euler angle from another euler angle
* \return A reference to this euler angle
*
* \param angles The other euler angle
*/
template<typename T>
EulerAngles<T>& EulerAngles<T>::Set(const EulerAngles& angles)
{
@ -394,3 +420,4 @@ std::ostream& operator<<(std::ostream& out, const Nz::EulerAngles<T>& angles)
#undef F
#include <Nazara/Core/DebugOff.hpp>
#include "EulerAngles.hpp"

View File

@ -8,6 +8,7 @@
#define NAZARA_QUATERNION_HPP
#include <Nazara/Core/String.hpp>
#include <Nazara/Math/Angle.hpp>
namespace Nz
{
@ -21,6 +22,7 @@ namespace Nz
public:
Quaternion() = default;
Quaternion(T W, T X, T Y, T Z);
template<AngleUnit Unit> Quaternion(const Angle<Unit, T>& angle);
Quaternion(const EulerAngles<T>& angles);
Quaternion(T angle, const Vector3<T>& axis);
Quaternion(const T quat[4]);
@ -49,6 +51,7 @@ namespace Nz
Quaternion& Normalize(T* length = nullptr);
Quaternion& Set(T W, T X, T Y, T Z);
template<AngleUnit Unit> Quaternion& Set(const Angle<Unit, T>& angle);
Quaternion& Set(const EulerAngles<T>& angles);
Quaternion& Set(T angle, const Vector3<T>& normalizedAxis);
Quaternion& Set(const T quat[4]);

View File

@ -39,6 +39,18 @@ namespace Nz
Set(W, X, Y, Z);
}
/*!
* \brief Constructs a Quaternion object from an angle
*
* \param angle Angle representing a 2D rotation
*/
template<typename T>
template<AngleUnit Unit>
Quaternion<T>::Quaternion(const Angle<Unit, T>& angle)
{
Set(angle);
}
/*!
* \brief Constructs a Quaternion object from a EulerAngles
*
@ -46,7 +58,6 @@ namespace Nz
*
* \see EulerAngles
*/
template<typename T>
Quaternion<T>::Quaternion(const EulerAngles<T>& angles)
{
@ -343,6 +354,21 @@ namespace Nz
return *this;
}
/*!
* \brief Sets this quaternion from a 2D rotation specified by an Angle
* \return A reference to this quaternion
*
* \param angle 2D angle
*
* \see Angle
*/
template<typename T>
template<AngleUnit Unit>
Quaternion<T>& Quaternion<T>::Set(const Angle<Unit, T>& angle)
{
return Set(angle.ToQuaternion());
}
/*!
* \brief Sets this quaternion from rotation specified by Euler angle
* \return A reference to this quaternion
@ -351,7 +377,6 @@ namespace Nz
*
* \see EulerAngles
*/
template<typename T>
Quaternion<T>& Quaternion<T>::Set(const EulerAngles<T>& angles)
{
@ -886,3 +911,4 @@ std::ostream& operator<<(std::ostream& out, const Nz::Quaternion<T>& quat)
#undef F
#include <Nazara/Core/DebugOff.hpp>
#include "Quaternion.hpp"