[Programming a push button to do a certain task]

Joined
Jul 14, 2022
Messages
1
Reaction score
0
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:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top