Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to rotate an image in opengles GLkit and get it back to its original position in GLkit.

rotation += 5;
_modelViewMatrix = GLKMatrix4Rotate( _modelViewMatrix, GLKMathDegreesToRadians(5), 1, 0, 0);
_modelViewMatrix = GLKMatrix4Rotate( _modelViewMatrix, GLKMathDegreesToRadians(rotation), 1,0,0);

I need to move it in x axis for certain amount and getting back to its original position from where it started. How should i do it?

share|improve this question
Interpolation/tweening will be your friend. Save your start rotation and position as well as time, maintain a percentage variable and increase it to 1 for so many seconds, then back to 0. Multiply the distance you want to move in total by this percentage and add that onto your original start positions/rotation (you'll probably want to have two separate end variables, one for x-axis and one for the rotation since you probably don't want to be moving x as fast as you rotate or vice versa). – Jeff Mar 15 '13 at 12:53

Here's some very crude code to roughly illustrate a potential solution:

   vec3 startRot = object.transform.rotation;
   object.startRotReference = startRot;

rotation += 5;


if(object.transform.rotation.x >= object.targetRotX)
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.