Okay,
I put that code because I thought that the rest of it isn't necessary to show .
Here is my paintGL() method in the class MainWidget:
void MainWidget::paintGL()
{
//qDebug()<<__func__;
// Clear color and depth buffer
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//================Orbital Frame ==========================================//
QMatrix4x4 localMatrix;
glMatrixMode(GL_PROJECTION);
glLoadMatrixf(projection.constData());
glMatrixMode(GL_MODELVIEW);
glLoadMatrixf(localMatrix.constData());
gluLookAt(2.0,2.0,0.0,0.0,0.0,-5.0,0.0,1.0,0.0);
glTranslatef(0.0,0.0,-5.0);
glRotatef(180.0,0.0,1.0,0.0);
glRotatef(-90.0,1.0,0.0,0.0);
glScalef(0.4,0.4,0.4);
//glMatrixMode(GL_PROJECTION);
DrawOrbitalFrame();
program.bind();
texture->bind();
// Calculate model view transformation
//qDebug()<<"modelview before transformation"<<matrix;
//qDebug()<<"modelview matrix"<<localMatrix;
localMatrix.setToIdentity();
localMatrix.lookAt(QVector3D(2.0, 2.0, 0.0), QVector3D(0.0,0.0,-5.0),QVector3D(0.0,1.0,0.0));
localMatrix.translate(0.0, 0.0, -5.0);
localMatrix.scale(0.4,0.4,0.4);
quaternion = QQuaternion(quat_w, quat_x, quat_y, quat_z);
quaternion.normalize(); // Normalizing my quaternion
if(ApplyRotation == true)
{
EulerAngles.append(quaternion.toEulerAngles()); //rotation order is 213.
localMatrix.rotate(quaternion);
}
program.setUniformValue("mvp_matrix", projection * localMatrix);
update();
//! [6]
//!
// Use texture unit 0 which contains cube.png
program.setUniformValue("texture", 0);
// Draw cube geometry
geometries->drawCubeGeometry(&program);
texture->release();
program.release();
}
And in my MainWindow class where I programmed the push button:
void MainWindow::on_pushButton_3_clicked()
{
this->ui->mainwidget->ApplyRotation = true;
}
That's what I actually did, I called the variable applyRotation in my my piantGL() method to rotate the object once the user inserts the quaternion value and click on the push button.