From 527b503bd78b3ac996e68f68d5e35a55bf43dbc3 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Fri, 23 Feb 2018 20:16:08 -1000 Subject: [PATCH] Make vectors and quaternions implicitly convertible to athena vectors --- include/zeus/CQuaternion.hpp | 27 +++++---------------------- include/zeus/CVector2f.hpp | 20 ++++---------------- include/zeus/CVector3f.hpp | 20 ++++---------------- include/zeus/CVector4f.hpp | 20 ++++---------------- 4 files changed, 17 insertions(+), 70 deletions(-) diff --git a/include/zeus/CQuaternion.hpp b/include/zeus/CQuaternion.hpp index 24b29cd..4817827 100644 --- a/include/zeus/CQuaternion.hpp +++ b/include/zeus/CQuaternion.hpp @@ -61,31 +61,13 @@ public: #endif } - operator atVec4f() + operator atVec4f&() { - atVec4f ret; -#if __SSE__ - ret.mVec128 = mVec128; -#else - ret.vec[0] = w; - ret.vec[1] = x; - ret.vec[2] = y; - ret.vec[3] = z; -#endif - return ret; + return *reinterpret_cast(v); } - operator atVec4f() const + operator const atVec4f&() const { - atVec4f ret; -#if __SSE__ - ret.mVec128 = mVec128; -#else - ret.vec[0] = w; - ret.vec[1] = x; - ret.vec[2] = y; - ret.vec[3] = z; -#endif - return ret; + return *reinterpret_cast(v); } #endif @@ -218,6 +200,7 @@ public: { float w, x, y, z; }; + float v[4]; }; static const CQuaternion skNoRotation; diff --git a/include/zeus/CVector2f.hpp b/include/zeus/CVector2f.hpp index 7ec8ab3..55136c6 100644 --- a/include/zeus/CVector2f.hpp +++ b/include/zeus/CVector2f.hpp @@ -52,25 +52,13 @@ public: } #endif - operator atVec2f() + operator atVec2f&() { - atVec2f ret; -#if __SSE__ - ret.mVec128 = mVec128; -#else - ret.vec = v; -#endif - return ret; + return *reinterpret_cast(v); } - operator atVec2f() const + operator const atVec2f&() const { - atVec2f ret; -#if __SSE__ - ret.mVec128 = mVec128; -#else - ret.vec = v; -#endif - return ret; + return *reinterpret_cast(v); } void readBig(athena::io::IStreamReader& input) diff --git a/include/zeus/CVector3f.hpp b/include/zeus/CVector3f.hpp index a63f35f..469cd0d 100644 --- a/include/zeus/CVector3f.hpp +++ b/include/zeus/CVector3f.hpp @@ -50,25 +50,13 @@ public: } #endif - operator atVec3f() + operator atVec3f&() { - atVec3f ret; -#if __SSE__ - ret.mVec128 = mVec128; -#else - ret.vec = v; -#endif - return ret; + return *reinterpret_cast(v); } - operator atVec3f() const + operator const atVec3f&() const { - atVec3f ret; -#if __SSE__ - ret.mVec128 = mVec128; -#else - ret.vec = v; -#endif - return ret; + return *reinterpret_cast(v); } void readBig(athena::io::IStreamReader& input) diff --git a/include/zeus/CVector4f.hpp b/include/zeus/CVector4f.hpp index 6f8acf7..ff9a957 100644 --- a/include/zeus/CVector4f.hpp +++ b/include/zeus/CVector4f.hpp @@ -48,25 +48,13 @@ public: } #endif - operator atVec4f() + operator atVec4f&() { - atVec4f ret; -#if __SSE__ - ret.mVec128 = mVec128; -#else - ret.vec = v; -#endif - return ret; + return *reinterpret_cast(v); } - operator atVec4f() const + operator const atVec4f&() const { - atVec4f ret; -#if __SSE__ - ret.mVec128 = mVec128; -#else - ret.vec = v; -#endif - return ret; + return *reinterpret_cast(v); } void readBig(athena::io::IStreamReader& input)