|
想实现的效果:坦克绕物体坐标系PITCH,YAW,ROLL正常旋转
但现实的效果:坦克绕物体坐标系PITCH,YAW正常,ROLL总是以世界坐标系来旋转
使用的是MatrixTransform,
也用PositionAttitudeTransform试过,也是一样的效果,后来我用一个MatrixTransform表示位移,另一个表示旋转,还是无法解决问题
节点结构
MatrixTransform *tankLocalMT
----Node *tank
变量
double pitch,yaw,roll;
Quat _rotate;
Vec3d _translate;
Vec3d _scale;
烦请大神看一下,困扰很久了
代码:
- Matrix tankData::setState()
- {
- _rotate.makeRotate(
- osg::DegreesToRadians(pitch), Vec3d(1, 0, 0),
- osg::DegreesToRadians(yaw), Vec3d(0, 1, 0),
- osg::DegreesToRadians(roll), Vec3d(0, 0, 1)
- );
- return Matrix(
- Matrix::scale(_scale)*
- Matrix::rotate(_rotate)*
- Matrix::translate(_translate)
- );
- }
复制代码
- //向前移动
- void tankData::moveForward()
- {
- _translate=_translate+(distance*flySpeed);
- tankLocalMT->setMatrix(setState());
- }
- //朝正后方移动
- void tankData::moveBack()
- {
- _translate=_translate-(distance*flySpeed);
- tankLocalMT->setMatrix(setState());
- }
- //Roll旋转
- void tankData::turnRoll()
- {
- roll++;
- if (roll == 180) roll = -180;
- tankLocalMT->setMatrix(setState());
-
- }
- void tankData::turnRoll_()
- {
- roll--;
- if (roll == 180) roll = -180;
- tankLocalMT->setMatrix(setState());
- }
- //Pitch旋转
- void tankData::turnPitch()
- {
- if (pitch < 90)
- {
- pitch++;
- tankLocalMT->setMatrix(setState());
- }
- }
- void tankData::turnPitch_()
- {
- if (pitch >- 90)
- {
- pitch--;
- tankLocalMT->setMatrix(setState());
- }
-
- }
- //Yaw旋转
- void tankData::turnYaw()
- {
- yaw++;
- if (yaw == 180) yaw = -180;
- tankLocalMT->setMatrix(setState());
- }
- void tankData::turnYaw_()
- {
- yaw--;
- if (yaw == 180) yaw = -180;
- tankLocalMT->setMatrix(setState());
- }
复制代码 |
|