Add matrix to quaternion constructor

This commit is contained in:
Jack Andersen 2016-04-07 17:35:16 -10:00
parent baaca3136b
commit c16f25db09
1 changed files with 12 additions and 2 deletions

View File

@ -5,6 +5,7 @@
#include "CAxisAngle.hpp" #include "CAxisAngle.hpp"
#include "zeus/CVector3f.hpp" #include "zeus/CVector3f.hpp"
#include "zeus/CVector4f.hpp" #include "zeus/CVector4f.hpp"
#include "zeus/CMatrix3f.hpp"
#include "zeus/Math.hpp" #include "zeus/Math.hpp"
#if ZE_ATHENA_TYPES #if ZE_ATHENA_TYPES
#include <athena/IStreamReader.hpp> #include <athena/IStreamReader.hpp>
@ -41,6 +42,15 @@ public:
#endif #endif
} }
CQuaternion(const CMatrix3f& mat)
{
w = std::sqrt(1.0f + mat[0][0] + mat[1][1] + mat[2][2]) / 2.0f;
double w4 = 4.0f * w;
x = (mat[1][2] - mat[2][1]) / w4;
y = (mat[2][0] - mat[0][2]) / w4;
z = (mat[0][1] - mat[1][0]) / w4;
}
operator atVec4f() operator atVec4f()
{ {
atVec4f ret; atVec4f ret;
@ -160,8 +170,8 @@ public:
return std::asin(-2.f * (x * z - w * y)); return std::asin(-2.f * (x * z - w * y));
} }
inline float& operator[](size_t idx) {return (&x)[idx];} inline float& operator[](size_t idx) {return (&w)[idx];}
inline const float& operator[](size_t idx) const {return (&x)[idx];} inline const float& operator[](size_t idx) const {return (&w)[idx];}
union union
{ {