So, I've noticed that when you rotate a cube in local coordinates you somehow rotate the axis as well. If you try to rotate a cube 90 degrees on the x axis and then try constantly rotating it on the y axis, you will see the cube rotating on the z axis instead of y. In order to give you a better understanding for my problem, check the following:
Rotating the cube on the Y axis with initial rotation (0,0,0)
Rotating the cube on the y Axis with initial rotation (90,0,0)
In the second video, I was expecting to see the cube rotating around the Y axis, not the Z. This is exactly the effect that you get if with the initial rotation (90,0,0) the Y axis rotates as well (and now lying on the floor ) becoming the Z axis. Is this what is actually happening? So how can I rotate the cube without rotating the actual local Axis (Just rotating the cube around the Axis in local space)?
This is how I rotate the cube before I draw:
//Initialize the mvp transformations.
glm::mat4 model = glm::mat4(1.0f);
glm::mat4 view = glm::mat4(1.0f);
glm::mat4 proj = glm::mat4(1.0f);
//Translate.
model = glm::translate(model, m_pos);
//Rotate the model.
model = glm::rotate(model, glm::radians(m_rotation.x), glm::vec3(1.0f, 0.0f, 0.0f));
model = glm::rotate(model, glm::radians(m_rotation.y), glm::vec3(0.0f, 1.0f, 0.0f));
model = glm::rotate(model, glm::radians(m_rotation.z), glm::vec3(0.0f, 0.0f, 1.0f));
//Scale.
model = glm::scale(model, m_scale);
//View.
view = m_core->m_cam->GetView();
//Projection.
proj = glm::perspective(glm::radians(m_core->m_cam->m_fov), (float)m_core->m_width / m_core->m_height, 0.1f, 100.0f);
//Set the tranformation matrices on the shader.
m_program->SetUniformMat4f("model", model);
m_program->SetUniformMat4f("view", view);
m_program->SetUniformMat4f("proj", proj);
//Draw Call.
glDrawArrays(GL_TRIANGLES, 0, 36);
And inside the vertex shader you can guess what I'm doing:
gl_Position = proj * view * model * vec4(aPos, 1.0f);
My mind goes to the same technique I learned about the camera system. There, I learned that I had to create 3 vectors (up, left and front) which actually are going to define a new coordinate system with origin the center of the camera. Do I have to do the same thing here? Each cube will have 3 vectors which they define a new coordinate system with origin the center of the cube (this will be the local coordinate system of the cube) and then use somehow these vectors to rotate the cube accordingly.
Can you give me some examples?
Thank you!