Sprite - rotation acceleration

Hello

I want to create a “sprite” whose rotation is accelerating and when I press button (‘A’ for example) acceleration slows down.
This is what I created:

	
private void update()
	{

		if(1 < 2)
		{
			rotation=1;
			time += Gdx.graphics.getDeltaTime();
			rotation *= time * temp;
			System.out.println("time " + time);
			System.out.println("rotation " + rotation);
			System.out.println("temp " + temp);

			if(rotation > 360)
			{
				time = 0;
				temp += 30;
			}
			else if(Gdx.input.isKeyPressed(Keys.A))
			{
				rotation -= 4.0f;
				time = 0;
				temp /= 1.01;
			}
		}
	}

and render:

batch.draw(kreska2, Gdx.graphics.getWidth()/2-kreska.getWidth()/2, Gdx.graphics.getHeight()/2, 0, 0, kreska.getWidth(), kreska.getHeight(), 1, 1, rotation);
  1. Iis it designed in the correct way? Or it is piece of…?
  2. How to create a smooth acceleration?
  3. (It is main question) Right now when I press ‘A’ rotation speed will slow down but angle will be set to 0. When I will just use ‘rotation -= 4.0f;’ to slow down rotation, that the angle will go back several degrees. How to handle this topic?

You should think in terms of:

  • position (in your case “angular position” or “orientation”, what you call “rotation”)
  • velocity (in your case “angular velocity”)
  • acceleration (in your case “angular acceleration”)

and how those terms relate to each other. Research that first!

Orientation relates to angular velocity in the following way:
delta(orientation) / delta(time) = angular velocity
where delta(X) means: the change/difference of X between some last point in time t0 and next point in time t1.

reordering this equation gives:
delta(orientation) = angular velocity * delta(time)

So, accumulating orientation can be done like this:
orientation += angular velocity * delta(time)

For angular velocity vs. angular acceleration it looks equivalent to the above:
delta(angular velocity) / delta(time) = angular acceleration

reordering:
delta(angular velocity) = angular acceleration * delta(time)

Accumulating:
angular velocity += angular acceleration * delta(time)

You want to accelerate (increase angular velocity, that is) when button ‘A’ is not pressed. So, set the angular acceleration to some value, say 1.0.
Based on the new angular acceleration you can compute the delta(angular velocity). Based on the new angular velocity you compute delta(orientation) and based on that you end up with the new absolute orientation. You do this process constantly each frame. The only thing that changes is how much acceleration you apply to your rotation.
When you press ‘A’, you use a negative angular acceleration that is acting in the opposite rotation direction.