2
我已经使用QQuaternion和QPushButton实现了Objectrotation。 只要push_x_button被按下,rotate_plus_x()被激活。 分别为minus_x。使用QQuaternion和QSlider旋转
void OpenGLScene::rotate_plus_x()
{
OpenGLScene::anglex = 2;
test->rotation *= QQuaternion::fromAxisAndAngle(QVector3D(1,0,0),OpenGLScene::anglex);
update();
}
void OpenGLScene::rotate_minus_x()
{
OpenGLScene::anglex = -2;
test->rotation *= QQuaternion::fromAxisAndAngle(QVector3D(1,0,0),OpenGLScene::anglex);
update();
}
void OpenGLScene::rotate_plus_y(){...}
void OpenGLScene::rotate_minus_y(){...}
void OpenGLScene::rotate_plus_z(){...}
void OpenGLScene::rotate_minus_z(){...}
现在我想用Qslider而不是QPushButton实现功能。 范围在-180°到180°之间 但是后来我遇到了一个问题,我得到了奇怪的结果,因为Qslider的价值发生了变化,并且QQuaternion预示着一个不可更改的角度。 你有想法如何实现吗?我已经用if语句尝试过了。 类似于:
if(slidervalue<0){
OpenGLScene::anglex = -2;
test->rotation *= QQuaternion::fromAxisAndAngle(QVector3D(1,0,0),OpenGLScene::anglex);}
else{
OpenGLScene::anglex = 2;
test->rotation *= QQuaternion::fromAxisAndAngle(QVector3D(1,0,0),OpenGLScene::anglex);}
不幸的是,它不工作。你有一个想法,如何实现这一点?
谢谢
谢谢。这正是问题所在 – buddy 2012-01-13 23:24:34