Hello Guys,
I hope you're doing well.
I'm a newbie here.
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:
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:
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.
Please if anyone can help me, I would really appreciate it.
ps: I'm using Qt and OpenGL
Thank you all.
I hope you're doing well.
I'm a newbie here.
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:
C++:
void MainWindow::on_pushButton_3_clicked()
{
this->ui->mainwidget->ApplyRotation = true;
}
C++:
if(ApplyRotation == true)
{
EulerAngles.append(quaternion.toEulerAngles()); //rotation order is 213.
localMatrix.rotate(quaternion);
}
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:
C++:
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.
Please if anyone can help me, I would really appreciate it.
ps: I'm using Qt and OpenGL
Thank you all.