Hello guys,
I hope that you all are ok.
So I created an application on Qt6 that rotates a cube using quaternions. The rotation is performed relative to the standard OpenGL coordinate system.
As I know, the standard OpenGL coordinate system is shown in the image below:
I added a fixed coordinate system to my scene (like the one shown in the image above). So when I insert the quaternion values as follows: w=0.7, x=0.7, y=0.0, z=0.0, the cube rotates around the x axis of the coordinate system standard.
Then I had to change the orientation of the axes of this coordinate system as shown in the image below where:
x is the magenta axis
y is White’s axis
z is the yellow axis
and my goal is to rotate the cube using a quaternion but this time the new fixed coordinate systemI didn’t know how to do it but that’s what I’ve done so far.
In my paintGL() function, I started by drawing the fixed coordinate system and changing the orientation of its axes using rotate:
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//================Orbital Frame ==========================================//
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
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();
Then in my program I have shader programs (Vertex and Fragment shader programs) which I used to draw a textured cube:
program.bind();
texture->bind();
// Calculate model view transformation
QMatrix4x4 localMatrix;
//QMatrix4x4 identity;
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
localMatrix.rotate(quaternion); // the quaternion in here corresponds to the one that can be manually inserted in the spin boxes in the ui
quaternion=csvquaternion;
localMatrix.rotate(quaternion); // the quaternion in here correponds to the one extracted from a QList
program.setUniformValue("mvp_matrix", projection * localMatrix);
update();
// Use texture unit 0 which contains cube.png
program.setUniformValue("texture", 0);
// Draw cube geometry
geometries->drawCubeGeometry(&program);
texture->release();
program.release();
The rotation is achieved using the rotate function but the object rotates around the axes of the standard coordinate system and not the new one.
Can anyone tell me what I can do to make it rotate around the new fixed coordinate system or give me a little advice on how to achieve this?
Thank you all.