二、欧拉角
欧拉角指的是:以世界坐标系为参考坐标系(一定记住是世界坐标系),使用x,y,z三个值来分别表示绕(世界的)x轴、y轴、z轴
旋转的角度量值。其取值是在[0, 360]间。一般用roll, pitch,
yaw来表示这些分量的旋转值。因为是以世界坐标系为参考坐标系,因此每一次的旋转都不会影响到后续的旋转转轴。即:它无法表示任意轴的旋转。
一直以为 x轴是pitch y是yaw ,z 是roll的,今天受到教训了,搞了很久
原来,x轴对应的roll,y轴对应的是pitch ,z是yaw
如此 欧拉角转四元数就解决了
void FromEuler(float roll, float pitch, float yaw)
{
// Basically we create 3 Quaternions, one for pitch, one for yaw, one for roll
// and multiply those together.
// the calculation below does the same, just shorter
float p = pitch * DEG2RAD / 2.0;
float y = yaw * DEG2RAD / 2.0;
float r = roll * DEG2RAD / 2.0;
float sinp = sin(p);
float siny = sin(y);
float sinr = sin(r);
float cosp = cos(p);
float cosy = cos(y);
float cosr = cos(r);
this->x = sinr * cosp * cosy - cosr * sinp * siny;
this->y = cosr * sinp * cosy + sinr * cosp * siny;
this->z = cosr * cosp * siny - sinr * sinp * cosy;
this->w = cosr * cosp * cosy + sinr * sinp * siny;
Normalize();
}
原文:http://www.cnblogs.com/dragon2012/p/3925227.html