Skip to content
Advertisement

OpenGL ES rotating shape around its center

I tried to rotate rectangle using rotateMatrix, following tutorial on https://developer.android.com/training/graphics/opengl/motion, but when I runned it, the rectangle is rotating around (I think) point 0,0. What do I need to change to make it rotate around it’s center?

JavaScript

Advertisement

Answer

If you want to rotate around a pivot you have to:

  • Translate the object so that the pivot point is moved to (0, 0).
  • Rotate the object.
  • Move the object so that the pivot point moves in its original position.
JavaScript

However, I recommend drawing the rectangle so that the center of the rectangle is at position (0, 0). Finally move the rectangle to its target position in the scene:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement