carlos
carlos

Reputation: 35

glm rotate and translation

I have a mat4 called model. I want my cube to orbit around a position. I am able to call the glm::rotate(mat4, angle, vec3) just fine and have it rotate at its origin.

void Object::Update(unsigned int dt)
{
  angle += dt * M_PI/1000;
  model = glm::rotate(glm::mat4(1.0f), (angle), glm::vec3(0.0, 1.0, 0.0));
  model = glm::translate(glm::mat4(1.0f), glm::vec3(0.5f, -0.5f, 0.0f));
}

Unfortunately my cube is frozen in place when I add the glm::translate call after the rotation. Is there something basic I'm missing?

Upvotes: 0

Views: 4734

Answers (1)

Carl
Carl

Reputation: 2067

You must pass it the result of the rotation as the initial matrix: model = glm::translate(model, glm::vec3(0.5f, -0.5f, 0.0f));. Otherwise you are resetting and translating the Identity matrix, which will completely overwrite your rotation.

Upvotes: 2

Related Questions