Math: Remove NAZARA_MATH_ANGLE_RADIAN and functions using it

This commit is contained in:
Jérôme Leclercq 2021-06-01 17:37:40 +02:00
parent d0d65be35f
commit 4d74cef034
29 changed files with 234 additions and 323 deletions

View File

@ -214,7 +214,7 @@ int main()
Nz::Vector2ui windowSize = window.GetSize();
Nz::AccessByOffset<Nz::Matrix4f&>(viewerDataBuffer.data(), viewerUboOffsets.viewMatrixOffset) = Nz::Matrix4f::Translate(Nz::Vector3f::Backward() * 1);
Nz::AccessByOffset<Nz::Matrix4f&>(viewerDataBuffer.data(), viewerUboOffsets.projMatrixOffset) = Nz::Matrix4f::Perspective(70.f, float(windowSize.x) / windowSize.y, 0.1f, 1000.f);
Nz::AccessByOffset<Nz::Matrix4f&>(viewerDataBuffer.data(), viewerUboOffsets.projMatrixOffset) = Nz::Matrix4f::Perspective(Nz::DegreeAnglef(70.f), float(windowSize.x) / windowSize.y, 0.1f, 1000.f);
Nz::AccessByOffset<Nz::Vector2f&>(viewerDataBuffer.data(), viewerUboOffsets.invTargetSizeOffset) = 1.f / Nz::Vector2f(window.GetSize().x, window.GetSize().y);
std::vector<std::uint8_t> instanceDataBuffer(instanceUboOffsets.totalSize);
@ -770,7 +770,8 @@ int main()
float sensitivity = 0.3f; // Sensibilité de la souris
// On modifie l'angle de la caméra grâce au déplacement relatif sur X de la souris
camAngles.yaw = Nz::NormalizeAngle(camAngles.yaw - event.mouseMove.deltaX*sensitivity);
camAngles.yaw = camAngles.yaw - event.mouseMove.deltaX*sensitivity;
camAngles.yaw.Normalize();
// Idem, mais pour éviter les problèmes de calcul de la matrice de vue, on restreint les angles
camAngles.pitch = Nz::Clamp(camAngles.pitch + event.mouseMove.deltaY*sensitivity, -89.f, 89.f);
@ -802,7 +803,7 @@ int main()
case Nz::WindowEventType::Resized:
{
Nz::Vector2ui windowSize = window.GetSize();
Nz::AccessByOffset<Nz::Matrix4f&>(viewerDataBuffer.data(), viewerUboOffsets.projMatrixOffset) = Nz::Matrix4f::Perspective(70.f, float(windowSize.x) / windowSize.y, 0.1f, 1000.f);
Nz::AccessByOffset<Nz::Matrix4f&>(viewerDataBuffer.data(), viewerUboOffsets.projMatrixOffset) = Nz::Matrix4f::Perspective(Nz::DegreeAnglef(70.f), float(windowSize.x) / windowSize.y, 0.1f, 1000.f);
viewerUboUpdate = true;
break;
}

View File

@ -83,7 +83,7 @@ int main()
Nz::Vector2ui windowSize = window.GetSize();
Nz::AccessByOffset<Nz::Matrix4f&>(viewerDataBuffer.data(), viewerUboOffsets.viewMatrixOffset) = Nz::Matrix4f::Translate(Nz::Vector3f::Backward() * 1);
Nz::AccessByOffset<Nz::Matrix4f&>(viewerDataBuffer.data(), viewerUboOffsets.projMatrixOffset) = Nz::Matrix4f::Perspective(70.f, float(windowSize.x) / windowSize.y, 0.1f, 1000.f);
Nz::AccessByOffset<Nz::Matrix4f&>(viewerDataBuffer.data(), viewerUboOffsets.projMatrixOffset) = Nz::Matrix4f::Perspective(Nz::DegreeAnglef(70.f), float(windowSize.x) / windowSize.y, 0.1f, 1000.f);
std::vector<std::uint8_t> instanceDataBuffer(instanceUboOffsets.totalSize);
@ -186,7 +186,8 @@ int main()
float sensitivity = 0.3f; // Sensibilité de la souris
// On modifie l'angle de la caméra grâce au déplacement relatif sur X de la souris
camAngles.yaw = Nz::NormalizeAngle(camAngles.yaw - event.mouseMove.deltaX*sensitivity);
camAngles.yaw = camAngles.yaw - event.mouseMove.deltaX * sensitivity;
camAngles.yaw.Normalize();
// Idem, mais pour éviter les problèmes de calcul de la matrice de vue, on restreint les angles
camAngles.pitch = Nz::Clamp(camAngles.pitch + event.mouseMove.deltaY*sensitivity, -89.f, 89.f);
@ -200,7 +201,7 @@ int main()
case Nz::WindowEventType::Resized:
{
Nz::Vector2ui windowSize = window.GetSize();
Nz::AccessByOffset<Nz::Matrix4f&>(viewerDataBuffer.data(), viewerUboOffsets.projMatrixOffset) = Nz::Matrix4f::Perspective(70.f, float(windowSize.x) / windowSize.y, 0.1f, 1000.f);
Nz::AccessByOffset<Nz::Matrix4f&>(viewerDataBuffer.data(), viewerUboOffsets.projMatrixOffset) = Nz::Matrix4f::Perspective(Nz::DegreeAnglef(70.f), float(windowSize.x) / windowSize.y, 0.1f, 1000.f);
viewerUboUpdate = true;
break;
}

View File

@ -145,7 +145,7 @@ int main()
ubo;
Nz::Vector2ui windowSize = window.GetSize();
ubo.projectionMatrix = Nz::Matrix4f::Perspective(70.f, float(windowSize.x) / windowSize.y, 0.1f, 1000.f);
ubo.projectionMatrix = Nz::Matrix4f::Perspective(Nz::DegreeAnglef(70.f), float(windowSize.x) / windowSize.y, 0.1f, 1000.f);
ubo.viewMatrix = Nz::Matrix4f::Translate(Nz::Vector3f::Backward() * 1);
ubo.modelMatrix = Nz::Matrix4f::Translate(Nz::Vector3f::Forward() * 2 + Nz::Vector3f::Right());
@ -291,7 +291,8 @@ int main()
float sensitivity = 0.3f; // Sensibilité de la souris
// On modifie l'angle de la caméra grâce au déplacement relatif sur X de la souris
camAngles.yaw = Nz::NormalizeAngle(camAngles.yaw - event.mouseMove.deltaX*sensitivity);
camAngles.yaw = camAngles.yaw - event.mouseMove.deltaX * sensitivity;
camAngles.yaw.Normalize();
// Idem, mais pour éviter les problèmes de calcul de la matrice de vue, on restreint les angles
camAngles.pitch = Nz::Clamp(camAngles.pitch + event.mouseMove.deltaY*sensitivity, -89.f, 89.f);
@ -305,7 +306,7 @@ int main()
case Nz::WindowEventType::Resized:
{
Nz::Vector2ui windowSize = window.GetSize();
ubo.projectionMatrix = Nz::Matrix4f::Perspective(70.f, float(windowSize.x) / windowSize.y, 0.1f, 1000.f);
ubo.projectionMatrix = Nz::Matrix4f::Perspective(Nz::DegreeAnglef(70.f), float(windowSize.x) / windowSize.y, 0.1f, 1000.f);
uboUpdate = true;
break;
}

View File

@ -9,6 +9,7 @@
#define NAZARA_ALGORITHM_MATH_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Math/Enums.hpp>
#include <cmath>
#include <limits>
#include <string>
@ -35,11 +36,12 @@
namespace Nz
{
template<AngleUnit Unit, typename T> class Angle;
template<typename T> constexpr T Approach(T value, T objective, T increment);
template<typename T> constexpr T Clamp(T value, T min, T max);
template<typename T, AngleUnit Unit> constexpr Angle<Unit, T> Clamp(Angle<Unit, T> value, T min, T max);
template<typename T> constexpr std::size_t CountBits(T value);
template<typename T> constexpr T FromDegrees(T degrees);
template<typename T> constexpr T FromRadians(T radians);
template<typename T> constexpr T DegreeToRadian(T degrees);
template<typename T> constexpr T GetNearestPowerOfTwo(T number);
constexpr unsigned int GetNumberLength(signed char number);
@ -56,7 +58,6 @@ namespace Nz
template<typename T> constexpr T IntegralPow(T base, unsigned int exponent);
template<typename T, typename T2> constexpr T Lerp(const T& from, const T& to, const T2& interpolation);
template<typename T> constexpr T MultiplyAdd(T x, T y, T z);
template<typename T> constexpr T NormalizeAngle(T angle);
template<typename T> constexpr bool NumberEquals(T a, T b);
template<typename T> constexpr bool NumberEquals(T a, T b, T maxDifference);
inline std::string NumberToString(long long number, UInt8 radix = 10);
@ -64,8 +65,6 @@ namespace Nz
template<typename T> T SetBit(T number, T bit);
inline long long StringToNumber(const std::string_view& str, UInt8 radix = 10, bool* ok = nullptr);
template<typename T> bool TestBit(T number, T bit);
template<typename T> constexpr T ToDegrees(T angle);
template<typename T> constexpr T ToRadians(T angle);
}
#include <Nazara/Math/Algorithm.inl>

View File

@ -157,6 +157,21 @@ namespace Nz
return std::max(std::min(value, max), min);
}
/*!
* \ingroup math
* \brief Clamps an angle value between min and max and returns the expected value
* \return If value is not in the interval of min..max, value obtained is the nearest limit of this interval
*
* \param value Value to clamp
* \param min Minimum of the interval
* \param max Maximum of the interval
*/
template<typename T, AngleUnit Unit>
constexpr Angle<Unit, T> Clamp(Angle<Unit, T> value, T min, T max)
{
return T();
}
/*!
* \ingroup math
* \brief Gets number of bits set in the number
@ -191,40 +206,6 @@ namespace Nz
return degrees * T(M_PI/180.0);
}
/*!
* \ingroup math
* \brief Gets the unit from degree and convert it according to NAZARA_MATH_ANGLE_RADIAN
* \return Express the degrees
*
* \param degrees Convert degree to NAZARA_MATH_ANGLE_RADIAN unit
*/
template<typename T>
constexpr T FromDegrees(T degrees)
{
#if NAZARA_MATH_ANGLE_RADIAN
return DegreeToRadian(degrees);
#else
return degrees;
#endif
}
/*!
* \ingroup math
* \brief Gets the unit from radian and convert it according to NAZARA_MATH_ANGLE_RADIAN
* \return Express the radians
*
* \param radians Convert radian to NAZARA_MATH_ANGLE_RADIAN unit
*/
template<typename T>
constexpr T FromRadians(T radians)
{
#if NAZARA_MATH_ANGLE_RADIAN
return radians;
#else
return RadianToDegree(radians);
#endif
}
/*!
* \ingroup math
* \brief Gets the nearest power of two for the number
@ -506,30 +487,6 @@ namespace Nz
}
#endif
/*!
* \ingroup math
* \brief Normalizes the angle
* \return Normalized value between 0..2*(pi if radian or 180 if degrees)
*
* \param angle Angle to normalize
*/
template<typename T>
constexpr inline T NormalizeAngle(T angle)
{
#if NAZARA_MATH_ANGLE_RADIAN
const T limit = T(M_PI);
#else
const T limit = T(180.0);
#endif
const T twoLimit = limit * T(2);
angle = std::fmod(angle, twoLimit);
if (angle < T(0))
angle += twoLimit;
return angle;
}
/*!
* \ingroup math
* \brief Checks whether two numbers are equal
@ -702,40 +659,7 @@ namespace Nz
NazaraAssert(bit < sizeof(number) * CHAR_BIT, "bit index out of range");
return number & (T(1) << bit);
}
/*!
* \ingroup math
* \brief Gets the degree from unit and convert it according to NAZARA_MATH_ANGLE_RADIAN
* \return Express in degrees
*
* \param angle Convert degree from NAZARA_MATH_ANGLE_RADIAN unit to degrees
*/
template<typename T>
constexpr T ToDegrees(T angle)
{
#if NAZARA_MATH_ANGLE_RADIAN
return RadianToDegree(angle);
#else
return angle;
#endif
}
/*!
* \ingroup math
* \brief Gets the radian from unit and convert it according to NAZARA_MATH_ANGLE_RADIAN
* \return Express in radians
*
* \param angle Convert degree from NAZARA_MATH_ANGLE_RADIAN unit to radians
*/
template<typename T>
constexpr T ToRadians(T angle)
{
#if NAZARA_MATH_ANGLE_RADIAN
return angle;
#else
return DegreeToRadian(angle);
#endif
}
}
#include <Nazara/Core/DebugOff.hpp>
#include "Algorithm.hpp"

View File

@ -26,11 +26,11 @@ namespace Nz
class Angle
{
public:
Angle() = default;
Angle(T angle);
Angle(const Angle<AngleUnit::Degree, T>& angle);
Angle(const Angle<AngleUnit::Radian, T>& angle);
template<typename U> explicit Angle(const Angle<Unit, U>& Angle);
constexpr Angle() = default;
constexpr Angle(T angle);
template<typename U> constexpr explicit Angle(const Angle<Unit, U>& Angle);
constexpr Angle(const Angle<AngleUnit::Degree, T>& angle);
constexpr Angle(const Angle<AngleUnit::Radian, T>& angle);
~Angle() = default;
T GetCos() const;
@ -38,39 +38,39 @@ namespace Nz
std::pair<T, T> GetSinCos() const;
T GetTan() const;
Angle& MakeZero();
constexpr Angle& MakeZero();
void Normalize();
constexpr Angle& Normalize();
Angle& Set(const Angle& ang);
template<typename U> Angle& Set(const Angle<Unit, U>& ang);
constexpr Angle& Set(const Angle& ang);
template<typename U> constexpr Angle& Set(const Angle<Unit, U>& ang);
T ToDegrees() const;
Angle<AngleUnit::Degree, T> ToDegreeAngle() const;
constexpr T ToDegrees() const;
constexpr Angle<AngleUnit::Degree, T> ToDegreeAngle() const;
EulerAngles<T> ToEulerAngles() const;
Quaternion<T> ToQuaternion() const;
T ToRadians() const;
Angle<AngleUnit::Radian, T> ToRadianAngle() const;
constexpr T ToRadians() const;
constexpr Angle<AngleUnit::Radian, T> ToRadianAngle() const;
std::string ToString() const;
Angle& operator=(const Angle&) = default;
constexpr Angle& operator=(const Angle&) = default;
Angle operator+(const Angle& other) const;
Angle operator-(const Angle& other) const;
Angle operator*(T scalar) const;
Angle operator/(T divider) const;
constexpr Angle operator+(const Angle& other) const;
constexpr Angle operator-(const Angle& other) const;
constexpr Angle operator*(T scalar) const;
constexpr Angle operator/(T divider) const;
Angle& operator+=(const Angle& other);
Angle& operator-=(const Angle& other);
Angle& operator*=(T scalar);
Angle& operator/=(T divider);
constexpr Angle& operator+=(const Angle& other);
constexpr Angle& operator-=(const Angle& other);
constexpr Angle& operator*=(T scalar);
constexpr Angle& operator/=(T divider);
bool operator==(const Angle& other) const;
bool operator!=(const Angle& other) const;
constexpr bool operator==(const Angle& other) const;
constexpr bool operator!=(const Angle& other) const;
static Angle FromDegrees(T ang);
static Angle FromRadians(T ang);
static Angle Zero();
static constexpr Angle FromDegrees(T ang);
static constexpr Angle FromRadians(T ang);
static constexpr Angle Zero();
T value;
};

View File

@ -32,22 +32,22 @@ namespace Nz
return 180;
}
template<typename T> static T FromDegrees(T degrees)
template<typename T> static constexpr T FromDegrees(T degrees)
{
return degrees;
}
template<typename T> static T FromRadians(T radians)
template<typename T> static constexpr T FromRadians(T radians)
{
return RadianToDegree(radians);
}
template<typename T> static T ToDegrees(T degrees)
template<typename T> static constexpr T ToDegrees(T degrees)
{
return degrees;
}
template<typename T> static T ToRadians(T degrees)
template<typename T> static constexpr T ToRadians(T degrees)
{
return DegreeToRadian(degrees);
}
@ -71,22 +71,22 @@ namespace Nz
return T(M_PI);
}
template<typename T> static T FromDegrees(T degrees)
template<typename T> static constexpr T FromDegrees(T degrees)
{
return DegreeToRadian(degrees);
}
template<typename T> static T FromRadians(T radians)
template<typename T> static constexpr T FromRadians(T radians)
{
return radians;
}
template<typename T> static T ToDegrees(T radians)
template<typename T> static constexpr T ToDegrees(T radians)
{
return RadianToDegree(radians);
}
template<typename T> static T ToRadians(T radians)
template<typename T> static constexpr T ToRadians(T radians)
{
return radians;
}
@ -141,7 +141,7 @@ namespace Nz
* \param value value of the angle
*/
template<AngleUnit Unit, typename T>
Angle<Unit, T>::Angle(T angle) :
constexpr Angle<Unit, T>::Angle(T angle) :
value(angle)
{
}
@ -152,7 +152,7 @@ namespace Nz
* \param value Angle object to copy
*/
template<AngleUnit Unit, typename T>
Angle<Unit, T>::Angle(const Angle<AngleUnit::Degree, T>& angle) :
constexpr Angle<Unit, T>::Angle(const Angle<AngleUnit::Degree, T>& angle) :
value(Detail::AngleUtils<Unit>::FromDegrees(angle.value))
{
}
@ -163,7 +163,7 @@ namespace Nz
* \param value Angle object to copy
*/
template<AngleUnit Unit, typename T>
Angle<Unit, T>::Angle(const Angle<AngleUnit::Radian, T>& angle) :
constexpr Angle<Unit, T>::Angle(const Angle<AngleUnit::Radian, T>& angle) :
value(Detail::AngleUtils<Unit>::FromRadians(angle.value))
{
}
@ -225,7 +225,7 @@ namespace Nz
* \brief Changes the angle value to zero
*/
template<AngleUnit Unit, typename T>
Angle<Unit, T>& Angle<Unit, T>::MakeZero()
constexpr Angle<Unit, T>& Angle<Unit, T>::MakeZero()
{
value = T(0);
return *this;
@ -239,7 +239,7 @@ namespace Nz
* For radian angles, local limits are [-M_PI, M_PI]
*/
template<AngleUnit Unit, typename T>
void Angle<Unit, T>::Normalize()
constexpr Angle<Unit, T>& Angle<Unit, T>::Normalize()
{
constexpr T limit = Detail::AngleUtils<Unit>::template GetLimit<T>();
constexpr T twoLimit = limit * T(2);
@ -247,6 +247,8 @@ namespace Nz
value = std::fmod(value, twoLimit);
if (value < T(0))
value += twoLimit;
return *this;
}
/*!
@ -255,7 +257,7 @@ namespace Nz
* \param Angle Angle which will be copied
*/
template<AngleUnit Unit, typename T>
Angle<Unit, T>& Angle<Unit, T>::Set(const Angle& ang)
constexpr Angle<Unit, T>& Angle<Unit, T>::Set(const Angle& ang)
{
value = ang.value;
return *this;
@ -270,7 +272,7 @@ namespace Nz
*/
template<AngleUnit Unit, typename T>
template<typename U>
Angle<Unit, T>& Angle<Unit, T>::Set(const Angle<Unit, U>& ang)
constexpr Angle<Unit, T>& Angle<Unit, T>::Set(const Angle<Unit, U>& ang)
{
value = static_cast<T>(ang.value);
return *this;
@ -281,7 +283,7 @@ namespace Nz
* \return Equivalent degree angle value
*/
template<AngleUnit Unit, typename T>
T Angle<Unit, T>::ToDegrees() const
constexpr T Angle<Unit, T>::ToDegrees() const
{
return Detail::AngleUtils<Unit>::ToDegrees(value);
}
@ -291,7 +293,7 @@ namespace Nz
* \return Equivalent degree angle
*/
template<AngleUnit Unit, typename T>
Angle<AngleUnit::Degree, T> Angle<Unit, T>::ToDegreeAngle() const
constexpr Angle<AngleUnit::Degree, T> Angle<Unit, T>::ToDegreeAngle() const
{
return DegreeAngle<T>(ToDegrees());
}
@ -329,7 +331,7 @@ namespace Nz
* \return Equivalent radian angle value
*/
template<AngleUnit Unit, typename T>
T Angle<Unit, T>::ToRadians() const
constexpr T Angle<Unit, T>::ToRadians() const
{
return Detail::AngleUtils<Unit>::ToRadians(value);
}
@ -339,7 +341,7 @@ namespace Nz
* \return Equivalent radian angle
*/
template<AngleUnit Unit, typename T>
Angle<AngleUnit::Radian, T> Angle<Unit, T>::ToRadianAngle() const
constexpr Angle<AngleUnit::Radian, T> Angle<Unit, T>::ToRadianAngle() const
{
return RadianAngle<T>(ToRadians());
}
@ -386,7 +388,7 @@ namespace Nz
* \param other Angle to add
*/
template<AngleUnit Unit, typename T>
Angle<Unit, T> Angle<Unit, T>::operator+(const Angle& other) const
constexpr Angle<Unit, T> Angle<Unit, T>::operator+(const Angle& other) const
{
return Angle(value + other.value);
}
@ -398,7 +400,7 @@ namespace Nz
* \param other Angle to subtract
*/
template<AngleUnit Unit, typename T>
Angle<Unit, T> Angle<Unit, T>::operator-(const Angle& other) const
constexpr Angle<Unit, T> Angle<Unit, T>::operator-(const Angle& other) const
{
return Angle(value - other.value);
}
@ -410,7 +412,7 @@ namespace Nz
* \param scalar Multiplier
*/
template<AngleUnit Unit, typename T>
Angle<Unit, T> Angle<Unit, T>::operator*(T scalar) const
constexpr Angle<Unit, T> Angle<Unit, T>::operator*(T scalar) const
{
return Angle(value * scalar);
}
@ -422,7 +424,7 @@ namespace Nz
* \param divider Divider
*/
template<AngleUnit Unit, typename T>
Angle<Unit, T> Angle<Unit, T>::operator/(T divider) const
constexpr Angle<Unit, T> Angle<Unit, T>::operator/(T divider) const
{
return Angle(value / divider);
}
@ -434,7 +436,7 @@ namespace Nz
* \param other Angle to add
*/
template<AngleUnit Unit, typename T>
Angle<Unit, T>& Angle<Unit, T>::operator+=(const Angle& other)
constexpr Angle<Unit, T>& Angle<Unit, T>::operator+=(const Angle& other)
{
value += other.value;
return *this;
@ -447,7 +449,7 @@ namespace Nz
* \param other Angle to subtract
*/
template<AngleUnit Unit, typename T>
Angle<Unit, T>& Angle<Unit, T>::operator-=(const Angle& other)
constexpr Angle<Unit, T>& Angle<Unit, T>::operator-=(const Angle& other)
{
value -= other.value;
return *this;
@ -460,7 +462,7 @@ namespace Nz
* \param scalar Multiplier
*/
template<AngleUnit Unit, typename T>
Angle<Unit, T>& Angle<Unit, T>::operator*=(T scalar)
constexpr Angle<Unit, T>& Angle<Unit, T>::operator*=(T scalar)
{
value *= scalar;
return *this;
@ -473,7 +475,7 @@ namespace Nz
* \param divider Divider
*/
template<AngleUnit Unit, typename T>
Angle<Unit, T>& Angle<Unit, T>::operator/=(T divider)
constexpr Angle<Unit, T>& Angle<Unit, T>::operator/=(T divider)
{
value /= divider;
return *this;
@ -486,7 +488,7 @@ namespace Nz
* \param other The other angle to compare to
*/
template<AngleUnit Unit, typename T>
bool Angle<Unit, T>::operator==(const Angle& other) const
constexpr bool Angle<Unit, T>::operator==(const Angle& other) const
{
return NumberEquals(value, other.value, Detail::AngleUtils<Unit>::template GetEpsilon<T>());
}
@ -498,7 +500,7 @@ namespace Nz
* \param other The other angle to compare to
*/
template<AngleUnit Unit, typename T>
bool Angle<Unit, T>::operator!=(const Angle& other) const
constexpr bool Angle<Unit, T>::operator!=(const Angle& other) const
{
return !NumberEquals(value, other.value, Detail::AngleUtils<Unit>::template GetEpsilon<T>());
}
@ -510,7 +512,7 @@ namespace Nz
* \param ang Degree angle
*/
template<AngleUnit Unit, typename T>
Angle<Unit, T> Angle<Unit, T>::FromDegrees(T ang)
constexpr Angle<Unit, T> Angle<Unit, T>::FromDegrees(T ang)
{
return Angle(Detail::AngleUtils<Unit>::FromDegrees(ang));
}
@ -522,7 +524,7 @@ namespace Nz
* \param ang Radian angle
*/
template<AngleUnit Unit, typename T>
Angle<Unit, T> Angle<Unit, T>::FromRadians(T ang)
constexpr Angle<Unit, T> Angle<Unit, T>::FromRadians(T ang)
{
return Angle(Detail::AngleUtils<Unit>::FromRadians(ang));
}
@ -532,7 +534,7 @@ namespace Nz
* \return Zero angle
*/
template<AngleUnit Unit, typename T>
Angle<Unit, T> Angle<Unit, T>::Zero()
constexpr Angle<Unit, T> Angle<Unit, T>::Zero()
{
Angle angle;
angle.MakeZero();

View File

@ -35,9 +35,6 @@
/// Each modification of a paramater of the module needs a recompilation of the unit
// Define the radian as unit for angles
#define NAZARA_MATH_ANGLE_RADIAN 0
// Optimize automatically the operation on affine matrices (Ask several comparisons to determine if the matrix is affine)
#define NAZARA_MATH_MATRIX4_CHECK_AFFINE 0

View File

@ -21,8 +21,8 @@ namespace Nz
{
public:
EulerAngles() = default;
EulerAngles(T P, T Y, T R);
EulerAngles(const T angles[3]);
EulerAngles(DegreeAngle<T> P, DegreeAngle<T> Y, DegreeAngle<T> R);
EulerAngles(const DegreeAngle<T> angles[3]);
template<AngleUnit Unit> EulerAngles(const Angle<Unit, T>& angle);
//EulerAngles(const Matrix3<T>& mat);
EulerAngles(const Quaternion<T>& quat);
@ -34,8 +34,8 @@ namespace Nz
EulerAngles& Normalize();
EulerAngles& Set(T P, T Y, T R);
EulerAngles& Set(const T angles[3]);
EulerAngles& Set(DegreeAngle<T> P, DegreeAngle<T> Y, DegreeAngle<T> R);
EulerAngles& Set(const DegreeAngle<T> angles[3]);
template<AngleUnit Unit> EulerAngles& Set(const Angle<Unit, T>& angles);
//EulerAngles& Set(const Matrix3<T>& mat);
EulerAngles& Set(const Quaternion<T>& quat);
@ -61,7 +61,7 @@ namespace Nz
static EulerAngles Zero();
T pitch, yaw, roll;
DegreeAngle<T> pitch, yaw, roll;
};
using EulerAnglesd = EulerAngles<double>;

View File

@ -32,7 +32,7 @@ namespace Nz
*/
template<typename T>
EulerAngles<T>::EulerAngles(T P, T Y, T R)
EulerAngles<T>::EulerAngles(DegreeAngle<T> P, DegreeAngle<T> Y, DegreeAngle<T> R)
{
Set(P, Y, R);
}
@ -44,7 +44,7 @@ namespace Nz
*/
template<typename T>
EulerAngles<T>::EulerAngles(const T angles[3])
EulerAngles<T>::EulerAngles(const DegreeAngle<T> angles[3])
{
Set(angles);
}
@ -101,17 +101,15 @@ namespace Nz
* \brief Normalizes the euler angle
* \return A reference to this euler angle with has been normalized
*
* \remark Normalization depends on NAZARA_MATH_ANGLE_RADIAN, between 0..2*pi
*
* \see NormalizeAngle
*/
template<typename T>
EulerAngles<T>& EulerAngles<T>::Normalize()
{
pitch = NormalizeAngle(pitch);
yaw = NormalizeAngle(yaw);
roll = NormalizeAngle(roll);
pitch.Normalize();
yaw.Normalize();
roll.Normalize();
return *this;
}
@ -126,7 +124,7 @@ namespace Nz
*/
template<typename T>
EulerAngles<T>& EulerAngles<T>::Set(T P, T Y, T R)
EulerAngles<T>& EulerAngles<T>::Set(DegreeAngle<T> P, DegreeAngle<T> Y, DegreeAngle<T> R)
{
pitch = P;
yaw = Y;
@ -143,7 +141,7 @@ namespace Nz
*/
template<typename T>
EulerAngles<T>& EulerAngles<T>::Set(const T angles[3])
EulerAngles<T>& EulerAngles<T>::Set(const DegreeAngle<T> angles[3])
{
pitch = angles[0];
yaw = angles[1];
@ -192,9 +190,9 @@ namespace Nz
template<typename U>
EulerAngles<T>& EulerAngles<T>::Set(const EulerAngles<U>& angles)
{
pitch = T(angles.pitch);
yaw = T(angles.yaw);
roll = T(angles.roll);
pitch.Set(angles.pitch);
yaw.Set(angles.yaw);
roll.Set(angles.roll);
return *this;
}
@ -208,13 +206,13 @@ namespace Nz
Quaternion<T> EulerAngles<T>::ToQuaternion() const
{
// XYZ
T c1 = std::cos(ToRadians(yaw) / T(2.0));
T c2 = std::cos(ToRadians(roll) / T(2.0));
T c3 = std::cos(ToRadians(pitch) / T(2.0));
T c1 = (yaw / T(2.0)).GetCos();
T c2 = (roll / T(2.0)).GetCos();
T c3 = (pitch / T(2.0)).GetCos();
T s1 = std::sin(ToRadians(yaw) / T(2.0));
T s2 = std::sin(ToRadians(roll) / T(2.0));
T s3 = std::sin(ToRadians(pitch) / T(2.0));
T s1 = (yaw / T(2.0)).GetSin();
T s2 = (roll / T(2.0)).GetSin();
T s3 = (pitch / T(2.0)).GetSin();
return Quaternion<T>(c1 * c2 * c3 - s1 * s2 * s3,
s1 * s2 * c3 + c1 * c2 * s3,
@ -310,9 +308,7 @@ namespace Nz
template<typename T>
bool EulerAngles<T>::operator==(const EulerAngles& angles) const
{
return NumberEquals(pitch, angles.pitch) &&
NumberEquals(yaw, angles.yaw) &&
NumberEquals(roll, angles.roll);
return pitch == angles.pitch && yaw == angles.yaw && roll == angles.roll;
}
/*!

View File

@ -7,6 +7,7 @@
#ifndef NAZARA_FRUSTUM_HPP
#define NAZARA_FRUSTUM_HPP
#include <Nazara/Math/Angle.hpp>
#include <Nazara/Math/BoundingVolume.hpp>
#include <Nazara/Math/Enums.hpp>
#include <Nazara/Math/Matrix4.hpp>
@ -29,7 +30,7 @@ namespace Nz
Frustum(const Frustum& frustum) = default;
~Frustum() = default;
Frustum& Build(T angle, T ratio, T zNear, T zFar, const Vector3<T>& eye, const Vector3<T>& target, const Vector3<T>& up = Vector3<T>::Up());
Frustum& Build(RadianAngle<T> angle, T ratio, T zNear, T zFar, const Vector3<T>& eye, const Vector3<T>& target, const Vector3<T>& up = Vector3<T>::Up());
bool Contains(const BoundingVolume<T>& volume) const;
bool Contains(const Box<T>& box) const;

View File

@ -40,7 +40,7 @@ namespace Nz
* \brief Builds the frustum object
* \return A reference to this frustum which is the build up camera's field of view
*
* \param angle Unit depends on NAZARA_MATH_ANGLE_RADIAN
* \param angle FOV angle
* \param ratio Rendering ratio (typically 16/9 or 4/3)
* \param zNear Distance where 'vision' begins
* \param zFar Distance where 'vision' ends
@ -50,15 +50,11 @@ namespace Nz
*/
template<typename T>
Frustum<T>& Frustum<T>::Build(T angle, T ratio, T zNear, T zFar, const Vector3<T>& eye, const Vector3<T>& target, const Vector3<T>& up)
Frustum<T>& Frustum<T>::Build(RadianAngle<T> angle, T ratio, T zNear, T zFar, const Vector3<T>& eye, const Vector3<T>& target, const Vector3<T>& up)
{
#if NAZARA_MATH_ANGLE_RADIAN
angle /= T(2.0);
#else
angle = DegreeToRadian(angle / T(2.0));
#endif
T tangent = std::tan(angle);
T tangent = angle.GetTan();
T nearH = zNear * tangent;
T nearW = nearH * ratio;
T farH = zFar * tangent;

View File

@ -10,6 +10,7 @@
///FIXME: Matrices column-major, difficile de bosser avec (Tout passer en row-major et transposer dans les shaders ?)
#include <Nazara/Core/TypeTag.hpp>
#include <Nazara/Math/Angle.hpp>
#include <Nazara/Math/Config.hpp>
#include <string>
@ -72,7 +73,7 @@ namespace Nz
Matrix4& MakeIdentity();
Matrix4& MakeLookAt(const Vector3<T>& eye, const Vector3<T>& target, const Vector3<T>& up = Vector3<T>::Up());
Matrix4& MakeOrtho(T left, T right, T top, T bottom, T zNear = -1.0, T zFar = 1.0);
Matrix4& MakePerspective(T angle, T ratio, T zNear, T zFar);
Matrix4& MakePerspective(RadianAngle<T> angle, T ratio, T zNear, T zFar);
Matrix4& MakeRotation(const Quaternion<T>& rotation);
Matrix4& MakeScale(const Vector3<T>& scale);
Matrix4& MakeTranslation(const Vector3<T>& translation);
@ -124,7 +125,7 @@ namespace Nz
static Matrix4 Identity();
static Matrix4 LookAt(const Vector3<T>& eye, const Vector3<T>& target, const Vector3<T>& up = Vector3<T>::Up());
static Matrix4 Ortho(T left, T right, T top, T bottom, T zNear = -1.0, T zFar = 1.0);
static Matrix4 Perspective(T angle, T ratio, T zNear, T zFar);
static Matrix4 Perspective(RadianAngle<T> angle, T ratio, T zNear, T zFar);
static Matrix4 Rotate(const Quaternion<T>& rotation);
static Matrix4 Scale(const Vector3<T>& scale);
static Matrix4 Translate(const Vector3<T>& translation);

View File

@ -903,7 +903,7 @@ namespace Nz
* \brief Makes the matrix a 'perspective matrix'
* \return A reference to this matrix transformed in 'perspective matrix'
*
* \param angle Unit depends on NAZARA_MATH_ANGLE_RADIAN
* \param angle FOV angle
* \param ratio Rendering ratio (typically 16/9 or 4/3)
* \param zNear Distance where 'vision' begins
* \param zFar Distance where 'vision' ends
@ -912,16 +912,12 @@ namespace Nz
*/
template<typename T>
Matrix4<T>& Matrix4<T>::MakePerspective(T angle, T ratio, T zNear, T zFar)
Matrix4<T>& Matrix4<T>::MakePerspective(RadianAngle<T> angle, T ratio, T zNear, T zFar)
{
// http://msdn.microsoft.com/en-us/library/windows/desktop/bb204945(v=vs.85).aspx
#if NAZARA_MATH_ANGLE_RADIAN
angle /= T(2.0);
#else
angle = DegreeToRadian(angle / T(2.0));
#endif
// https://docs.microsoft.com/fr-fr/windows/win32/direct3d10/d3d10-d3dxmatrixperspectivefovrh
angle = RadianAngle<T>(M_PI_2) - angle / T(2.0);
T yScale = std::tan(static_cast<T>(M_PI_2) - angle);
T yScale = angle.GetTan();
Set(yScale / ratio, T(0.0), T(0.0), T(0.0),
T(0.0), yScale, T(0.0), T(0.0),
@ -1598,7 +1594,7 @@ namespace Nz
* \brief Shorthand for the 'perspective' matrix
* \return A Matrix4 which is the 'perspective' matrix
*
* \param angle Unit depends on NAZARA_MATH_ANGLE_RADIAN
* \param angle FOV angle
* \param ratio Rendering ratio (typically 16/9 or 4/3)
* \param zNear Distance where 'vision' begins
* \param zFar Distance where 'vision' ends
@ -1607,7 +1603,7 @@ namespace Nz
*/
template<typename T>
Matrix4<T> Matrix4<T>::Perspective(T angle, T ratio, T zNear, T zFar)
Matrix4<T> Matrix4<T>::Perspective(RadianAngle<T> angle, T ratio, T zNear, T zFar)
{
Matrix4 matrix;
matrix.MakePerspective(angle, ratio, zNear, zFar);

View File

@ -24,7 +24,7 @@ namespace Nz
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(RadianAngle<T> angle, const Vector3<T>& axis);
Quaternion(const T quat[4]);
//Quaternion(const Matrix3<T>& mat);
template<typename U> explicit Quaternion(const Quaternion<U>& quat);
@ -53,7 +53,7 @@ namespace Nz
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(RadianAngle<T> angle, const Vector3<T>& normalizedAxis);
Quaternion& Set(const T quat[4]);
//Quaternion& Set(const Matrix3<T>& mat);
template<typename U> Quaternion& Set(const Quaternion<U>& quat);

View File

@ -66,12 +66,12 @@ namespace Nz
/*!
* \brief Constructs a Quaternion object from an angle and a direction
*
* \param angle Unit depends of NAZARA_MATH_ANGLE_RADIAN
* \param angle Angle to rotate along the axis
* \param axis Vector3 which represents a direction, no need to be normalized
*/
template<typename T>
Quaternion<T>::Quaternion(T angle, const Vector3<T>& axis)
Quaternion<T>::Quaternion(RadianAngle<T> angle, const Vector3<T>& axis)
{
Set(angle, axis);
}
@ -386,27 +386,23 @@ namespace Nz
* \brief Sets this quaternion from rotation specified by axis and angle
* \return A reference to this quaternion
*
* \param angle Unit depends of NAZARA_MATH_ANGLE_RADIAN
* \param angle Angle to rotate along the axis
* \param axis Vector3 which represents a direction, no need to be normalized
*/
template<typename T>
Quaternion<T>& Quaternion<T>::Set(T angle, const Vector3<T>& axis)
Quaternion<T>& Quaternion<T>::Set(RadianAngle<T> angle, const Vector3<T>& axis)
{
#if !NAZARA_MATH_ANGLE_RADIAN
angle = DegreeToRadian(angle);
#endif
angle /= T(2.0);
Vector3<T> normalizedAxis = axis.GetNormal();
T sinAngle = std::sin(angle);
auto sincos = angle.GetSinCos();
w = std::cos(angle);
x = normalizedAxis.x * sinAngle;
y = normalizedAxis.y * sinAngle;
z = normalizedAxis.z * sinAngle;
w = sincos.second;
x = normalizedAxis.x * sincos.first;
y = normalizedAxis.y * sincos.first;
z = normalizedAxis.z * sincos.first;
return Normalize();
}
@ -488,15 +484,15 @@ namespace Nz
T test = x * y + z * w;
if (test > T(0.499))
// singularity at north pole
return EulerAngles<T>(T(0.0), FromRadians(T(2.0) * std::atan2(x, w)), FromDegrees(T(90.0)));
return EulerAngles<T>(DegreeAngle<T>(T(0.0)), RadianAngle<T>(T(2.0) * std::atan2(x, w)), DegreeAngle<T>(T(90.0)));
if (test < T(-0.499))
// singularity at south pole
return EulerAngles<T>(T(0.0), FromRadians(T(-2.0) * std::atan2(x, w)), FromDegrees(T(-90.0)));
return EulerAngles<T>(DegreeAngle<T>(T(0.0)), RadianAngle<T>(T(-2.0) * std::atan2(x, w)), DegreeAngle<T>(T(-90.0)));
return EulerAngles<T>(FromRadians(std::atan2(T(2.0) * x * w - T(2.0) * y * z, T(1.0) - T(2.0) * x * x - T(2.0) * z * z)),
FromRadians(std::atan2(T(2.0) * y * w - T(2.0) * x * z, T(1.0) - T(2.0) * y * y - T(2.0) * z * z)),
FromRadians(std::asin(T(2.0) * test)));
return EulerAngles<T>(RadianAngle<T>(std::atan2(T(2.0) * x * w - T(2.0) * y * z, T(1.0) - T(2.0) * x * x - T(2.0) * z * z)),
RadianAngle<T>(std::atan2(T(2.0) * y * w - T(2.0) * x * z, T(1.0) - T(2.0) * y * y - T(2.0) * z * z)),
RadianAngle<T>(std::asin(T(2.0) * test)));
}
/*!

View File

@ -9,6 +9,7 @@
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/TypeTag.hpp>
#include <Nazara/Math/Angle.hpp>
#include <functional>
#include <string>
@ -33,7 +34,7 @@ namespace Nz
~Vector2() = default;
T AbsDotProduct(const Vector2& vec) const;
T AngleBetween(const Vector2& vec) const;
RadianAngle<T> AngleBetween(const Vector2& vec) const;
template<typename U = T>
U Distance(const Vector2& vec) const;

View File

@ -97,7 +97,7 @@ namespace Nz
/*!
* \brief Calculates the angle between two vectors in orthonormal basis
* \return The angle unit depends of NAZARA_MATH_ANGLE_RADIAN, you may want to normalize it to the range 0..2*pi with NormalizeAngle
* \return The angle
*
* \param vec The other vector to measure the angle with
*
@ -107,9 +107,9 @@ namespace Nz
*/
template<typename T>
T Vector2<T>::AngleBetween(const Vector2& vec) const
RadianAngle<T> Vector2<T>::AngleBetween(const Vector2& vec) const
{
return FromRadians(std::atan2(vec.y, vec.x) - std::atan2(y, x));
return std::atan2(vec.y, vec.x) - std::atan2(y, x);
}
/*!

View File

@ -9,6 +9,7 @@
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/TypeTag.hpp>
#include <Nazara/Math/Angle.hpp>
#include <functional>
#include <string>
@ -34,7 +35,7 @@ namespace Nz
~Vector3() = default;
T AbsDotProduct(const Vector3& vec) const;
T AngleBetween(const Vector3& vec) const;
RadianAngle<T> AngleBetween(const Vector3& vec) const;
Vector3 CrossProduct(const Vector3& vec) const;

View File

@ -107,7 +107,7 @@ namespace Nz
/*!
* \brief Calculates the angle between two vectors in orthonormal basis
* \return The angle unit depends of NAZARA_MATH_ANGLE_RADIAN in the range 0..pi
* \return The angle
*
* \param vec The other vector to measure the angle with
*
@ -118,7 +118,7 @@ namespace Nz
* \see NormalizeAngle
*/
template<typename T>
T Vector3<T>::AngleBetween(const Vector3& vec) const
RadianAngle<T> Vector3<T>::AngleBetween(const Vector3& vec) const
{
// sqrt(a) * sqrt(b) = sqrt(a*b)
T divisor = std::sqrt(GetSquaredLength() * vec.GetSquaredLength());
@ -134,7 +134,7 @@ namespace Nz
#endif
T alpha = DotProduct(vec) / divisor;
return FromRadians(std::acos(Clamp(alpha, T(-1.0), T(1.0))));
return std::acos(Clamp(alpha, T(-1.0), T(1.0)));
}
/*!

View File

@ -128,9 +128,7 @@ namespace Ndk
{
Nz::Quaternionf transition = newRotation * oldRotation.GetConjugate();
Nz::EulerAnglesf angles = transition.ToEulerAngles();
Nz::Vector3f angularVelocity(Nz::ToRadians(angles.pitch * invElapsedTime),
Nz::ToRadians(angles.yaw * invElapsedTime),
Nz::ToRadians(angles.roll * invElapsedTime));
Nz::Vector3f angularVelocity((angles.pitch * invElapsedTime).ToRadians(), (angles.yaw * invElapsedTime).ToRadians(), (angles.roll * invElapsedTime).ToRadians());
physObj->SetRotation(oldRotation);
physObj->SetAngularVelocity(angularVelocity);

View File

@ -1,4 +1,5 @@
#include <Nazara/Math/Algorithm.hpp>
#include <Nazara/Math/Angle.hpp>
#include <Catch/catch.hpp>
#include <limits>
@ -208,62 +209,62 @@ TEST_CASE("NormalizeAngle", "[MATH][ALGORITHM]")
{
SECTION("-90 should be normalized to +270")
{
REQUIRE(Nz::NormalizeAngle(Nz::FromDegrees(-90.f)) == Nz::FromDegrees(270.f));
REQUIRE(Nz::DegreeAnglef(-90.f).Normalize() == Nz::DegreeAnglef(270.f));
}
SECTION("-540 should be normalized to +180")
{
REQUIRE(Nz::NormalizeAngle(Nz::FromDegrees(-540.f)) == Nz::FromDegrees(180.f));
REQUIRE(Nz::DegreeAnglef(-540.f).Normalize() == Nz::DegreeAnglef(180.f));
}
SECTION("0 should remain 0")
{
REQUIRE(Nz::NormalizeAngle(Nz::FromDegrees(0.f)) == Nz::FromDegrees(0.f));
REQUIRE(Nz::DegreeAnglef(0.f).Normalize() == Nz::DegreeAnglef(0.f));
}
SECTION("90 should remain 90")
{
REQUIRE(Nz::NormalizeAngle(Nz::FromDegrees(90.f)) == Nz::FromDegrees(90.f));
REQUIRE(Nz::DegreeAnglef(90.f).Normalize() == Nz::DegreeAnglef(90.f));
}
SECTION("360 should be normalized to 0")
{
REQUIRE(Nz::NormalizeAngle(Nz::FromDegrees(360.f)) == Nz::FromDegrees(0.f));
REQUIRE(Nz::DegreeAnglef(360.f).Normalize() == Nz::DegreeAnglef(0.f));
}
SECTION("450 should be normalized to 90")
{
REQUIRE(Nz::NormalizeAngle(Nz::FromDegrees(450.f)) == Nz::FromDegrees(90.f));
REQUIRE(Nz::DegreeAnglef(450.f).Normalize() == Nz::DegreeAnglef(90.f));
}
SECTION("-90 should be normalized to +270")
{
REQUIRE(Nz::NormalizeAngle(Nz::FromDegrees(-90)) == Nz::FromDegrees(270));
REQUIRE(Nz::DegreeAnglef(-90).Normalize() == Nz::DegreeAnglef(270));
}
SECTION("-540 should be normalized to +180")
{
REQUIRE(Nz::NormalizeAngle(Nz::FromDegrees(-540)) == Nz::FromDegrees(180));
REQUIRE(Nz::DegreeAnglef(-540).Normalize() == Nz::DegreeAnglef(180));
}
SECTION("0 should remain 0")
{
REQUIRE(Nz::NormalizeAngle(Nz::FromDegrees(0)) == Nz::FromDegrees(0));
REQUIRE(Nz::DegreeAnglef(0).Normalize() == Nz::DegreeAnglef(0));
}
SECTION("90 should remain 90")
{
REQUIRE(Nz::NormalizeAngle(Nz::FromDegrees(90)) == Nz::FromDegrees(90));
REQUIRE(Nz::DegreeAnglef(90).Normalize() == Nz::DegreeAnglef(90));
}
SECTION("360 should be normalized to 0")
{
REQUIRE(Nz::NormalizeAngle(Nz::FromDegrees(360)) == Nz::FromDegrees(0));
REQUIRE(Nz::DegreeAnglef(360).Normalize() == Nz::DegreeAnglef(0));
}
SECTION("450 should be normalized to 90")
{
REQUIRE(Nz::NormalizeAngle(Nz::FromDegrees(450)) == Nz::FromDegrees(90));
REQUIRE(Nz::DegreeAnglef(450).Normalize() == Nz::DegreeAnglef(90));
}
}

View File

@ -16,8 +16,8 @@ SCENARIO("EulerAngles", "[MATH][EULERANGLES]")
WHEN("We do some operations")
{
Nz::EulerAnglesf euler90(Nz::FromDegrees(90.f), Nz::FromDegrees(90.f), Nz::FromDegrees(90.f));
Nz::EulerAnglesf euler270(Nz::FromDegrees(270.f), Nz::FromDegrees(270.f), Nz::FromDegrees(270.f));
Nz::EulerAnglesf euler90(Nz::DegreeAnglef(90.f), Nz::DegreeAnglef(90.f), Nz::DegreeAnglef(90.f));
Nz::EulerAnglesf euler270(Nz::DegreeAnglef(270.f), Nz::DegreeAnglef(270.f), Nz::DegreeAnglef(270.f));
Nz::EulerAnglesf euler360 = euler90 + euler270;
euler360.Normalize();
@ -45,9 +45,9 @@ SCENARIO("EulerAngles", "[MATH][EULERANGLES]")
GIVEN("Three rotation of 90 on each axis")
{
Nz::EulerAnglesf euler90P(Nz::FromDegrees(90.f), 0.f, 0.f);
Nz::EulerAnglesf euler90Y(0.f, Nz::FromDegrees(90.f), 0.f);
Nz::EulerAnglesf euler90R(0.f, 0.f, Nz::FromDegrees(90.f));
Nz::EulerAnglesf euler90P(Nz::DegreeAnglef(90.f), 0.f, 0.f);
Nz::EulerAnglesf euler90Y(0.f, Nz::DegreeAnglef(90.f), 0.f);
Nz::EulerAnglesf euler90R(0.f, 0.f, Nz::DegreeAnglef(90.f));
WHEN("We transform the axis")
{
@ -70,37 +70,37 @@ SCENARIO("EulerAngles", "[MATH][EULERANGLES]")
{
THEN("These results are expected")
{
CHECK(Nz::EulerAngles<int>(Nz::FromDegrees(45.f), 0.f, 0.f) == Nz::EulerAngles<int>(Nz::Quaternionf(0.923879504204f, 0.382683455944f, 0.f, 0.f).ToEulerAngles()));
CHECK(Nz::EulerAngles<int>(0.f, Nz::FromDegrees(45.f), 0.f) == Nz::EulerAngles<int>(Nz::Quaternionf(0.923879504204f, 0.f, 0.382683455944f, 0.f).ToEulerAngles()));
CHECK(Nz::EulerAngles<int>(0.f, 0.f, Nz::FromDegrees(45.f)) == Nz::EulerAngles<int>(Nz::Quaternionf(0.923879504204f, 0.f, 0.f, 0.382683455944f).ToEulerAngles()));
CHECK(Nz::EulerAnglesf(Nz::DegreeAnglef(45.f), 0.f, 0.f) == Nz::EulerAnglesf(Nz::Quaternionf(0.923879504204f, 0.382683455944f, 0.f, 0.f).ToEulerAngles()));
CHECK(Nz::EulerAnglesf(0.f, Nz::DegreeAnglef(45.f), 0.f) == Nz::EulerAnglesf(Nz::Quaternionf(0.923879504204f, 0.f, 0.382683455944f, 0.f).ToEulerAngles()));
CHECK(Nz::EulerAnglesf(0.f, 0.f, Nz::DegreeAnglef(45.f)) == Nz::EulerAnglesf(Nz::Quaternionf(0.923879504204f, 0.f, 0.f, 0.382683455944f).ToEulerAngles()));
}
}
}
GIVEN("Three euler angles: (0, 22.5, 22.5), (90, 90, 0) and (30, 0, 30)")
{
Nz::EulerAnglesf euler45(Nz::FromDegrees(0.f), Nz::FromDegrees(22.5f), Nz::FromDegrees(22.5f));
Nz::EulerAnglesf euler90(Nz::FromDegrees(90.f), Nz::FromDegrees(90.f), Nz::FromDegrees(0.f));
Nz::EulerAnglesf euler30(Nz::FromDegrees(30.f), Nz::FromDegrees(0.f), Nz::FromDegrees(30.f));
Nz::EulerAnglesf euler45(Nz::DegreeAnglef(0.f), Nz::DegreeAnglef(22.5f), Nz::DegreeAnglef(22.5f));
Nz::EulerAnglesf euler90(Nz::DegreeAnglef(90.f), Nz::DegreeAnglef(90.f), Nz::DegreeAnglef(0.f));
Nz::EulerAnglesf euler30(Nz::DegreeAnglef(30.f), Nz::DegreeAnglef(0.f), Nz::DegreeAnglef(30.f));
WHEN("We convert them to quaternion")
{
THEN("And then convert to euler angles, we have identity")
{
Nz::EulerAnglesf tmp = Nz::Quaternionf(euler45.ToQuaternion()).ToEulerAngles();
CHECK(tmp.pitch == Approx(0.f));
CHECK(tmp.yaw == Approx(22.5f));
CHECK(tmp.roll == Approx(22.5f));
CHECK(tmp.pitch.ToDegrees() == Approx(0.f));
CHECK(tmp.yaw.ToDegrees() == Approx(22.5f));
CHECK(tmp.roll.ToDegrees() == Approx(22.5f));
tmp = Nz::Quaternionf(euler90.ToQuaternion()).ToEulerAngles();
CHECK(tmp.pitch == Approx(90.f));
CHECK(tmp.yaw == Approx(90.f));
CHECK(tmp.roll == Approx(0.f));
CHECK(tmp.pitch.ToDegrees() == Approx(90.f));
CHECK(tmp.yaw.ToDegrees() == Approx(90.f));
CHECK(tmp.roll.ToDegrees() == Approx(0.f));
tmp = Nz::Quaternionf(euler30.ToQuaternion()).ToEulerAngles();
CHECK(tmp.pitch == Approx(30.f));
CHECK(tmp.yaw == Approx(0.f).margin(0.0001f));
CHECK(tmp.roll == Approx(30.f));
CHECK(tmp.pitch.ToDegrees() == Approx(30.f));
CHECK(tmp.yaw.ToDegrees() == Approx(0.f).margin(0.0001f));
CHECK(tmp.roll.ToDegrees() == Approx(30.f));
}
}
}

View File

@ -6,7 +6,7 @@ SCENARIO("Frustum", "[MATH][FRUSTUM]")
GIVEN("One frustum (90, 1, 1, 1000, (0, 0, 0), (1, 0, 0))")
{
Nz::Frustumf frustum;
frustum.Build(Nz::FromDegrees(90.f), 1.f, 1.f, 1000.f, Nz::Vector3f::Zero(), Nz::Vector3f::UnitX());
frustum.Build(Nz::DegreeAnglef(90.f), 1.f, 1.f, 1000.f, Nz::Vector3f::Zero(), Nz::Vector3f::UnitX());
WHEN("We ask for intersection with objects outside the frustum")
{

View File

@ -102,42 +102,42 @@ SCENARIO("Matrix4", "[MATH][MATRIX4]")
{
THEN("Rotation around X")
{
transformedMatrix.MakeTransform(Nz::Vector3f::Zero(), Nz::EulerAnglesf(Nz::FromDegrees(45.f), 0.f, 0.f).ToQuaternion());
transformedMatrix.MakeTransform(Nz::Vector3f::Zero(), Nz::EulerAnglesf(Nz::DegreeAnglef(45.f), 0.f, 0.f).ToQuaternion());
Nz::Matrix4f rotation45X(1.f, 0.f, 0.f, 0.f,
0.f, std::sqrt(2.f) / 2.f, std::sqrt(2.f) / 2.f, 0.f,
0.f, -std::sqrt(2.f) / 2.f, std::sqrt(2.f) / 2.f, 0.f,
0.f, 0.f, 0.f, 1.f);
CHECK(transformedMatrix == rotation45X);
transformedMatrix.MakeTransform(Nz::Vector3f::Unit(), Nz::EulerAnglesf(Nz::FromDegrees(45.f), 0.f, 0.f).ToQuaternion());
transformedMatrix.MakeTransform(Nz::Vector3f::Unit(), Nz::EulerAnglesf(Nz::DegreeAnglef(45.f), 0.f, 0.f).ToQuaternion());
rotation45X.ApplyTranslation(Nz::Vector3f::Unit());
CHECK(transformedMatrix == rotation45X);
}
THEN("Rotation around Y")
{
transformedMatrix.MakeTransform(Nz::Vector3f::Zero(), Nz::EulerAnglesf(0.f, Nz::FromDegrees(45.f), 0.f).ToQuaternion());
transformedMatrix.MakeTransform(Nz::Vector3f::Zero(), Nz::EulerAnglesf(0.f, Nz::DegreeAnglef(45.f), 0.f).ToQuaternion());
Nz::Matrix4f rotation45Y(std::sqrt(2.f) / 2.f, 0.f, -std::sqrt(2.f) / 2.f, 0.f,
0.f, 1.f, 0.f, 0.f,
std::sqrt(2.f) / 2.f, 0.f, std::sqrt(2.f) / 2.f, 0.f,
0.f, 0.f, 0.f, 1.f);
CHECK(transformedMatrix == rotation45Y);
transformedMatrix.MakeTransform(Nz::Vector3f::Unit(), Nz::EulerAnglesf(0.f, Nz::FromDegrees(45.f), 0.f).ToQuaternion());
transformedMatrix.MakeTransform(Nz::Vector3f::Unit(), Nz::EulerAnglesf(0.f, Nz::DegreeAnglef(45.f), 0.f).ToQuaternion());
rotation45Y.ApplyTranslation(Nz::Vector3f::Unit());
CHECK(transformedMatrix == rotation45Y);
}
THEN("Rotation around Z")
{
transformedMatrix.MakeTransform(Nz::Vector3f::Zero(), Nz::EulerAnglesf(0.f, 0.f, Nz::FromDegrees(45.f)).ToQuaternion());
transformedMatrix.MakeTransform(Nz::Vector3f::Zero(), Nz::EulerAnglesf(0.f, 0.f, Nz::DegreeAnglef(45.f)).ToQuaternion());
Nz::Matrix4f rotation45Z( std::sqrt(2.f) / 2.f, std::sqrt(2.f) / 2.f, 0.f, 0.f,
-std::sqrt(2.f) / 2.f, std::sqrt(2.f) / 2.f, 0.f, 0.f,
0.f, 0.f, 1.f, 0.f,
0.f, 0.f, 0.f, 1.f);
CHECK(transformedMatrix == rotation45Z);
transformedMatrix.MakeTransform(Nz::Vector3f::Unit(), Nz::EulerAnglesf(Nz::EulerAnglesf(0.f, 0.f, Nz::FromDegrees(45.f)).ToQuaternion()));
transformedMatrix.MakeTransform(Nz::Vector3f::Unit(), Nz::EulerAnglesf(Nz::EulerAnglesf(0.f, 0.f, Nz::DegreeAnglef(45.f)).ToQuaternion()));
rotation45Z.ApplyTranslation(Nz::Vector3f::Unit());
CHECK(transformedMatrix == rotation45Z);
}
@ -157,7 +157,7 @@ SCENARIO("Matrix4", "[MATH][MATRIX4]")
WHEN("We rotate it from pitch 30")
{
Nz::Quaternionf rotation(Nz::EulerAnglesf(Nz::FromDegrees(30.f), 0.f, 0.f));
Nz::Quaternionf rotation(Nz::EulerAnglesf(Nz::DegreeAnglef(30.f), 0.f, 0.f));
identity.ApplyRotation(rotation);
THEN("We should retrieve it")
@ -168,7 +168,7 @@ SCENARIO("Matrix4", "[MATH][MATRIX4]")
WHEN("We rotate it from yaw 30")
{
Nz::Quaternionf rotation(Nz::EulerAnglesf(0.f, Nz::FromDegrees(30.f), 0.f));
Nz::Quaternionf rotation(Nz::EulerAnglesf(0.f, Nz::DegreeAnglef(30.f), 0.f));
identity.ApplyRotation(rotation);
THEN("We should retrieve it")
@ -179,7 +179,7 @@ SCENARIO("Matrix4", "[MATH][MATRIX4]")
WHEN("We rotate it from roll 30")
{
Nz::Quaternionf rotation(Nz::EulerAnglesf(0.f, 0.f, Nz::FromDegrees(30.f)));
Nz::Quaternionf rotation(Nz::EulerAnglesf(0.f, 0.f, Nz::DegreeAnglef(30.f)));
identity.ApplyRotation(rotation);
THEN("We should retrieve it")
@ -190,7 +190,7 @@ SCENARIO("Matrix4", "[MATH][MATRIX4]")
WHEN("We rotate it from a strange rotation")
{
Nz::Quaternionf rotation(Nz::EulerAnglesf(Nz::FromDegrees(10.f), Nz::FromDegrees(20.f), Nz::FromDegrees(30.f)));
Nz::Quaternionf rotation(Nz::EulerAnglesf(Nz::DegreeAnglef(10.f), Nz::DegreeAnglef(20.f), Nz::DegreeAnglef(30.f)));
identity.ApplyRotation(rotation);
THEN("We should retrieve it")
@ -213,7 +213,7 @@ SCENARIO("Matrix4", "[MATH][MATRIX4]")
AND_THEN("With a rotation")
{
identity.ApplyRotation(Nz::EulerAnglesf(Nz::FromDegrees(10.f), Nz::FromDegrees(20.f), Nz::FromDegrees(30.f)));
identity.ApplyRotation(Nz::EulerAnglesf(Nz::DegreeAnglef(10.f), Nz::DegreeAnglef(20.f), Nz::DegreeAnglef(30.f)));
Nz::Vector3f retrievedScale = identity.GetScale();
CHECK(retrievedScale.x == Approx(scale.x));
CHECK(retrievedScale.y == Approx(scale.y));
@ -248,12 +248,12 @@ SCENARIO("Matrix4", "[MATH][MATRIX4]")
Nz::Matrix4f simple = Nz::Matrix4f::Transform(simpleTranslation, simpleRotation, simpleScale);
Nz::Vector3f complexTranslation = Nz::Vector3f(-5.f, 7.f, 3.5f);
Nz::Quaternionf complexRotation = Nz::EulerAnglesf(Nz::FromDegrees(-22.5f), Nz::FromDegrees(30.f), Nz::FromDegrees(15.f));
Nz::Quaternionf complexRotation = Nz::EulerAnglesf(Nz::DegreeAnglef(-22.5f), Nz::DegreeAnglef(30.f), Nz::DegreeAnglef(15.f));
Nz::Vector3f complexScale = Nz::Vector3f(1.f, 2.f, 0.5f);
Nz::Matrix4f complex = Nz::Matrix4f::Transform(complexTranslation, complexRotation, complexScale);
Nz::Vector3f oppositeTranslation = Nz::Vector3f(-5.f, 7.f, 3.5f);
Nz::Quaternionf oppositeRotation = Nz::EulerAnglesf(Nz::FromDegrees(-90.f), Nz::FromDegrees(0.f), Nz::FromDegrees(0.f));
Nz::Quaternionf oppositeRotation = Nz::EulerAnglesf(Nz::DegreeAnglef(-90.f), Nz::DegreeAnglef(0.f), Nz::DegreeAnglef(0.f));
Nz::Vector3f oppositeScale = Nz::Vector3f(1.f, 2.f, 0.5f);
Nz::Matrix4f opposite = Nz::Matrix4f::Transform(oppositeTranslation, oppositeRotation, oppositeScale);
@ -280,7 +280,7 @@ SCENARIO("Matrix4", "[MATH][MATRIX4]")
{
Nz::Vector3f translation(-5.f, 3.f, 0.5);
Nz::Matrix4f initial = Nz::Matrix4f::Translate(translation);
Nz::Quaternionf rotation = Nz::EulerAnglesf(Nz::FromDegrees(30.f), Nz::FromDegrees(-90.f), 0.f);
Nz::Quaternionf rotation = Nz::EulerAnglesf(Nz::DegreeAnglef(30.f), Nz::DegreeAnglef(-90.f), 0.f);
initial.ApplyRotation(rotation);
Nz::Matrix4f simple = Nz::Matrix4f::Transform(-translation, rotation.GetInverse(), Nz::Vector3f::Unit());

View File

@ -5,7 +5,7 @@ SCENARIO("Quaternion", "[MATH][QUATERNION]")
{
GIVEN("Two quaternions (0, 1, 0, 0)")
{
Nz::Quaternionf firstQuaternion(Nz::FromDegrees(180.f), Nz::Vector3f::UnitX());
Nz::Quaternionf firstQuaternion(Nz::DegreeAnglef(180.f), Nz::Vector3f::UnitX());
Nz::Quaternionf secondQuaternion(0.f, 1.f, 0.f, 0.f);
WHEN("We compare them")
@ -97,7 +97,7 @@ SCENARIO("Quaternion", "[MATH][QUATERNION]")
GIVEN("Two different quaternions (10, (1, 0, 0) and (20, (1, 0, 0))")
{
Nz::Quaternionf x10 = Nz::Quaternionf(Nz::FromDegrees(10.f), Nz::Vector3f::UnitX());
Nz::Quaternionf x10 = Nz::Quaternionf(Nz::DegreeAnglef(10.f), Nz::Vector3f::UnitX());
Nz::Quaternionf x20 = x10 * x10;
Nz::Quaternionf x30a = x10 * x20;
@ -107,16 +107,16 @@ SCENARIO("Quaternion", "[MATH][QUATERNION]")
{
THEN("These results are expected")
{
REQUIRE(x20 == Nz::Quaternionf(Nz::FromDegrees(20.f), Nz::Vector3f::UnitX()));
REQUIRE(x20 == Nz::Quaternionf(Nz::DegreeAnglef(20.f), Nz::Vector3f::UnitX()));
REQUIRE(x30a == x30b);
}
}
WHEN("Convert euler to quaternion")
{
Nz::Quaternionf X45(Nz::EulerAnglesf(Nz::FromDegrees(45.f), 0.f, 0.f));
Nz::Quaternionf Y45(Nz::EulerAnglesf(0.f, Nz::FromDegrees(45.f), 0.f));
Nz::Quaternionf Z45(Nz::EulerAnglesf(0.f, 0.f, Nz::FromDegrees(45.f)));
Nz::Quaternionf X45(Nz::EulerAnglesf(Nz::DegreeAnglef(45.f), 0.f, 0.f));
Nz::Quaternionf Y45(Nz::EulerAnglesf(0.f, Nz::DegreeAnglef(45.f), 0.f));
Nz::Quaternionf Z45(Nz::EulerAnglesf(0.f, 0.f, Nz::DegreeAnglef(45.f)));
THEN("They must be equal")
{
@ -159,11 +159,11 @@ SCENARIO("Quaternion", "[MATH][QUATERNION]")
AND_THEN("The half of 45 is 22.5")
{
Nz::Quaternionf quaterionA(Nz::FromDegrees(0.f), Nz::Vector3f::UnitZ());
Nz::Quaternionf quaterionB(Nz::FromDegrees(45.f), Nz::Vector3f::UnitZ());
Nz::Quaternionf quaterionA(Nz::DegreeAnglef(0.f), Nz::Vector3f::UnitZ());
Nz::Quaternionf quaterionB(Nz::DegreeAnglef(45.f), Nz::Vector3f::UnitZ());
Nz::Quaternionf quaternionC = Nz::Quaternionf::Slerp(quaterionA, quaterionB, 0.5f);
Nz::Quaternionf unitZ225(Nz::FromDegrees(22.5f), Nz::Vector3f::UnitZ());
Nz::Quaternionf unitZ225(Nz::DegreeAnglef(22.5f), Nz::Vector3f::UnitZ());
REQUIRE(quaternionC.w == Approx(unitZ225.w));
REQUIRE(quaternionC.x == Approx(unitZ225.x));
REQUIRE(quaternionC.y == Approx(unitZ225.y));
@ -176,21 +176,21 @@ SCENARIO("Quaternion", "[MATH][QUATERNION]")
THEN("The rotation in right-handed is 90 degree on z")
{
Nz::Quaternionf rotationBetweenXY = Nz::Quaternionf::RotationBetween(Nz::Vector3f::UnitX(), Nz::Vector3f::UnitY());
Nz::Quaternionf rotation90Z(Nz::FromDegrees(90.f), Nz::Vector3f::UnitZ());
Nz::Quaternionf rotation90Z(Nz::DegreeAnglef(90.f), Nz::Vector3f::UnitZ());
REQUIRE(rotation90Z == rotationBetweenXY);
}
THEN("The rotation in right-handed is 90 degree on y")
{
Nz::Quaternionf rotationBetweenXZ = Nz::Quaternionf::RotationBetween(Nz::Vector3f::UnitX(), Nz::Vector3f::UnitZ());
Nz::Quaternionf rotation90Y(Nz::FromDegrees(-90.f), Nz::Vector3f::UnitY());
Nz::Quaternionf rotation90Y(Nz::DegreeAnglef(-90.f), Nz::Vector3f::UnitY());
REQUIRE(rotation90Y == rotationBetweenXZ);
}
THEN("The rotation in right-handed is 90 degree on x")
{
Nz::Quaternionf rotationBetweenYZ = Nz::Quaternionf::RotationBetween(Nz::Vector3f::UnitY(), Nz::Vector3f::UnitZ());
Nz::Quaternionf rotation90X(Nz::FromDegrees(90.f), Nz::Vector3f::UnitX());
Nz::Quaternionf rotation90X(Nz::DegreeAnglef(90.f), Nz::Vector3f::UnitX());
REQUIRE(rotation90X == rotationBetweenYZ);
}
@ -224,21 +224,21 @@ SCENARIO("Quaternion", "[MATH][QUATERNION]")
{
THEN("Those are equal to")
{
CHECK(Nz::NumberEquals(rotation90X.ToEulerAngles().pitch, Nz::FromDegrees(90.f), 0.1f));
CHECK(Nz::NumberEquals(rotation90Y.ToEulerAngles().yaw, Nz::FromDegrees(90.f), 0.1f));
CHECK(Nz::NumberEquals(rotation90Z.ToEulerAngles().roll, Nz::FromDegrees(90.f), 0.1f));
CHECK(Nz::NumberEquals(rotation90X.ToEulerAngles().pitch.ToDegrees(), 90.f, 0.1f));
CHECK(Nz::NumberEquals(rotation90Y.ToEulerAngles().yaw.ToDegrees(), 90.f, 0.1f));
CHECK(Nz::NumberEquals(rotation90Z.ToEulerAngles().roll.ToDegrees(), 90.f, 0.1f));
CHECK(rotation180X == Nz::EulerAnglesf(180.f, 0.f, 0.f));
CHECK(rotation180Y == Nz::EulerAnglesf(0.f, 180.f, 0.f));
CHECK(rotation180Z == Nz::EulerAnglesf(0.f, 0.f, 180.f));
CHECK(Nz::NumberEquals(rotation270X.ToEulerAngles().pitch, Nz::FromDegrees(-90.f), 0.1f));
CHECK(Nz::NumberEquals(rotation270Y.ToEulerAngles().yaw, Nz::FromDegrees(-90.f), 0.1f));
CHECK(Nz::NumberEquals(rotation270Z.ToEulerAngles().roll, Nz::FromDegrees(-90.f), 0.1f));
CHECK(Nz::NumberEquals(rotation270X.ToEulerAngles().pitch.ToDegrees(), -90.f, 0.1f));
CHECK(Nz::NumberEquals(rotation270Y.ToEulerAngles().yaw.ToDegrees(), -90.f, 0.1f));
CHECK(Nz::NumberEquals(rotation270Z.ToEulerAngles().roll.ToDegrees(), -90.f, 0.1f));
CHECK(Nz::NumberEquals(special.ToEulerAngles().pitch, Nz::FromDegrees(0.f), 0.1f));
CHECK(Nz::NumberEquals(special.ToEulerAngles().yaw, Nz::FromDegrees(1.f), 0.1f));
CHECK(Nz::NumberEquals(special.ToEulerAngles().roll, Nz::FromDegrees(90.f), 0.1f));
CHECK(Nz::NumberEquals(special.ToEulerAngles().pitch.ToDegrees(), 0.f, 0.1f));
CHECK(Nz::NumberEquals(special.ToEulerAngles().yaw.ToDegrees(), 1.f, 0.1f));
CHECK(Nz::NumberEquals(special.ToEulerAngles().roll.ToDegrees(), 90.f, 0.1f));
}
}
}

View File

@ -1,6 +1,6 @@
#include <Nazara/Math/Vector2.hpp>
#include <Catch/catch.hpp>
#include <Nazara/Math/Vector2.hpp>
#include <Nazara/Math/Vector4.hpp>
SCENARIO("Vector2", "[MATH][VECTOR2]")
@ -27,9 +27,9 @@ SCENARIO("Vector2", "[MATH][VECTOR2]")
{
REQUIRE(firstUnit.AbsDotProduct(tmp) == Approx(2.f));
REQUIRE(firstUnit.DotProduct(tmp) == Approx(0.f));
REQUIRE(firstUnit.AngleBetween(tmp) == Approx(Nz::FromDegrees(90.f)));
REQUIRE(firstUnit.AngleBetween(tmp) == Nz::DegreeAnglef(90.f));
Nz::Vector2f negativeUnitX = -Nz::Vector2f::UnitX();
REQUIRE(negativeUnitX.AngleBetween(negativeUnitX + Nz::Vector2f(0, 0.0000001f)) == Approx(Nz::FromDegrees(360.f)));
REQUIRE(negativeUnitX.AngleBetween(negativeUnitX + Nz::Vector2f(0, 0.0000001f)) == Nz::DegreeAnglef(360.f));
}
}

View File

@ -1,7 +1,6 @@
#include <Nazara/Math/Vector3.hpp>
#include <Catch/catch.hpp>
#include <Nazara/Math/Vector2.hpp>
#include <Nazara/Math/Vector3.hpp>
#include <Nazara/Math/Vector4.hpp>
SCENARIO("Vector3", "[MATH][VECTOR3]")
@ -27,8 +26,8 @@ SCENARIO("Vector3", "[MATH][VECTOR3]")
{
REQUIRE(firstUnit.AbsDotProduct(tmp) == Approx(2.f));
REQUIRE(firstUnit.DotProduct(tmp) == Approx(0.f));
REQUIRE(firstUnit.AngleBetween(tmp) == Approx(Nz::FromDegrees(90.f)));
REQUIRE(firstUnit.AngleBetween(-firstUnit) == Approx(Nz::FromDegrees(180.f)));
REQUIRE(firstUnit.AngleBetween(tmp) == Nz::DegreeAnglef(90.f));
REQUIRE(firstUnit.AngleBetween(-firstUnit) == Nz::DegreeAnglef(180.f));
}
}

View File

@ -99,7 +99,7 @@ SCENARIO("PhysicsSystem2D", "[NDK][PHYSICSSYSTEM2D]")
CHECK(physicsComponent2D.GetAngularVelocity() == angularSpeed);
CHECK(physicsComponent2D.GetAABB() == Nz::Rectf(-2.f, 0.f, 2.f, 1.f));
CHECK(physicsComponent2D.GetRotation() == Nz::RadianAnglef::FromDegrees(90.f));
CHECK(nodeComponent.GetRotation().ToEulerAngles().roll == Approx(Nz::FromDegrees(90.f)));
CHECK(nodeComponent.GetRotation().ToEulerAngles().roll == Nz::DegreeAnglef(90.f));
}
}
@ -147,7 +147,7 @@ SCENARIO("PhysicsSystem2D", "[NDK][PHYSICSSYSTEM2D]")
CHECK(physicsComponent2D.GetAABB() == Nz::Rectf(1.f, 4.f, 2.f, 1.f));
CHECK(physicsComponent2D.GetRotation() == 2.f * angularSpeed);
CHECK(nodeComponent.GetPosition() == position);
CHECK(nodeComponent.GetRotation().ToEulerAngles().roll == Approx(Nz::FromDegrees(90.f)));
CHECK(nodeComponent.GetRotation().ToEulerAngles().roll == Nz::DegreeAnglef(90.f));
}
}
}