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 ==========================================//
Then in my program I have shader programs (Vertex and Fragment shader programs) which I used to draw a textured cube:
// Calculate model view transformation
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);
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
localMatrix.rotate(quaternion); // the quaternion in here correponds to the one extracted from a QList
program.setUniformValue("mvp_matrix", projection * localMatrix);
// Use texture unit 0 which contains cube.png
// Draw cube geometry
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.