Search code examples
c++openglglm-math

Rotating a polygon about origin


I'm trying to rotate an object (set of vertices) about the origin in opengl.

The object being a Carriage in a Ferris wheel which must not must stay upright during the rotation. So far all I've got is the following transformation which rotates the carriage but does not stay upright. This uses basic rotation transformation about the origin at a 72 degree angle. The model martix looks something like this:

g_modelMatrix[i] = glm::mat4(1.0f) * glm::rotate(glm::radians(-72.0f), glm::vec3(0.0f, 0.0f, 1.0f)); 

where glm::mat4(1.0f)is an identity matrix

The end result transforms the carriage but does not make it upright. enter image description here What transformation would be appropriate for this kind of problem?


Solution

  • This is the approach I used to solve the problem.

    rotate(i * 72°) * translate(r, 0, 0) * rotate(-i * 72°)