Disabled intrinsics and made Quaternions thread safe
This commit is contained in:
parent
68ac55b760
commit
b168289208
@ -2,7 +2,7 @@
|
|||||||
#include "Vector3.h"
|
#include "Vector3.h"
|
||||||
#include "Math.h"
|
#include "Math.h"
|
||||||
|
|
||||||
//#define _EULE_NO_INTRINSICS_
|
#define _EULE_NO_INTRINSICS_
|
||||||
#ifndef _EULE_NO_INTRINSICS_
|
#ifndef _EULE_NO_INTRINSICS_
|
||||||
#include <immintrin.h>
|
#include <immintrin.h>
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#include "Quaternion.h"
|
#include "Quaternion.h"
|
||||||
#include "Constants.h"
|
#include "Constants.h"
|
||||||
|
|
||||||
//#define _EULE_NO_INTRINSICS_
|
#define _EULE_NO_INTRINSICS_
|
||||||
#ifndef _EULE_NO_INTRINSICS_
|
#ifndef _EULE_NO_INTRINSICS_
|
||||||
#include <immintrin.h>
|
#include <immintrin.h>
|
||||||
#endif
|
#endif
|
||||||
@ -174,6 +174,8 @@ bool Quaternion::operator!= (const Quaternion& q) const
|
|||||||
|
|
||||||
Quaternion Quaternion::Inverse() const
|
Quaternion Quaternion::Inverse() const
|
||||||
{
|
{
|
||||||
|
const std::lock_guard<std::mutex> lock(lock_inverseCache);
|
||||||
|
|
||||||
if (!isCacheUpToDate_inverse)
|
if (!isCacheUpToDate_inverse)
|
||||||
{
|
{
|
||||||
cache_inverse = (Conjugate() * (1.0 / v.SqrMagnitude())).v;
|
cache_inverse = (Conjugate() * (1.0 / v.SqrMagnitude())).v;
|
||||||
@ -214,6 +216,8 @@ Vector3d Quaternion::RotateVector(const Vector3d& vec) const
|
|||||||
|
|
||||||
Vector3d Quaternion::ToEulerAngles() const
|
Vector3d Quaternion::ToEulerAngles() const
|
||||||
{
|
{
|
||||||
|
const std::lock_guard<std::mutex> lock(lock_eulerCache);
|
||||||
|
|
||||||
if (!isCacheUpToDate_euler)
|
if (!isCacheUpToDate_euler)
|
||||||
{
|
{
|
||||||
Vector3d euler;
|
Vector3d euler;
|
||||||
@ -245,6 +249,8 @@ Vector3d Quaternion::ToEulerAngles() const
|
|||||||
|
|
||||||
Matrix4x4 Quaternion::ToRotationMatrix() const
|
Matrix4x4 Quaternion::ToRotationMatrix() const
|
||||||
{
|
{
|
||||||
|
const std::lock_guard<std::mutex> lock(lock_matrixCache);
|
||||||
|
|
||||||
if (!isCacheUpToDate_matrix)
|
if (!isCacheUpToDate_matrix)
|
||||||
{
|
{
|
||||||
Matrix4x4 m;
|
Matrix4x4 m;
|
||||||
@ -328,7 +334,7 @@ namespace Eule
|
|||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::wostream& operator<<(std::wostream& os, const Quaternion& q)
|
std::wostream& operator<< (std::wostream& os, const Quaternion& q)
|
||||||
{
|
{
|
||||||
os << L"[" << q.v << L"]";
|
os << L"[" << q.v << L"]";
|
||||||
return os;
|
return os;
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#include "Vector3.h"
|
#include "Vector3.h"
|
||||||
#include "Vector4.h"
|
#include "Vector4.h"
|
||||||
#include "Matrix4x4.h"
|
#include "Matrix4x4.h"
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
namespace Eule
|
namespace Eule
|
||||||
{
|
{
|
||||||
@ -95,5 +96,9 @@ namespace Eule
|
|||||||
mutable bool isCacheUpToDate_inverse = false;
|
mutable bool isCacheUpToDate_inverse = false;
|
||||||
mutable Vector4d cache_inverse;
|
mutable Vector4d cache_inverse;
|
||||||
|
|
||||||
|
// Mutexes for thread-safe caching
|
||||||
|
mutable std::mutex lock_eulerCache;
|
||||||
|
mutable std::mutex lock_matrixCache;
|
||||||
|
mutable std::mutex lock_inverseCache;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#include "Math.h"
|
#include "Math.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
//#define _EULE_NO_INTRINSICS_
|
#define _EULE_NO_INTRINSICS_
|
||||||
#ifndef _EULE_NO_INTRINSICS_
|
#ifndef _EULE_NO_INTRINSICS_
|
||||||
#include <immintrin.h>
|
#include <immintrin.h>
|
||||||
#endif
|
#endif
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#include "Math.h"
|
#include "Math.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
//#define _EULE_NO_INTRINSICS_
|
#define _EULE_NO_INTRINSICS_
|
||||||
#ifndef _EULE_NO_INTRINSICS_
|
#ifndef _EULE_NO_INTRINSICS_
|
||||||
#include <immintrin.h>
|
#include <immintrin.h>
|
||||||
#endif
|
#endif
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#include "Math.h"
|
#include "Math.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
//#define _EULE_NO_INTRINSICS_
|
#define _EULE_NO_INTRINSICS_
|
||||||
#ifndef _EULE_NO_INTRINSICS_
|
#ifndef _EULE_NO_INTRINSICS_
|
||||||
#include <immintrin.h>
|
#include <immintrin.h>
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user