Hello, I hope you're all doing well.
So I developed an application that rotates a cube using quaternions.
In my mainwindow.ui, I have 4 spin boxes, each one of them corresponds to the quaternion components ( w, x, y and z).
After inserting the components' values manually, the cube changes its orientation.
Now I want to add a push button "Apply rotation". So when I insert the quaternion components in the spin boxes, I should first click on the push button to apply the rotation and then see the cube changing its orientation.
In my code I have two classes:
MainWindow
Mainwidget
In my mainwidget.cpp, I have a method which is paintGL() and in which I render the whole scene and apply transformations on the cube.
To make the rotation possible using the push button I did this:
In mainwidow.cpp:
void MainWindow::on_pushButton_3_clicked()
{
this->ui->mainwidget->ApplyRotation = true;
}
In paintGL() in my mainwidget.cpp:
if(ApplyRotation == true)
{
EulerAngles.append(quaternion.toEulerAngles()); //rotation order is 213.
localMatrix.rotate(quaternion); // rotates the cube whenever I insert a quaternion and click on apply button
}
When I insert the quaternion components in the spin boxes, then click on the push button, the object changes its orientation.
However when I keep changing the quaternion components after the first attempt, the cube keeps rotating. I mean I no longer need to click on the push button again to apply the rotation after the first click on the push button.
So I did this:
if(ApplyRotation == true)
{
ApplyRotation=false;
EulerAngles.append(quaternion.toEulerAngles()); //rotation order is 213.
localMatrix.rotate(quaternion);
}
Now after inserting the quaternions components in the spin boxes, I click on the push button, the object changes its orientation immediately but goes back quickly to its initial orientation. I want it to stay at the new orientation.
I don't know what I'm doing wrong because the code seems logical.
My goal is to make the object rotate only if the push button is clicked.
Please if anyone can help me, I would really appreciate it.
ps: I'm using Qt and OpenGL
Thank you all.