Improved g++ compatibility. Still not tested well enough.
This commit is contained in:
parent
131a2239b3
commit
58c369e025
@ -32,6 +32,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="Collider.h" />
|
<ClInclude Include="Collider.h" />
|
||||||
<ClInclude Include="Constants.h" />
|
<ClInclude Include="Constants.h" />
|
||||||
|
<ClInclude Include="gcccompat.h" />
|
||||||
<ClInclude Include="Math.h" />
|
<ClInclude Include="Math.h" />
|
||||||
<ClInclude Include="Matrix4x4.h" />
|
<ClInclude Include="Matrix4x4.h" />
|
||||||
<ClInclude Include="Quaternion.h" />
|
<ClInclude Include="Quaternion.h" />
|
||||||
|
@ -80,5 +80,8 @@
|
|||||||
<ClInclude Include="Random.h">
|
<ClInclude Include="Random.h">
|
||||||
<Filter>Headerdateien</Filter>
|
<Filter>Headerdateien</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="gcccompat.h">
|
||||||
|
<Filter>Headerdateien</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
@ -1,9 +1,12 @@
|
|||||||
#include "Quaternion.h"
|
#include "Quaternion.h"
|
||||||
#include "Constants.h"
|
#include "Constants.h"
|
||||||
|
#include <algorithm>
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
//#define _EULE_NO_INTRINSICS_
|
//#define _EULE_NO_INTRINSICS_
|
||||||
#ifndef _EULE_NO_INTRINSICS_
|
#ifndef _EULE_NO_INTRINSICS_
|
||||||
#include <immintrin.h>
|
#include <immintrin.h>
|
||||||
|
#include "gcccompat.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
using namespace Eule;
|
using namespace Eule;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#include "Random.h"
|
#include "Random.h"
|
||||||
#include <Array>
|
#include <array>
|
||||||
|
|
||||||
using namespace Eule;
|
using namespace Eule;
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@ using namespace Eule;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// Good, optimized chad version for doubles
|
// Good, optimized chad version for doubles
|
||||||
|
template<>
|
||||||
double Vector2<double>::DotProduct(const Vector2<double>& other) const
|
double Vector2<double>::DotProduct(const Vector2<double>& other) const
|
||||||
{
|
{
|
||||||
#ifndef _EULE_NO_INTRINSICS_
|
#ifndef _EULE_NO_INTRINSICS_
|
||||||
@ -44,6 +45,7 @@ double Vector2<double>::DotProduct(const Vector2<double>& other) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Slow, lame version for intcels
|
// Slow, lame version for intcels
|
||||||
|
template<>
|
||||||
double Vector2<int>::DotProduct(const Vector2<int>& other) const
|
double Vector2<int>::DotProduct(const Vector2<int>& other) const
|
||||||
{
|
{
|
||||||
int iDot = (x * other.x) +
|
int iDot = (x * other.x) +
|
||||||
@ -55,6 +57,7 @@ double Vector2<int>::DotProduct(const Vector2<int>& other) const
|
|||||||
|
|
||||||
|
|
||||||
// Good, optimized chad version for doubles
|
// Good, optimized chad version for doubles
|
||||||
|
template<>
|
||||||
double Vector2<double>::CrossProduct(const Vector2<double>& other) const
|
double Vector2<double>::CrossProduct(const Vector2<double>& other) const
|
||||||
{
|
{
|
||||||
return (x * other.y) -
|
return (x * other.y) -
|
||||||
@ -62,6 +65,7 @@ double Vector2<double>::CrossProduct(const Vector2<double>& other) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Slow, lame version for intcels
|
// Slow, lame version for intcels
|
||||||
|
template<>
|
||||||
double Vector2<int>::CrossProduct(const Vector2<int>& other) const
|
double Vector2<int>::CrossProduct(const Vector2<int>& other) const
|
||||||
{
|
{
|
||||||
int iCross = (x * other.y) -
|
int iCross = (x * other.y) -
|
||||||
@ -73,6 +77,7 @@ double Vector2<int>::CrossProduct(const Vector2<int>& other) const
|
|||||||
|
|
||||||
|
|
||||||
// Good, optimized chad version for doubles
|
// Good, optimized chad version for doubles
|
||||||
|
template<>
|
||||||
double Vector2<double>::SqrMagnitude() const
|
double Vector2<double>::SqrMagnitude() const
|
||||||
{
|
{
|
||||||
// x.DotProduct(x) == x.SqrMagnitude()
|
// x.DotProduct(x) == x.SqrMagnitude()
|
||||||
@ -80,6 +85,7 @@ double Vector2<double>::SqrMagnitude() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Slow, lame version for intcels
|
// Slow, lame version for intcels
|
||||||
|
template<>
|
||||||
double Vector2<int>::SqrMagnitude() const
|
double Vector2<int>::SqrMagnitude() const
|
||||||
{
|
{
|
||||||
int iSqrMag = x*x + y*y;
|
int iSqrMag = x*x + y*y;
|
||||||
@ -93,7 +99,7 @@ double Vector2<T>::Magnitude() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<>
|
||||||
Vector2<double> Vector2<double>::VectorScale(const Vector2<double>& scalar) const
|
Vector2<double> Vector2<double>::VectorScale(const Vector2<double>& scalar) const
|
||||||
{
|
{
|
||||||
#ifndef _EULE_NO_INTRINSICS_
|
#ifndef _EULE_NO_INTRINSICS_
|
||||||
@ -124,6 +130,7 @@ Vector2<double> Vector2<double>::VectorScale(const Vector2<double>& scalar) cons
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<>
|
||||||
Vector2<int> Vector2<int>::VectorScale(const Vector2<int>& scalar) const
|
Vector2<int> Vector2<int>::VectorScale(const Vector2<int>& scalar) const
|
||||||
{
|
{
|
||||||
return Vector2<int>(
|
return Vector2<int>(
|
||||||
@ -143,6 +150,7 @@ Vector2<double> Vector2<T>::Normalize() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Method to normalize a Vector2d
|
// Method to normalize a Vector2d
|
||||||
|
template<>
|
||||||
void Vector2<double>::NormalizeSelf()
|
void Vector2<double>::NormalizeSelf()
|
||||||
{
|
{
|
||||||
double length = Magnitude();
|
double length = Magnitude();
|
||||||
@ -184,6 +192,7 @@ void Vector2<double>::NormalizeSelf()
|
|||||||
|
|
||||||
// You can't normalize an int vector, ffs!
|
// You can't normalize an int vector, ffs!
|
||||||
// But we need an implementation for T=int
|
// But we need an implementation for T=int
|
||||||
|
template<>
|
||||||
void Vector2<int>::NormalizeSelf()
|
void Vector2<int>::NormalizeSelf()
|
||||||
{
|
{
|
||||||
std::cerr << "Stop normalizing int-vectors!!" << std::endl;
|
std::cerr << "Stop normalizing int-vectors!!" << std::endl;
|
||||||
@ -195,6 +204,7 @@ void Vector2<int>::NormalizeSelf()
|
|||||||
|
|
||||||
|
|
||||||
// Good, optimized chad version for doubles
|
// Good, optimized chad version for doubles
|
||||||
|
template<>
|
||||||
void Vector2<double>::LerpSelf(const Vector2<double>& other, double t)
|
void Vector2<double>::LerpSelf(const Vector2<double>& other, double t)
|
||||||
{
|
{
|
||||||
const double it = 1.0 - t; // Inverse t
|
const double it = 1.0 - t; // Inverse t
|
||||||
@ -235,6 +245,7 @@ void Vector2<double>::LerpSelf(const Vector2<double>& other, double t)
|
|||||||
|
|
||||||
|
|
||||||
// Slow, lame version for intcels
|
// Slow, lame version for intcels
|
||||||
|
template<>
|
||||||
void Vector2<int>::LerpSelf(const Vector2<int>& other, double t)
|
void Vector2<int>::LerpSelf(const Vector2<int>& other, double t)
|
||||||
{
|
{
|
||||||
const double it = 1.0 - t; // Inverse t
|
const double it = 1.0 - t; // Inverse t
|
||||||
@ -245,6 +256,7 @@ void Vector2<int>::LerpSelf(const Vector2<int>& other, double t)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<>
|
||||||
Vector2<double> Vector2<double>::Lerp(const Vector2<double>& other, double t) const
|
Vector2<double> Vector2<double>::Lerp(const Vector2<double>& other, double t) const
|
||||||
{
|
{
|
||||||
Vector2d copy(*this);
|
Vector2d copy(*this);
|
||||||
@ -253,6 +265,7 @@ Vector2<double> Vector2<double>::Lerp(const Vector2<double>& other, double t) co
|
|||||||
return copy;
|
return copy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<>
|
||||||
Vector2<double> Vector2<int>::Lerp(const Vector2<int>& other, double t) const
|
Vector2<double> Vector2<int>::Lerp(const Vector2<int>& other, double t) const
|
||||||
{
|
{
|
||||||
Vector2d copy(this->ToDouble());
|
Vector2d copy(this->ToDouble());
|
||||||
@ -312,7 +325,7 @@ Vector2<double> Vector2<T>::ToDouble() const
|
|||||||
return Vector2<double>((double)x, (double)y);
|
return Vector2<double>((double)x, (double)y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<>
|
||||||
Vector2<double> Vector2<double>::operator+(const Vector2<double>& other) const
|
Vector2<double> Vector2<double>::operator+(const Vector2<double>& other) const
|
||||||
{
|
{
|
||||||
#ifndef _EULE_NO_INTRINSICS_
|
#ifndef _EULE_NO_INTRINSICS_
|
||||||
@ -353,6 +366,7 @@ Vector2<T> Vector2<T>::operator+(const Vector2<T>& other) const
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
template<>
|
||||||
void Vector2<double>::operator+=(const Vector2<double>& other)
|
void Vector2<double>::operator+=(const Vector2<double>& other)
|
||||||
{
|
{
|
||||||
#ifndef _EULE_NO_INTRINSICS_
|
#ifndef _EULE_NO_INTRINSICS_
|
||||||
@ -391,6 +405,7 @@ void Vector2<T>::operator+=(const Vector2<T>& other)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
template<>
|
||||||
Vector2<double> Vector2<double>::operator-(const Vector2<double>& other) const
|
Vector2<double> Vector2<double>::operator-(const Vector2<double>& other) const
|
||||||
{
|
{
|
||||||
#ifndef _EULE_NO_INTRINSICS_
|
#ifndef _EULE_NO_INTRINSICS_
|
||||||
@ -431,6 +446,7 @@ Vector2<T> Vector2<T>::operator-(const Vector2<T>& other) const
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
template<>
|
||||||
void Vector2<double>::operator-=(const Vector2<double>& other)
|
void Vector2<double>::operator-=(const Vector2<double>& other)
|
||||||
{
|
{
|
||||||
#ifndef _EULE_NO_INTRINSICS_
|
#ifndef _EULE_NO_INTRINSICS_
|
||||||
@ -469,6 +485,7 @@ void Vector2<T>::operator-=(const Vector2<T>& other)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
template<>
|
||||||
Vector2<double> Vector2<double>::operator*(const double scale) const
|
Vector2<double> Vector2<double>::operator*(const double scale) const
|
||||||
{
|
{
|
||||||
#ifndef _EULE_NO_INTRINSICS_
|
#ifndef _EULE_NO_INTRINSICS_
|
||||||
@ -510,6 +527,7 @@ Vector2<T> Vector2<T>::operator*(const T scale) const
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
template<>
|
||||||
void Vector2<double>::operator*=(const double scale)
|
void Vector2<double>::operator*=(const double scale)
|
||||||
{
|
{
|
||||||
#ifndef _EULE_NO_INTRINSICS_
|
#ifndef _EULE_NO_INTRINSICS_
|
||||||
@ -548,6 +566,7 @@ void Vector2<T>::operator*=(const T scale)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
template<>
|
||||||
Vector2<double> Vector2<double>::operator/(const double scale) const
|
Vector2<double> Vector2<double>::operator/(const double scale) const
|
||||||
{
|
{
|
||||||
#ifndef _EULE_NO_INTRINSICS_
|
#ifndef _EULE_NO_INTRINSICS_
|
||||||
@ -589,6 +608,7 @@ Vector2<T> Vector2<T>::operator/(const T scale) const
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
template<>
|
||||||
void Vector2<double>::operator/=(const double scale)
|
void Vector2<double>::operator/=(const double scale)
|
||||||
{
|
{
|
||||||
#ifndef _EULE_NO_INTRINSICS_
|
#ifndef _EULE_NO_INTRINSICS_
|
||||||
|
@ -19,6 +19,7 @@ using namespace Eule;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// Good, optimized chad version for doubles
|
// Good, optimized chad version for doubles
|
||||||
|
template<>
|
||||||
double Vector3<double>::DotProduct(const Vector3<double>& other) const
|
double Vector3<double>::DotProduct(const Vector3<double>& other) const
|
||||||
{
|
{
|
||||||
#ifndef _EULE_NO_INTRINSICS_
|
#ifndef _EULE_NO_INTRINSICS_
|
||||||
@ -45,6 +46,7 @@ double Vector3<double>::DotProduct(const Vector3<double>& other) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Slow, lame version for intcels
|
// Slow, lame version for intcels
|
||||||
|
template<>
|
||||||
double Vector3<int>::DotProduct(const Vector3<int>& other) const
|
double Vector3<int>::DotProduct(const Vector3<int>& other) const
|
||||||
{
|
{
|
||||||
int iDot = (x * other.x) + (y * other.y) + (z * other.z);
|
int iDot = (x * other.x) + (y * other.y) + (z * other.z);
|
||||||
@ -54,6 +56,7 @@ double Vector3<int>::DotProduct(const Vector3<int>& other) const
|
|||||||
|
|
||||||
|
|
||||||
// Good, optimized chad version for doubles
|
// Good, optimized chad version for doubles
|
||||||
|
template<>
|
||||||
Vector3<double> Vector3<double>::CrossProduct(const Vector3<double>& other) const
|
Vector3<double> Vector3<double>::CrossProduct(const Vector3<double>& other) const
|
||||||
{
|
{
|
||||||
Vector3<double> cp;
|
Vector3<double> cp;
|
||||||
@ -65,6 +68,7 @@ Vector3<double> Vector3<double>::CrossProduct(const Vector3<double>& other) cons
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Slow, lame version for intcels
|
// Slow, lame version for intcels
|
||||||
|
template<>
|
||||||
Vector3<double> Vector3<int>::CrossProduct(const Vector3<int>& other) const
|
Vector3<double> Vector3<int>::CrossProduct(const Vector3<int>& other) const
|
||||||
{
|
{
|
||||||
Vector3<double> cp;
|
Vector3<double> cp;
|
||||||
@ -78,6 +82,7 @@ Vector3<double> Vector3<int>::CrossProduct(const Vector3<int>& other) const
|
|||||||
|
|
||||||
|
|
||||||
// Good, optimized chad version for doubles
|
// Good, optimized chad version for doubles
|
||||||
|
template<>
|
||||||
double Vector3<double>::SqrMagnitude() const
|
double Vector3<double>::SqrMagnitude() const
|
||||||
{
|
{
|
||||||
// x.DotProduct(x) == x.SqrMagnitude()
|
// x.DotProduct(x) == x.SqrMagnitude()
|
||||||
@ -85,6 +90,7 @@ double Vector3<double>::SqrMagnitude() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Slow, lame version for intcels
|
// Slow, lame version for intcels
|
||||||
|
template<>
|
||||||
double Vector3<int>::SqrMagnitude() const
|
double Vector3<int>::SqrMagnitude() const
|
||||||
{
|
{
|
||||||
int iSqrMag = x*x + y*y + z*z;
|
int iSqrMag = x*x + y*y + z*z;
|
||||||
@ -99,6 +105,7 @@ double Vector3<T>::Magnitude() const
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
template<>
|
||||||
Vector3<double> Vector3<double>::VectorScale(const Vector3<double>& scalar) const
|
Vector3<double> Vector3<double>::VectorScale(const Vector3<double>& scalar) const
|
||||||
{
|
{
|
||||||
#ifndef _EULE_NO_INTRINSICS_
|
#ifndef _EULE_NO_INTRINSICS_
|
||||||
@ -132,6 +139,7 @@ Vector3<double> Vector3<double>::VectorScale(const Vector3<double>& scalar) cons
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<>
|
||||||
Vector3<int> Vector3<int>::VectorScale(const Vector3<int>& scalar) const
|
Vector3<int> Vector3<int>::VectorScale(const Vector3<int>& scalar) const
|
||||||
{
|
{
|
||||||
return Vector3<int>(
|
return Vector3<int>(
|
||||||
@ -153,6 +161,7 @@ Vector3<double> Vector3<T>::Normalize() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Method to normalize a Vector3d
|
// Method to normalize a Vector3d
|
||||||
|
template<>
|
||||||
void Vector3<double>::NormalizeSelf()
|
void Vector3<double>::NormalizeSelf()
|
||||||
{
|
{
|
||||||
const double length = Magnitude();
|
const double length = Magnitude();
|
||||||
@ -197,6 +206,7 @@ void Vector3<double>::NormalizeSelf()
|
|||||||
|
|
||||||
// You can't normalize an int vector, ffs!
|
// You can't normalize an int vector, ffs!
|
||||||
// But we need an implementation for T=int
|
// But we need an implementation for T=int
|
||||||
|
template<>
|
||||||
void Vector3<int>::NormalizeSelf()
|
void Vector3<int>::NormalizeSelf()
|
||||||
{
|
{
|
||||||
std::cerr << "Stop normalizing int-vectors!!" << std::endl;
|
std::cerr << "Stop normalizing int-vectors!!" << std::endl;
|
||||||
@ -266,6 +276,7 @@ const T& Vector3<T>::operator[](std::size_t idx) const
|
|||||||
|
|
||||||
|
|
||||||
// Good, optimized chad version for doubles
|
// Good, optimized chad version for doubles
|
||||||
|
template<>
|
||||||
void Vector3<double>::LerpSelf(const Vector3<double>& other, double t)
|
void Vector3<double>::LerpSelf(const Vector3<double>& other, double t)
|
||||||
{
|
{
|
||||||
const double it = 1.0 - t; // Inverse t
|
const double it = 1.0 - t; // Inverse t
|
||||||
@ -308,6 +319,7 @@ void Vector3<double>::LerpSelf(const Vector3<double>& other, double t)
|
|||||||
|
|
||||||
|
|
||||||
// Slow, lame version for intcels
|
// Slow, lame version for intcels
|
||||||
|
template<>
|
||||||
void Vector3<int>::LerpSelf(const Vector3<int>& other, double t)
|
void Vector3<int>::LerpSelf(const Vector3<int>& other, double t)
|
||||||
{
|
{
|
||||||
const double it = 1.0 - t; // Inverse t
|
const double it = 1.0 - t; // Inverse t
|
||||||
@ -319,6 +331,7 @@ void Vector3<int>::LerpSelf(const Vector3<int>& other, double t)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<>
|
||||||
Vector3<double> Vector3<double>::Lerp(const Vector3<double>& other, double t) const
|
Vector3<double> Vector3<double>::Lerp(const Vector3<double>& other, double t) const
|
||||||
{
|
{
|
||||||
Vector3d copy(*this);
|
Vector3d copy(*this);
|
||||||
@ -327,6 +340,7 @@ Vector3<double> Vector3<double>::Lerp(const Vector3<double>& other, double t) co
|
|||||||
return copy;
|
return copy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<>
|
||||||
Vector3<double> Vector3<int>::Lerp(const Vector3<int>& other, double t) const
|
Vector3<double> Vector3<int>::Lerp(const Vector3<int>& other, double t) const
|
||||||
{
|
{
|
||||||
Vector3d copy(this->ToDouble());
|
Vector3d copy(this->ToDouble());
|
||||||
@ -337,6 +351,7 @@ Vector3<double> Vector3<int>::Lerp(const Vector3<int>& other, double t) const
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
template<>
|
||||||
Vector3<double> Vector3<double>::operator+(const Vector3<double>& other) const
|
Vector3<double> Vector3<double>::operator+(const Vector3<double>& other) const
|
||||||
{
|
{
|
||||||
#ifndef _EULE_NO_INTRINSICS_
|
#ifndef _EULE_NO_INTRINSICS_
|
||||||
@ -380,6 +395,7 @@ Vector3<T> Vector3<T>::operator+(const Vector3<T>& other) const
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
template<>
|
||||||
void Vector3<double>::operator+=(const Vector3<double>& other)
|
void Vector3<double>::operator+=(const Vector3<double>& other)
|
||||||
{
|
{
|
||||||
#ifndef _EULE_NO_INTRINSICS_
|
#ifndef _EULE_NO_INTRINSICS_
|
||||||
@ -421,6 +437,7 @@ void Vector3<T>::operator+=(const Vector3<T>& other)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
template<>
|
||||||
Vector3<double> Vector3<double>::operator-(const Vector3<double>& other) const
|
Vector3<double> Vector3<double>::operator-(const Vector3<double>& other) const
|
||||||
{
|
{
|
||||||
#ifndef _EULE_NO_INTRINSICS_
|
#ifndef _EULE_NO_INTRINSICS_
|
||||||
@ -464,6 +481,7 @@ Vector3<T> Vector3<T>::operator-(const Vector3<T>& other) const
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
template<>
|
||||||
void Vector3<double>::operator-=(const Vector3<double>& other)
|
void Vector3<double>::operator-=(const Vector3<double>& other)
|
||||||
{
|
{
|
||||||
#ifndef _EULE_NO_INTRINSICS_
|
#ifndef _EULE_NO_INTRINSICS_
|
||||||
@ -505,6 +523,7 @@ void Vector3<T>::operator-=(const Vector3<T>& other)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
template<>
|
||||||
Vector3<double> Vector3<double>::operator*(const double scale) const
|
Vector3<double> Vector3<double>::operator*(const double scale) const
|
||||||
{
|
{
|
||||||
#ifndef _EULE_NO_INTRINSICS_
|
#ifndef _EULE_NO_INTRINSICS_
|
||||||
@ -549,6 +568,7 @@ Vector3<T> Vector3<T>::operator*(const T scale) const
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
template<>
|
||||||
void Vector3<double>::operator*=(const double scale)
|
void Vector3<double>::operator*=(const double scale)
|
||||||
{
|
{
|
||||||
#ifndef _EULE_NO_INTRINSICS_
|
#ifndef _EULE_NO_INTRINSICS_
|
||||||
@ -590,6 +610,7 @@ void Vector3<T>::operator*=(const T scale)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
template<>
|
||||||
Vector3<double> Vector3<double>::operator/(const double scale) const
|
Vector3<double> Vector3<double>::operator/(const double scale) const
|
||||||
{
|
{
|
||||||
#ifndef _EULE_NO_INTRINSICS_
|
#ifndef _EULE_NO_INTRINSICS_
|
||||||
@ -634,6 +655,7 @@ Vector3<T> Vector3<T>::operator/(const T scale) const
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
template<>
|
||||||
void Vector3<double>::operator/=(const double scale)
|
void Vector3<double>::operator/=(const double scale)
|
||||||
{
|
{
|
||||||
#ifndef _EULE_NO_INTRINSICS_
|
#ifndef _EULE_NO_INTRINSICS_
|
||||||
@ -674,6 +696,7 @@ void Vector3<T>::operator/=(const T scale)
|
|||||||
|
|
||||||
|
|
||||||
// Good, optimized chad version for doubles
|
// Good, optimized chad version for doubles
|
||||||
|
template<>
|
||||||
Vector3<double> Vector3<double>::operator*(const Matrix4x4& mat) const
|
Vector3<double> Vector3<double>::operator*(const Matrix4x4& mat) const
|
||||||
{
|
{
|
||||||
Vector3<double> newVec;
|
Vector3<double> newVec;
|
||||||
@ -727,6 +750,7 @@ Vector3<double> Vector3<double>::operator*(const Matrix4x4& mat) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Slow, lame version for intcels
|
// Slow, lame version for intcels
|
||||||
|
template<>
|
||||||
Vector3<int> Vector3<int>::operator*(const Matrix4x4& mat) const
|
Vector3<int> Vector3<int>::operator*(const Matrix4x4& mat) const
|
||||||
{
|
{
|
||||||
Vector3<double> newVec;
|
Vector3<double> newVec;
|
||||||
@ -751,6 +775,7 @@ Vector3<int> Vector3<int>::operator*(const Matrix4x4& mat) const
|
|||||||
|
|
||||||
|
|
||||||
// Good, optimized chad version for doubles
|
// Good, optimized chad version for doubles
|
||||||
|
template<>
|
||||||
void Vector3<double>::operator*=(const Matrix4x4& mat)
|
void Vector3<double>::operator*=(const Matrix4x4& mat)
|
||||||
{
|
{
|
||||||
#ifndef _EULE_NO_INTRINSICS_
|
#ifndef _EULE_NO_INTRINSICS_
|
||||||
@ -832,6 +857,7 @@ void Vector3<T>::operator=(Vector3<T>&& other) noexcept
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Slow, lame version for intcels
|
// Slow, lame version for intcels
|
||||||
|
template<>
|
||||||
void Vector3<int>::operator*=(const Matrix4x4& mat)
|
void Vector3<int>::operator*=(const Matrix4x4& mat)
|
||||||
{
|
{
|
||||||
Vector3<double> buffer(x, y, z);
|
Vector3<double> buffer(x, y, z);
|
||||||
|
@ -19,6 +19,7 @@ using namespace Eule;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// Good, optimized chad version for doubles
|
// Good, optimized chad version for doubles
|
||||||
|
template<>
|
||||||
double Vector4<double>::SqrMagnitude() const
|
double Vector4<double>::SqrMagnitude() const
|
||||||
{
|
{
|
||||||
return (x * x) +
|
return (x * x) +
|
||||||
@ -28,6 +29,7 @@ double Vector4<double>::SqrMagnitude() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Slow, lame version for intcels
|
// Slow, lame version for intcels
|
||||||
|
template<>
|
||||||
double Vector4<int>::SqrMagnitude() const
|
double Vector4<int>::SqrMagnitude() const
|
||||||
{
|
{
|
||||||
int iSqrMag = x*x + y*y + z*z + w*w;
|
int iSqrMag = x*x + y*y + z*z + w*w;
|
||||||
@ -41,6 +43,7 @@ double Vector4<T>::Magnitude() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<>
|
||||||
Vector4<double> Vector4<double>::VectorScale(const Vector4<double>& scalar) const
|
Vector4<double> Vector4<double>::VectorScale(const Vector4<double>& scalar) const
|
||||||
{
|
{
|
||||||
#ifndef _EULE_NO_INTRINSICS_
|
#ifndef _EULE_NO_INTRINSICS_
|
||||||
@ -76,6 +79,7 @@ Vector4<double> Vector4<double>::VectorScale(const Vector4<double>& scalar) cons
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<>
|
||||||
Vector4<int> Vector4<int>::VectorScale(const Vector4<int>& scalar) const
|
Vector4<int> Vector4<int>::VectorScale(const Vector4<int>& scalar) const
|
||||||
{
|
{
|
||||||
return Vector4<int>(
|
return Vector4<int>(
|
||||||
@ -97,7 +101,8 @@ Vector4<double> Vector4<T>::Normalize() const
|
|||||||
return norm;
|
return norm;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Method to normalize a Vector43d
|
// Method to normalize a Vector4d
|
||||||
|
template<>
|
||||||
void Vector4<double>::NormalizeSelf()
|
void Vector4<double>::NormalizeSelf()
|
||||||
{
|
{
|
||||||
double length = Magnitude();
|
double length = Magnitude();
|
||||||
@ -145,6 +150,7 @@ void Vector4<double>::NormalizeSelf()
|
|||||||
|
|
||||||
// You can't normalize an int vector, ffs!
|
// You can't normalize an int vector, ffs!
|
||||||
// But we need an implementation for T=int
|
// But we need an implementation for T=int
|
||||||
|
template<>
|
||||||
void Vector4<int>::NormalizeSelf()
|
void Vector4<int>::NormalizeSelf()
|
||||||
{
|
{
|
||||||
std::cerr << "Stop normalizing int-vectors!!" << std::endl;
|
std::cerr << "Stop normalizing int-vectors!!" << std::endl;
|
||||||
@ -220,6 +226,7 @@ const T& Vector4<T>::operator[](std::size_t idx) const
|
|||||||
|
|
||||||
|
|
||||||
// Good, optimized chad version for doubles
|
// Good, optimized chad version for doubles
|
||||||
|
template<>
|
||||||
void Vector4<double>::LerpSelf(const Vector4<double>& other, double t)
|
void Vector4<double>::LerpSelf(const Vector4<double>& other, double t)
|
||||||
{
|
{
|
||||||
const double it = 1.0 - t; // Inverse t
|
const double it = 1.0 - t; // Inverse t
|
||||||
@ -264,6 +271,7 @@ void Vector4<double>::LerpSelf(const Vector4<double>& other, double t)
|
|||||||
|
|
||||||
|
|
||||||
// Slow, lame version for intcels
|
// Slow, lame version for intcels
|
||||||
|
template<>
|
||||||
void Vector4<int>::LerpSelf(const Vector4<int>& other, double t)
|
void Vector4<int>::LerpSelf(const Vector4<int>& other, double t)
|
||||||
{
|
{
|
||||||
const double it = 1.0 - t;
|
const double it = 1.0 - t;
|
||||||
@ -276,6 +284,7 @@ void Vector4<int>::LerpSelf(const Vector4<int>& other, double t)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<>
|
||||||
Vector4<double> Vector4<double>::Lerp(const Vector4<double>& other, double t) const
|
Vector4<double> Vector4<double>::Lerp(const Vector4<double>& other, double t) const
|
||||||
{
|
{
|
||||||
Vector4d copy(*this);
|
Vector4d copy(*this);
|
||||||
@ -284,6 +293,7 @@ Vector4<double> Vector4<double>::Lerp(const Vector4<double>& other, double t) co
|
|||||||
return copy;
|
return copy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<>
|
||||||
Vector4<double> Vector4<int>::Lerp(const Vector4<int>& other, double t) const
|
Vector4<double> Vector4<int>::Lerp(const Vector4<int>& other, double t) const
|
||||||
{
|
{
|
||||||
Vector4d copy(this->ToDouble());
|
Vector4d copy(this->ToDouble());
|
||||||
@ -294,6 +304,7 @@ Vector4<double> Vector4<int>::Lerp(const Vector4<int>& other, double t) const
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
template<>
|
||||||
Vector4<double> Vector4<double>::operator+(const Vector4<double>& other) const
|
Vector4<double> Vector4<double>::operator+(const Vector4<double>& other) const
|
||||||
{
|
{
|
||||||
#ifndef _EULE_NO_INTRINSICS_
|
#ifndef _EULE_NO_INTRINSICS_
|
||||||
@ -340,6 +351,7 @@ Vector4<T> Vector4<T>::operator+(const Vector4<T>& other) const
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
template<>
|
||||||
void Vector4<double>::operator+=(const Vector4<double>& other)
|
void Vector4<double>::operator+=(const Vector4<double>& other)
|
||||||
{
|
{
|
||||||
#ifndef _EULE_NO_INTRINSICS_
|
#ifndef _EULE_NO_INTRINSICS_
|
||||||
@ -384,6 +396,7 @@ void Vector4<T>::operator+=(const Vector4<T>& other)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
template<>
|
||||||
Vector4<double> Vector4<double>::operator-(const Vector4<double>& other) const
|
Vector4<double> Vector4<double>::operator-(const Vector4<double>& other) const
|
||||||
{
|
{
|
||||||
#ifndef _EULE_NO_INTRINSICS_
|
#ifndef _EULE_NO_INTRINSICS_
|
||||||
@ -430,6 +443,7 @@ Vector4<T> Vector4<T>::operator-(const Vector4<T>& other) const
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
template<>
|
||||||
void Vector4<double>::operator-=(const Vector4<double>& other)
|
void Vector4<double>::operator-=(const Vector4<double>& other)
|
||||||
{
|
{
|
||||||
#ifndef _EULE_NO_INTRINSICS_
|
#ifndef _EULE_NO_INTRINSICS_
|
||||||
@ -474,6 +488,7 @@ void Vector4<T>::operator-=(const Vector4<T>& other)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
template<>
|
||||||
Vector4<double> Vector4<double>::operator*(const double scale) const
|
Vector4<double> Vector4<double>::operator*(const double scale) const
|
||||||
{
|
{
|
||||||
#ifndef _EULE_NO_INTRINSICS_
|
#ifndef _EULE_NO_INTRINSICS_
|
||||||
@ -521,6 +536,7 @@ Vector4<T> Vector4<T>::operator*(const T scale) const
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
template<>
|
||||||
void Vector4<double>::operator*=(const double scale)
|
void Vector4<double>::operator*=(const double scale)
|
||||||
{
|
{
|
||||||
#ifndef _EULE_NO_INTRINSICS_
|
#ifndef _EULE_NO_INTRINSICS_
|
||||||
@ -565,6 +581,7 @@ void Vector4<T>::operator*=(const T scale)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
template<>
|
||||||
Vector4<double> Vector4<double>::operator/(const double scale) const
|
Vector4<double> Vector4<double>::operator/(const double scale) const
|
||||||
{
|
{
|
||||||
#ifndef _EULE_NO_INTRINSICS_
|
#ifndef _EULE_NO_INTRINSICS_
|
||||||
@ -612,6 +629,7 @@ Vector4<T> Vector4<T>::operator/(const T scale) const
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
template<>
|
||||||
void Vector4<double>::operator/=(const double scale)
|
void Vector4<double>::operator/=(const double scale)
|
||||||
{
|
{
|
||||||
#ifndef _EULE_NO_INTRINSICS_
|
#ifndef _EULE_NO_INTRINSICS_
|
||||||
@ -668,6 +686,7 @@ bool Vector4<T>::operator==(const Vector4<T>& other) const
|
|||||||
|
|
||||||
|
|
||||||
// Good, optimized chad version for doubles
|
// Good, optimized chad version for doubles
|
||||||
|
template<>
|
||||||
Vector4<double> Vector4<double>::operator*(const Matrix4x4& mat) const
|
Vector4<double> Vector4<double>::operator*(const Matrix4x4& mat) const
|
||||||
{
|
{
|
||||||
Vector4<double> newVec;
|
Vector4<double> newVec;
|
||||||
@ -681,6 +700,7 @@ Vector4<double> Vector4<double>::operator*(const Matrix4x4& mat) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Slow, lame version for intcels
|
// Slow, lame version for intcels
|
||||||
|
template<>
|
||||||
Vector4<int> Vector4<int>::operator*(const Matrix4x4& mat) const
|
Vector4<int> Vector4<int>::operator*(const Matrix4x4& mat) const
|
||||||
{
|
{
|
||||||
Vector4<double> newVec;
|
Vector4<double> newVec;
|
||||||
@ -701,6 +721,7 @@ Vector4<int> Vector4<int>::operator*(const Matrix4x4& mat) const
|
|||||||
|
|
||||||
|
|
||||||
// Good, optimized chad version for doubles
|
// Good, optimized chad version for doubles
|
||||||
|
template<>
|
||||||
void Vector4<double>::operator*=(const Matrix4x4& mat)
|
void Vector4<double>::operator*=(const Matrix4x4& mat)
|
||||||
{
|
{
|
||||||
Vector4<double> buffer = *this;
|
Vector4<double> buffer = *this;
|
||||||
@ -749,6 +770,7 @@ void Vector4<T>::operator=(Vector4<T>&& other) noexcept
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Slow, lame version for intcels
|
// Slow, lame version for intcels
|
||||||
|
template<>
|
||||||
void Vector4<int>::operator*=(const Matrix4x4& mat)
|
void Vector4<int>::operator*=(const Matrix4x4& mat)
|
||||||
{
|
{
|
||||||
Vector4<double> buffer(x, y, z, w);
|
Vector4<double> buffer(x, y, z, w);
|
||||||
|
35
Eule/gcccompat.h
Normal file
35
Eule/gcccompat.h
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Some intrinsic functions such as _mm_sincos_pd are not available on g++ by default (requires some specific library).
|
||||||
|
* So let's just "re"define them manually if we're on g++.
|
||||||
|
* This way the code still works, even with the other intrinsics enabled.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if (__GNUC__ && __cplusplus)
|
||||||
|
#include <immintrin.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
inline __m256d _mm256_sincos_pd(__m256d* __cos, __m256d __vec)
|
||||||
|
{
|
||||||
|
double vec[4];
|
||||||
|
|
||||||
|
_mm256_storeu_pd(vec, __vec);
|
||||||
|
|
||||||
|
// Manually calculate cosines
|
||||||
|
*__cos = _mm256_set_pd(
|
||||||
|
cos(vec[3]),
|
||||||
|
cos(vec[2]),
|
||||||
|
cos(vec[1]),
|
||||||
|
cos(vec[0])
|
||||||
|
);
|
||||||
|
|
||||||
|
// Manually calculate sines
|
||||||
|
return _mm256_set_pd(
|
||||||
|
sin(vec[3]),
|
||||||
|
sin(vec[2]),
|
||||||
|
sin(vec[1]),
|
||||||
|
sin(vec[0])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
#endif
|
Loading…
x
Reference in New Issue
Block a user