Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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
add comment

1 Answer

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();
share|improve this answer
add comment

Your Answer

 
discard

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.