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

@@ -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)));
}
/*!