[DEV] add basic euler convertion from quaternion
This commit is contained in:
parent
c79652bba2
commit
28ffa0fb75
@ -56,3 +56,20 @@ etk::CCout& etk::operator <<(etk::CCout &os, const etk::Vector3D<bool> obj)
|
||||
return os;
|
||||
}
|
||||
|
||||
|
||||
vec3 quaternionToEulerXYZ(const btQuaternion& quat)
|
||||
{
|
||||
// back to the euler angle :
|
||||
float xxx = quat.x();
|
||||
float yyy = quat.y();
|
||||
float zzz = quat.z();
|
||||
float www = quat.w();
|
||||
double xxx2 = xxx*xxx;
|
||||
double yyy2 = yyy*yyy;
|
||||
double zzz2 = zzz*zzz;
|
||||
double www2 = www*www;
|
||||
// http://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles
|
||||
return vec3( atan2(2.0*(yyy*zzz + xxx*www) , (-xxx2-yyy2+zzz2+www2) ),
|
||||
asin(2.0*(xxx*zzz-yyy*www)),
|
||||
atan2(2.0*(xxx*yyy + zzz*www), (xxx2-yyy2-zzz2+www2) ) );
|
||||
}
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include <LinearMath/btScalar.h>
|
||||
#include <LinearMath/btMinMax.h>
|
||||
#include <LinearMath/btVector3.h>
|
||||
#include <LinearMath/btQuaternion.h>
|
||||
|
||||
namespace etk
|
||||
{
|
||||
@ -451,6 +452,8 @@ typedef etk::Vector3D<uint32_t> uivec3;
|
||||
typedef etk::Vector3D<bool> bvec3;
|
||||
|
||||
|
||||
vec3 quaternionToEulerXYZ(const btQuaternion& quat);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user