|
|
by Akatsuki
- // 欧拉角转矩阵[] EulerAngles To Matrix
- void AngleMatrix(const float in[3], float out[4][4])
- {
- float cx, sx, cy, sy, cz, sz;
- float yx, yy;
- cx = cos(in[0]);
- sx = sin(in[0]);
- cy = cos(in[1]);
- sy = sin(in[1]);
- cz = cos(in[2]);
- sz = sin(in[2]);
-
- yx = sy*cx;
- yy = sy*sx;
- out[0][0] = cy*cz;
- out[0][1] = -cy*sz;
- out[0][2] = sy;
- out[0][3] = 0;
- out[1][0] = yy*cz+cx*sz;
- out[1][1] = -yy*sz+cx*cz;
- out[1][2] = -sx;
- out[1][3] = 0;
- out[2][0] = -yx*cz+sx*sz;
- out[2][1] = yx*sz+sx*cz;
- out[2][2] = cx*cy;
- out[2][3] = 0;
- out[3][0] = 0;
- out[3][1] = 0;
- out[3][2] = 0;
- out[3][3] = 1;
- }
- // 矩阵转欧拉角[] Matrix To EulerAngles
- void MatrixAngle(const float in[4][4], float out[3])
- {
- float c;
- float tx, ty;
- out[1] = asin(in[0][2]);
- c = cos(out[1]);
- if (fabs(c)>0.005)
- {
- tx = in[2][2]/c;
- ty = -in[1][2]/c;
- out[0] = atan2(ty, tx);
- tx = in[0][0]/c;
- ty = -in[0][1]/c;
- out[2] = atan2(ty, tx);
- }
- else
- {
- out[0] = 0;
- tx = in[1][1];
- ty = in[1][0];
- out[2] = atan2(ty, tx);
- }
- }
复制代码 |
|