Skip to main content
2 of 6
added 37 characters in body; edited tags
BungleBonce
  • 1.9k
  • 2
  • 34
  • 69

Interpolating rotated objects

I've finally got interpolation working to 'smooth' out movement, however it doesn't seem to work for objects that are rotating, or pre-rotated (around their own center) - when I try to do this, the objects in question 'wobble'.

Note: I'm not talking about interpolating the actual rotation but rather the movement of a rotated object

So, let's say I have an object moving from left to right. Using the code below (with interpolation), it moves nice and smoothly. However, after rotating the object (let's say by 45 degrees, but this could be any angle), it's no longer moving smoothly, it still moves along it's path (left to right in this case) but it's no longer smooth.

Main Game Loop

@Override
public void onDrawFrame(GL10 gl) {

    //Grab time
    newTime = System.currentTimeMillis()*0.001;
    frameTime = newTime - currentTime;
    if ( frameTime > (dt*25))
        frameTime = (dt*25);

    currentTime = newTime;

    accumulator += frameTime;

    //Save game-state and update logic
    while (accumulator >= dt){
        saveGameState();  //Back up positions before updating them
        updateLogic(); //Update logic
        t += dt;
        accumulator -= dt;
    }

    //Get the amount to interpolate by
    interpolation = (float) (accumulator / dt);

    //Interpolate positions and render
    interpolate();      
    render(interpolation);
}

Rotation Code

public void rotate(float x, float y, float angle){

    //Rotate the quad   
    Matrix.setIdentityM(mRotationMatrix, 0);
    Matrix.translateM(mRotationMatrix, 0, centreX, centreY, 0f);
    Matrix.rotateM(mRotationMatrix, 0, -angle, 0, 0, 0.1f);
    Matrix.translateM(mRotationMatrix, 0, -centreX, -centreY, 0f);
}
BungleBonce
  • 1.9k
  • 2
  • 34
  • 69