I'm having a problem with rotating/moving an image. I've set one of my images to rotate on it's z-axis buy updating the angle, but when I run my game, the image starts slowly starts to rotate from a stationary position as if to build up momentum. Once it reaches a certain speed, it begins to slow down to almost a stop, then repeats the process over. Furthermore, when it starts to rotate, it's rotating clockwise. But halfway before it stops, it's now rotating counter-clockwise.

If I were to only update it's x or y position or both, the image will move slow, then speed up to the desired speed, instead of moving at the desired speed at start.

Lastly, if I were to rotate AND move the image, the image shakes erratically while rotating. My suspicion is that I'm calculating something wrong.

Within Shader

uniform mat4 projection;
uniform mat4 view;
uniform mat4 model;
gl_Position = projection * view * model * vec4(position, 1.0);


        projection = glm::ortho(LEFT, RIGHT, BOTTOM, TOP, ORTHO_NEAR, ORTHO_FAR);

        mSprite.init("res/texture/foo.png", 1.0f);
        mSprite.setRotation(rot, glm::vec3(0, 0, 1));

        glm::vec3 pos(1.5, 0.5, 0.0);
        mSprite2.init("res/texture/bar.png", 1.0f);
        mSprite2.setRotation(0.0f, glm::vec3(0, 1, 0));


        mPosition.x += 0.000005f;
        mPosition.y += 0.000005f;

        rot += 0.0005f;
        mSprite.setRotation(rot, glm::vec3(0, 0, 1));


        mSprite.draw(mShader, view);
        mSprite2.draw(mShader, view);

draw(Shader* shader, glm::mat4& view) (mSprite)

        // Draw image...

    void setPosition(glm::vec3 position)
        mModel = glm::translate(mModel, position);

    void setRotation(GLfloat angle, glm::vec3 axis)
        mModel = glm::rotate(mModel, angle, axis);
  • \$\begingroup\$ What kind of timestep are you using? When you translate something you usually multiply it by the delta time. That way when your program is running fast it translates less. When it's running slow it translates more, so it appears to be perfectly linear movement. Without it that would cause some jittery movement. \$\endgroup\$ – Andrew Wilson Jul 27 '15 at 10:56
  • \$\begingroup\$ Do you ever push/pop the model matrix? Or reset to the identity? It sounds like you're applying transformations on top of each other while you should probably push the matriz, apply the transformations, then pop. Watch out for the order in which you apply translation and rotation simultaneously. Also you stopped the shader before drawing the image? \$\endgroup\$ – aslg Jul 28 '15 at 9:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.