Math: Improve code
This commit is contained in:
parent
f2201404f3
commit
baaea2a33f
|
|
@ -142,7 +142,7 @@ namespace Nz
|
||||||
|
|
||||||
#ifdef NAZARA_PLATFORM_LINUX
|
#ifdef NAZARA_PLATFORM_LINUX
|
||||||
template<typename T>
|
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;
|
double s, c;
|
||||||
::sincos(x, &s, &c);
|
::sincos(x, &s, &c);
|
||||||
|
|
@ -151,14 +151,14 @@ namespace Nz
|
||||||
*cos = static_cast<T>(c);
|
*cos = static_cast<T>(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<>
|
||||||
void SinCos(std::enable_if_t<std::is_same<T, float>::value, float> x, float* s, float* c)
|
inline void SinCos(float x, float* s, float* c)
|
||||||
{
|
{
|
||||||
::sincosf(x, s, c);
|
::sincosf(x, s, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<>
|
||||||
void SinCos(std::enable_if_t<std::is_same<T, long double>::value, long double> x, long double* s, long double* c)
|
inline void SinCos(long double x, long double* s, long double* c)
|
||||||
{
|
{
|
||||||
::sincosl(x, s, c);
|
::sincosl(x, s, c);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -115,13 +115,9 @@ namespace Nz
|
||||||
Quaternion<T> EulerAngles<T>::ToQuaternion() const
|
Quaternion<T> EulerAngles<T>::ToQuaternion() const
|
||||||
{
|
{
|
||||||
// XYZ
|
// XYZ
|
||||||
T c1 = (yaw / T(2.0)).GetCos();
|
auto [s1, c1] = (yaw / T(2.0)).GetSinCos();
|
||||||
T c2 = (roll / T(2.0)).GetCos();
|
auto [s2, c2] = (roll / T(2.0)).GetSinCos();
|
||||||
T c3 = (pitch / T(2.0)).GetCos();
|
auto [s3, c3] = (pitch / T(2.0)).GetSinCos();
|
||||||
|
|
||||||
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,
|
return Quaternion<T>(c1 * c2 * c3 - s1 * s2 * s3,
|
||||||
s1 * s2 * c3 + c1 * c2 * s3,
|
s1 * s2 * c3 + c1 * c2 * s3,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue