I have implemented an Objectrotation with QQuaternion and QPushButton. As long as the plus_x_button is pushed the slot rotate_plus_x() is activated. Respectively for minus_x.
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(){...}
Now I would like to realize the functionality with a Qslider instead of the QPushButton. With a range between -180° and 180° But then I have the problem that I get weird outcomes because the value of the Qslider is changed and the QQuaternion expexts a nonchangeble angle. Have you an idea how to achieve that? I have tried it with if-statements. Something like:
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);}
Unfortunately its not working. Do you have an idea, how to achieve that?
Thank you
I think that to get what you're looking for, you should assign rather than multiply.
That is, if you slider is set to have values from -179 to +180 degrees, then you can just say:
Note that I'm using = instead of
*=
. That makes that the slider behave intuitively.