[Rotating a cube using quaternion with respect to a fixed frame] – For beginners

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:


//================Orbital Frame ==========================================//



gluLookAt(2.0,2.0,0.0, 0.0,0.0,-5.0,0.0,1.0,0.0);







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

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);


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

program.setUniformValue("texture", 0);

// 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.

About Debra D. Johnson

Check Also

What is a full frame camera? What you need now

Photographers hear about sensor size all the time, especially when looking to buy a new …