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?

  • \$\begingroup\$ 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). \$\endgroup\$ – 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)
| improve this answer | |

Your Answer

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

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