Add Matrix3x3 to euler anges constructor

This commit is contained in:
Jack Andersen 2017-04-18 13:40:12 -10:00
parent c3a6827e83
commit 85e340855a
2 changed files with 35 additions and 0 deletions

View File

@ -12,6 +12,7 @@ class CEulerAngles : public CVector3f
public:
CEulerAngles(float x, float y, float z) { assign(x, y, z); }
CEulerAngles(const CQuaternion& quat);
CEulerAngles(const CTransform& xf);
};
}

View File

@ -40,4 +40,38 @@ CEulerAngles::CEulerAngles(const CQuaternion& quat)
}
}
CEulerAngles::CEulerAngles(const CTransform& xf)
{
float xyMagSq = xf.basis[1][1] * xf.basis[1][1] + xf.basis[1][0] * xf.basis[1][0];
float f1 = 0.f;
if (xyMagSq > 0.f)
{
f1 = 1.f / std::sqrt(xyMagSq);
float f0;
for (int i=0 ; i<4 ; ++i)
{
f0 = f1 * f1;
f1 *= 0.5f;
f0 = 3.f - xyMagSq * f0;
f1 *= f0;
}
f1 = xyMagSq * f0;
}
if (std::fabs(f1) >= 0.00001)
{
x = -std::atan2(-xf.basis[1][2], f1);
y = -std::atan2(xf.basis[0][2], xf.basis[2][2]);
z = -std::atan2(xf.basis[1][0], xf.basis[1][1]);
}
else
{
x = -std::atan2(-xf.basis[1][2], f1);
y = -std::atan2(-xf.basis[2][0], xf.basis[0][0]);
z = 0.f;
}
}
}