0
votes

I try to translate objects after a rotation. I rotate objects with inputs events, stock the value of the rotation and use it for the translation. However, the objects translates with a wrong rotation. I don't understand why. here is pseudo code of my program :

translate :

for(int i = 0; i < numberObjects; i++)
objects.at(i) = glm::translate(glm::mat4(1.0f), newPosition.at(i)) * glm::rotate(glm::mat4(1.0f), valueOfRotation, glm::vec3(0, 0, 1));

rotate :

rotation = glm::rotate(glm::mat4(1.0f), valueOfRotation, glm::vec3(0, 0, 1));
for(int i = 0; i < numberObjects; i++)
objects.at(i) = objects.at(i) * rotation;

the rotation after translation works pretty well. Any idea please ? Thanks

1
Your translate code already includes a rotation. Do you rotate twice? - Ripi2
the glm:translate returns a mat4. have you try glm::mat4 translation= glm::translate(glm::mat4(1.0f), newPosition.at(i)); objects.at(i) = objects.at(i) * translation * glm::rotate(glm::mat4(1.0f), valueOfRotation, glm::vec3(0, 0, 1)); - OLIVER.KOO
@Ripi2 No, I'm not rotate twice because in glm::translate i use matrix identity. - KeurKeur
@O.KOO I tried it, but my object rotate around the Z axis not on the axis. - KeurKeur

1 Answers

0
votes

Okay, I finally found solution.

I used glm::decompose to extract the rotation and used it. But I still don't understand why

glm::translate(glm::mat4(1.0f), newPosition.at(i)) * glm::rotate(glm::mat4(1.0f), valueOfRotation, glm::vec3(0, 0, 1));

doesn't worked someone could explain me ?