Math: Improve code

This commit is contained in:
SirLynix 2023-12-20 16:13:36 +01:00
parent f2201404f3
commit baaea2a33f
2 changed files with 8 additions and 12 deletions

View File

@ -142,7 +142,7 @@ namespace Nz
#ifdef NAZARA_PLATFORM_LINUX
template<typename T>
void SinCos(std::enable_if_t<!std::is_same<T, float>::value && !std::is_same<T, long double>::value, double> x, T* sin, T* cos)
void SinCos(T x, T* sin, T* cos)
{
double s, c;
::sincos(x, &s, &c);
@ -151,14 +151,14 @@ namespace Nz
*cos = static_cast<T>(c);
}
template<typename T>
void SinCos(std::enable_if_t<std::is_same<T, float>::value, float> x, float* s, float* c)
template<>
inline void SinCos(float x, float* s, float* c)
{
::sincosf(x, s, c);
}
template<typename T>
void SinCos(std::enable_if_t<std::is_same<T, long double>::value, long double> x, long double* s, long double* c)
template<>
inline void SinCos(long double x, long double* s, long double* c)
{
::sincosl(x, s, c);
}

View File

@ -115,13 +115,9 @@ namespace Nz
Quaternion<T> EulerAngles<T>::ToQuaternion() const
{
// XYZ
T c1 = (yaw / T(2.0)).GetCos();
T c2 = (roll / T(2.0)).GetCos();
T c3 = (pitch / T(2.0)).GetCos();
T s1 = (yaw / T(2.0)).GetSin();
T s2 = (roll / T(2.0)).GetSin();
T s3 = (pitch / T(2.0)).GetSin();
auto [s1, c1] = (yaw / T(2.0)).GetSinCos();
auto [s2, c2] = (roll / T(2.0)).GetSinCos();
auto [s3, c3] = (pitch / T(2.0)).GetSinCos();
return Quaternion<T>(c1 * c2 * c3 - s1 * s2 * s3,
s1 * s2 * c3 + c1 * c2 * s3,