diff options
Diffstat (limited to 'indra/llmath')
-rw-r--r-- | indra/llmath/llvector4a.h | 13 | ||||
-rw-r--r-- | indra/llmath/v3math.h | 51 | ||||
-rw-r--r-- | indra/llmath/v4math.h | 51 |
3 files changed, 115 insertions, 0 deletions
diff --git a/indra/llmath/llvector4a.h b/indra/llmath/llvector4a.h index 8ef560dadf..4004852e06 100644 --- a/indra/llmath/llvector4a.h +++ b/indra/llmath/llvector4a.h @@ -33,6 +33,9 @@ class LLRotation; #include <assert.h> #include "llpreprocessor.h" #include "llmemory.h" +#include "glm/vec3.hpp" +#include "glm/vec4.hpp" +#include "glm/gtc/type_ptr.hpp" /////////////////////////////////// // FIRST TIME USERS PLEASE READ @@ -364,6 +367,16 @@ public: inline operator LLQuad() const; + explicit inline operator glm::vec3() const + { + return glm::make_vec3(getF32ptr()); + }; + + explicit inline operator glm::vec4() const + { + return glm::make_vec4(getF32ptr()); + }; + private: LLQuad mQ{}; }; diff --git a/indra/llmath/v3math.h b/indra/llmath/v3math.h index d063b15c74..a3bfa68060 100644 --- a/indra/llmath/v3math.h +++ b/indra/llmath/v3math.h @@ -31,6 +31,11 @@ #include "llmath.h" #include "llsd.h" + +#include "glm/vec3.hpp" +#include "glm/vec4.hpp" +#include "glm/gtc/type_ptr.hpp" + class LLVector2; class LLVector4; class LLVector4a; @@ -66,6 +71,11 @@ class LLVector3 explicit LLVector3(const LLVector4a& vec); // Initializes LLVector4 to (vec[0]. vec[1], vec[2]) explicit LLVector3(const LLSD& sd); + // GLM interop + explicit LLVector3(const glm::vec3& vec); // Initializes LLVector3 to (vec[0]. vec[1], vec[2]) + explicit LLVector3(const glm::vec4& vec); // Initializes LLVector3 to (vec[0]. vec[1], vec[2]) + explicit inline operator glm::vec3() const; // Initializes glm::vec3 to (vec[0]. vec[1], vec[2]) + explicit inline operator glm::vec4() const; // Initializes glm::vec4 to (vec[0]. vec[1], vec[2], 1) LLSD getValue() const; @@ -92,6 +102,8 @@ class LLVector3 inline void set(const F32 *vec); // Sets LLVector3 to vec const LLVector3& set(const LLVector4 &vec); const LLVector3& set(const LLVector3d &vec);// Sets LLVector3 to vec + inline void set(const glm::vec4& vec); // Sets LLVector3 to vec + inline void set(const glm::vec3& vec); // Sets LLVector3 to vec inline void setVec(F32 x, F32 y, F32 z); // deprecated inline void setVec(const LLVector3 &vec); // deprecated @@ -190,6 +202,20 @@ inline LLVector3::LLVector3(const F32 *vec) mV[VZ] = vec[VZ]; } +inline LLVector3::LLVector3(const glm::vec3& vec) +{ + mV[VX] = vec.x; + mV[VY] = vec.y; + mV[VZ] = vec.z; +} + +inline LLVector3::LLVector3(const glm::vec4& vec) +{ + mV[VX] = vec.x; + mV[VY] = vec.y; + mV[VZ] = vec.z; +} + /* inline LLVector3::LLVector3(const LLVector3 ©) { @@ -259,6 +285,20 @@ inline void LLVector3::set(const F32 *vec) mV[2] = vec[2]; } +inline void LLVector3::set(const glm::vec4& vec) +{ + mV[VX] = vec.x; + mV[VY] = vec.y; + mV[VZ] = vec.z; +} + +inline void LLVector3::set(const glm::vec3& vec) +{ + mV[VX] = vec.x; + mV[VY] = vec.y; + mV[VZ] = vec.z; +} + // deprecated inline void LLVector3::setVec(F32 x, F32 y, F32 z) { @@ -471,6 +511,17 @@ inline LLVector3 operator-(const LLVector3 &a) return LLVector3( -a.mV[0], -a.mV[1], -a.mV[2] ); } +inline LLVector3::operator glm::vec3() const +{ + // Do not use glm::make_vec3 it can result in a buffer overrun on some platforms due to glm::vec3 being a simd vector internally + return glm::vec3(mV[VX], mV[VY], mV[VZ]); +} + +inline LLVector3::operator glm::vec4() const +{ + return glm::vec4(mV[VX], mV[VY], mV[VZ], 1.f); +} + inline F32 dist_vec(const LLVector3 &a, const LLVector3 &b) { F32 x = a.mV[0] - b.mV[0]; diff --git a/indra/llmath/v4math.h b/indra/llmath/v4math.h index a5b6f506d7..a4c9668fdd 100644 --- a/indra/llmath/v4math.h +++ b/indra/llmath/v4math.h @@ -32,6 +32,10 @@ #include "v3math.h" #include "v2math.h" +#include "glm/vec3.hpp" +#include "glm/vec4.hpp" +#include "glm/gtc/type_ptr.hpp" + class LLMatrix3; class LLMatrix4; class LLQuaternion; @@ -73,6 +77,11 @@ class LLVector4 mV[3] = (F32)sd[3].asReal(); } + // GLM interop + explicit LLVector4(const glm::vec3& vec); // Initializes LLVector4 to (vec, 1) + explicit LLVector4(const glm::vec4& vec); // Initializes LLVector4 to vec + explicit operator glm::vec3() const; // Initializes glm::vec3 to (vec[0]. vec[1], vec[2]) + explicit operator glm::vec4() const; // Initializes glm::vec4 to (vec[0]. vec[1], vec[2], vec[3]) inline bool isFinite() const; // checks to see if all values of LLVector3 are finite @@ -85,6 +94,8 @@ class LLVector4 inline void set(const LLVector4 &vec); // Sets LLVector4 to vec inline void set(const LLVector3 &vec, F32 w = 1.f); // Sets LLVector4 to LLVector3 vec inline void set(const F32 *vec); // Sets LLVector4 to vec + inline void set(const glm::vec4& vec); // Sets LLVector4 to vec + inline void set(const glm::vec3& vec, F32 w = 1.f); // Sets LLVector4 to LLVector3 vec with w defaulted to 1 inline void setVec(F32 x, F32 y, F32 z); // deprecated inline void setVec(F32 x, F32 y, F32 z, F32 w); // deprecated @@ -223,6 +234,21 @@ inline LLVector4::LLVector4(const LLSD &sd) setValue(sd); } +inline LLVector4::LLVector4(const glm::vec3& vec) +{ + mV[VX] = vec.x; + mV[VY] = vec.y; + mV[VZ] = vec.z; + mV[VW] = 1.f; +} + +inline LLVector4::LLVector4(const glm::vec4& vec) +{ + mV[VX] = vec.x; + mV[VY] = vec.y; + mV[VZ] = vec.z; + mV[VW] = vec.w; +} inline bool LLVector4::isFinite() const { @@ -297,6 +323,21 @@ inline void LLVector4::set(const F32 *vec) mV[VW] = vec[VW]; } +inline void LLVector4::set(const glm::vec4& vec) +{ + mV[VX] = vec.x; + mV[VY] = vec.y; + mV[VZ] = vec.z; + mV[VW] = vec.w; +} + +inline void LLVector4::set(const glm::vec3& vec, F32 w) +{ + mV[VX] = vec.x; + mV[VY] = vec.y; + mV[VZ] = vec.z; + mV[VW] = w; +} // deprecated inline void LLVector4::setVec(F32 x, F32 y, F32 z) @@ -466,6 +507,16 @@ inline LLVector4 operator-(const LLVector4 &a) return LLVector4( -a.mV[VX], -a.mV[VY], -a.mV[VZ] ); } +inline LLVector4::operator glm::vec3() const +{ + return glm::vec3(mV[VX], mV[VY], mV[VZ]); +} + +inline LLVector4::operator glm::vec4() const +{ + return glm::make_vec4(mV); +} + inline F32 dist_vec(const LLVector4 &a, const LLVector4 &b) { LLVector4 vec = a - b; |