標籤:使用 os io for ad on sp c
二、歐拉角
歐拉角指的是:以全局座標係為參考座標系(一定記住是全局座標系),使用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();
}