Math: Replace M_PI defines with template constexpr constants
This commit is contained in:
@@ -14,28 +14,14 @@
|
||||
#include <limits>
|
||||
#include <string>
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.141592653589793238462643
|
||||
#endif
|
||||
|
||||
#ifndef M_PI_2
|
||||
#define M_PI_2 1.5707963267948966192313217
|
||||
#endif
|
||||
|
||||
#ifndef M_SQRT2
|
||||
#define M_SQRT2 1.4142135623730950488016887
|
||||
#endif
|
||||
|
||||
#ifndef M_SQRT3
|
||||
#define M_SQRT3 1.7320508075688772935274463
|
||||
#endif
|
||||
|
||||
#ifndef M_SQRT5
|
||||
#define M_SQRT5 2.23606797749979
|
||||
#endif
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
template<typename T> constexpr T HalfPi = T(1.5707963267948966192313216916398);
|
||||
template<typename T> constexpr T Pi = T(3.1415926535897932384626433832795);
|
||||
template<typename T> constexpr T Sqrt2 = T(1.4142135623730950488016887242097);
|
||||
template<typename T> constexpr T Sqrt3 = T(1.7320508075688772935274463415059);
|
||||
template<typename T> constexpr T Sqrt5 = T(2.2360679774997896964091736687313);
|
||||
|
||||
template<AngleUnit Unit, typename T> class Angle;
|
||||
|
||||
template<typename T> constexpr T Approach(T value, T objective, T increment);
|
||||
|
||||
@@ -203,7 +203,7 @@ namespace Nz
|
||||
template<typename T>
|
||||
constexpr T DegreeToRadian(T degrees)
|
||||
{
|
||||
return degrees * T(M_PI/180.0);
|
||||
return degrees * T(Pi<T>/180.0);
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -578,7 +578,7 @@ namespace Nz
|
||||
template<typename T>
|
||||
constexpr T RadianToDegree(T radians)
|
||||
{
|
||||
return radians * T(180.0/M_PI);
|
||||
return radians * T(180.0/Pi<T>);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
||||
@@ -68,7 +68,7 @@ namespace Nz
|
||||
|
||||
template<typename T> static constexpr T GetLimit()
|
||||
{
|
||||
return T(M_PI);
|
||||
return Pi<T>;
|
||||
}
|
||||
|
||||
template<typename T> static constexpr T FromDegrees(T degrees)
|
||||
@@ -236,7 +236,7 @@ namespace Nz
|
||||
*
|
||||
* If angle exceeds local limits positively or negatively, bring it back between them.
|
||||
* For degree angles, local limits are [-180, 180]
|
||||
* For radian angles, local limits are [-M_PI, M_PI]
|
||||
* For radian angles, local limits are [-Pi, Pi]
|
||||
*/
|
||||
template<AngleUnit Unit, typename T>
|
||||
constexpr Angle<Unit, T>& Angle<Unit, T>::Normalize()
|
||||
|
||||
@@ -915,7 +915,7 @@ namespace Nz
|
||||
Matrix4<T>& Matrix4<T>::MakePerspective(RadianAngle<T> angle, T ratio, T zNear, T zFar)
|
||||
{
|
||||
// https://docs.microsoft.com/fr-fr/windows/win32/direct3d10/d3d10-d3dxmatrixperspectivefovrh
|
||||
angle = RadianAngle<T>(M_PI_2) - angle / T(2.0);
|
||||
angle = RadianAngle<T>(HalfPi<T>) - angle / T(2.0);
|
||||
|
||||
T yScale = angle.GetTan();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user