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