将本地(=旋转后的)坐标转换为全局坐标
问题描述:
我有一个QVector3D,它定义了局部坐标系中的物体速度(=正Z表示向前移动,...),QVector3D在10度(0 .3600)步骤定义对象在全局坐标系中的旋转。将本地(=旋转后的)坐标转换为全局坐标
现在模拟我的场景,我需要在全局坐标系中的对象速度QVector3D。
我找到什么了到目前为止是旋转矩阵(从http://en.wikipedia.org/wiki/Rotation_matrix#Rotations_in_three_dimensions):
qreal angle(qreal in){ //helper function
return in/1800.0f*M_PI;
}
qreal xptr[9]={
1,0,0,
0,cos(angle(rotation.x())),-sin(angle(rotation.x())),
0,sin(angle(rotation.x())),cos(angle(rotation.x()))
};
qreal yptr[9]={
cos(angle(rotation.y())),0,sin(angle(rotation.y())),
0,1,0,
-sin(angle(rotation.y())),0,cos(angle(rotation.y()))
};
qreal zptr[9]={
cos(angle(rotation.z())),-sin(angle(rotation.z())),0,
sin(angle(rotation.z())),cos(angle(rotation.z())),0,
0,0,1
};
,但我不知道如何正确地使用它们。
编辑:如果其相关:单位,旋转方向......遵循OpenGL标准。
答
使用矩阵产品:transfomration_matrix X original_vector = transformed_vector
使用四元现在,不需要这些矩阵更多... – nonchip 2011-04-23 13:11:01