# Smooth matrix rotation

I have a coded a simple example for a matrix rotation. The example rotates a sphere around its center. The problem is that the rotation is not running perfectly smooth and I'm wondering why.

Here is a minimal code sample:

float totalMs = 0.0f;
int animationDuration = 5000;

void update(float deltaMs) {
totalMs += deltaMs;
float degrees = (totalMs % animationDuration) / animationDuration * 360.0f;
glm::mat4 rotation = glm::rotate(glm::mat4(), radians(degrees), rotationAxis);

//multiply modelViewMatrix by rotation matrix
//and use the resulting matrix in shader to transform points
}


I'm programming in C++, using GLM Library for Maths, SDL2 for rendering context and OpenGL for the rendering.

Any hints what could cause the rendering to not look totally smooth?

Edit: Ok I found out that the time needed for SDL_GL_SwapWindow() at the end of my gameLoop varies between <1ms and >30ms. What could be causing this?

• What are usual values of deltaMs here? Are you sure it is not a framerate problem? – Aracthor Sep 28 '15 at 0:55
• Looks like the deltaMs could be jittery/non-smooth. – Kromster says support Monica Sep 28 '15 at 16:08
• You are right its because of the deltaMs, I made an edit to the question. Any Ideas? – Dirk Sep 28 '15 at 20:27
• You should reformulate and rename your question to reflect the problem. – Kromster says support Monica Sep 29 '15 at 5:11