# OpenGL calculate circle rotation around a given point

I'm trying to rotate an object around a certain point. If this point is the center of my world space I use the following algorithm:

glm::vec3 center is the center of the current object. Each frame it will get updated.

glm::mat4 transformationMatrix is the 4x4 matrix I am "uploading" to my shader later on. It will get multiplied by the vertex position.

t_point is the point I'd like to rotate around

t_deflection is the impact for each axis (in order to draw ellipses instead of circles)

t_speed is in my case the current time since the game started (e.g. glfwGetTime())

void rotateByPointY( const glm::vec3& t_point, const glm::vec3& t_deflection, const float& t_speed )
{
float radius = glm::length( t_point - center );

glm::vec3 newPosition( glm::sin( t_speed ) * radius * t_deflection.x, center.y, glm::cos( t_speed ) * radius * t_deflection.z );

translationMatrix = glm::translate( glm::mat4( 1.0f ), newPosition );
center = newPosition;
}


How can I take into account a point other than the center of my world in the calculation?

EDIT:

So my rotateByPointY calculates the translation around the world center. Therefore I am adding the new center vector to my new position:

translationMatrix = glm::translate( glm::mat4( 1.0f ), newPosition + t_point );
center = newPosition + t_point;


That is working now!

• Have you heard the joke about the blue elephant gun? Try reducing the problem to one you already know how to solve. If you know how to rotate around zero, see if you can take the point you want to rotate around and shift it to zero, then shift the result back. Commented Feb 28, 2018 at 16:47
• I did not know the joke but it is a good one! Commented Feb 28, 2018 at 17:37