Use a union and move real component in CQuaternion

This commit is contained in:
Phillip Stephens 2016-01-16 21:45:47 -08:00
parent 0594099ccd
commit 3113307e6c
1 changed files with 7 additions and 5 deletions

View File

@ -26,12 +26,11 @@ public:
#endif #endif
CQuaternion(const CVector3f& vec) { fromVector3f(vec); } CQuaternion(const CVector3f& vec) { fromVector3f(vec); }
CQuaternion(const CVector4f& vec) CQuaternion(const CVector4f& vec)
: r(vec.w)
{ {
#if __SSE__ #if __SSE__
v.mVec128 = vec.mVec128; v.v[3] = 0; v.mVec128 = vec.mVec128;
#else #else
v.x = vec.x; v.y = vec.y; v.z = vec.z; v.x = vec.x; v.y = vec.y; v.z = vec.z; r = vec.w;
#endif #endif
} }
@ -105,8 +104,11 @@ public:
return asinf(-2.0 * (v.x * v.z - r * v.y)); return asinf(-2.0 * (v.x * v.z - r * v.y));
} }
float r; union
CVector3f v; {
struct { float x, y, z, r; };
CVector3f v;
};
}; };
CQuaternion operator+(float lhs, const CQuaternion& rhs); CQuaternion operator+(float lhs, const CQuaternion& rhs);