Rotations with QQuaternion and QSlider
-
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 have now the answer:
Instead of this:
@
test->rotation *= QQuaternion::fromAxisAndAngle(QVector3D(1,0,0),OpenGLScene::anglex);
@
I have to write this
@
test->rotation = QQuaternion::fromAxisAndAngle(QVector3D(1,0,0),OpenGLScene::anglex);
@