# Rotate an image and get back to its original position - opengles glkit

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?

• 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:

 if(object.grabStart){
vec3 startRot = object.transform.rotation;
object.startRotReference = startRot;
}

rotation += 5;

object.RotateXYZ(rotation,0,0);

if(object.transform.rotation.x >= object.targetRotX)
object.RotateToStartRot();