1

I set up my ortho projection like this :

transform = glm::ortho(0.0f, width, height, 0.0f);

this works pretty well, but when I want to use the glm::rotate function like this:

transform = glm::rotate(transform, glm::radians(45.0f), glm::vec3(0, 0, 1));

my object rotates around 0 : 0 : 0.

my vertices look like this:

GLfloat vertices[] = {
    600, 100, 0,
    612, 100, 0,
    612, 130, 0,
    600, 130, 0
};

how can I make my object rotate around its center ?

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
  • I've removed the [tag:glm] tag. [tag:glm] (generalized linear models) != [tag:glm-math] (GLM - OpenGL Mathematics) – Rabbid76 Oct 03 '21 at 10:52

1 Answers1

0

If you want to rotate around its center you have to:

  • Translate the object so that the center of the object is moved to (0, 0).
  • Rotate the object.
  • Move the object so that the center point moves in its original position.
GLfloat center_x = 606.0f;
GLfloat center_y = 115.0f;

transform = glm::translate(transform, glm::vec3(center_x, center_y, 0));
transform = glm::rotate(transform, glm::radians(45.0f), glm::vec3(0, 0, 1));
transform = glm::translate(transform, glm::vec3(-center_x, -center_y, 0));

See also How to use Pivot Point in Transformations

Rabbid76
  • 202,892
  • 27
  • 131
  • 174