Skip to main content
added 1251 characters in body
Source Link
BungleBonce
  • 1.9k
  • 2
  • 34
  • 69
  • During logic update, Move sprite is moved and rotaterotates it around it's center (using it's new/current X and Y to calculate it's center).
  • Get's to render()
  • Render method interpolates position creating new 'throwaway' coordinates at which object should be drawn
  • Render method draws sprite at it's 'render' x and y coordinates
  • Logic update moves and rotate around it actual x and y - not it's 'rendering x and y
  • and so on

So as you can see, it's being rotated, not around the coordinates that it's been drawn at but at it's actual coordinates. I cancan't rotate it around it's render coordinates, because the rotation is done within the logic routineupdate, not during the render call, therefore, it willwould be rotating it around it 'old' render position, not the next one and I won't know the new render coordinates until the next render call which means.........

  • During logic update, Move sprite and rotate it around it's center (using it's new/current X and Y to calculate it's center).
  • Get's to render()
  • Render method interpolates position creating new 'throwaway' coordinates at which object should be drawn
  • Render method draws sprite at it's 'render' x and y coordinates
  • Logic update moves and rotate around it actual x and y - not it's 'rendering x and y
  • and so on

So as you can see, it's being rotated, not around the coordinates that it's been drawn at but at it's actual coordinates. I can rotate it around it's render coordinates, because the rotation is done within the logic routine, therefore, it will be rotating it around it 'old' render position, not the next one and I won't know the new render coordinates until the next render call which means.........

  • During logic update, sprite is moved and rotates it around it's center (using it's new/current X and Y to calculate it's center).
  • Get's to render()
  • Render method interpolates position creating new 'throwaway' coordinates at which object should be drawn
  • Render method draws sprite at it's 'render' x and y coordinates
  • Logic update moves and rotate around it actual x and y - not it's 'rendering x and y
  • and so on

So as you can see, it's being rotated, not around the coordinates that it's been drawn at but at it's actual coordinates. I can't rotate it around it's render coordinates, because the rotation is done within the logic update, not during the render call, therefore, it would be rotating it around it 'old' render position, not the next one and I won't know the new render coordinates until the next render call which means.........

added 1251 characters in body
Source Link
BungleBonce
  • 1.9k
  • 2
  • 34
  • 69

Edit

OK so it appears this is the problem:

  • During logic update, Move sprite and rotate it around it's center (using it's new/current X and Y to calculate it's center).
  • Get's to render()
  • Render method interpolates position creating new 'throwaway' coordinates at which object should be drawn
  • Render method draws sprite at it's 'render' x and y coordinates
  • Logic update moves and rotate around it actual x and y - not it's 'rendering x and y
  • and so on

So as you can see, it's being rotated, not around the coordinates that it's been drawn at but at it's actual coordinates. I can rotate it around it's render coordinates, because the rotation is done within the logic routine, therefore, it will be rotating it around it 'old' render position, not the next one and I won't know the new render coordinates until the next render call which means.........

That the only way I can do this, is to actually translate / rotate the sprite within the render routine and not the logic routine.

I've tried this and it works, but not sure I'm happy about piling more 'logic' into my render routine.

Is this an 'acceptable' model? How else can I achieve rotation while keeping the object nicely interpolated?!

Edit

OK so it appears this is the problem:

  • During logic update, Move sprite and rotate it around it's center (using it's new/current X and Y to calculate it's center).
  • Get's to render()
  • Render method interpolates position creating new 'throwaway' coordinates at which object should be drawn
  • Render method draws sprite at it's 'render' x and y coordinates
  • Logic update moves and rotate around it actual x and y - not it's 'rendering x and y
  • and so on

So as you can see, it's being rotated, not around the coordinates that it's been drawn at but at it's actual coordinates. I can rotate it around it's render coordinates, because the rotation is done within the logic routine, therefore, it will be rotating it around it 'old' render position, not the next one and I won't know the new render coordinates until the next render call which means.........

That the only way I can do this, is to actually translate / rotate the sprite within the render routine and not the logic routine.

I've tried this and it works, but not sure I'm happy about piling more 'logic' into my render routine.

Is this an 'acceptable' model? How else can I achieve rotation while keeping the object nicely interpolated?!

deleted 16 characters in body
Source Link
BungleBonce
  • 1.9k
  • 2
  • 34
  • 69

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);
}

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);
}

I've finally got interpolation working to 'smooth' out movement, however it doesn't seem to work for objects that are rotating (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);
}
Tweeted twitter.com/#!/StackGameDev/status/509079965091237888
deleted 1 character in body
Source Link
BungleBonce
  • 1.9k
  • 2
  • 34
  • 69
Loading
added 37 characters in body; edited tags
Source Link
BungleBonce
  • 1.9k
  • 2
  • 34
  • 69
Loading
Source Link
BungleBonce
  • 1.9k
  • 2
  • 34
  • 69
Loading