How can I rorate an object in both positive and negative directions smoothly?

I am using keyboard keys to manually rotate my object.
To go from one direction to the other, I am switching between active and passive rotations.
However, this results in noticeable jumps, when the value switches from positive to negative, or vice versa.

I haven’t been able to work out an algorithm for this.
Does anyone have a solution?

Key up/down events should merely set or clear a flag which tracks whether the key is up or down. Timer/idle events should update the rotation angle based upon which key is down and the time since the last update.

Ideally, updates should use the time at which the frame was (or will be) displayed rather than the time “right now”. But that’s far from straightforward unless you can guarantee rendering as fast as the video refresh rate.

Key up/down events should merely set or clear a flag which tracks whether the key is up or down.

Yes.

{
	IsKeyDown(VK_LEFT) {
		Incriment(transformSpeed);
	}
}

void Incriment(const int& transformSpeed) {
	incr = true;
	if (transformSpeed == 1) {
		incriment = 1.0f;
	}
	//... etc.
	else if (transformSpeed == 5) {
		incriment = 0.0001f;
	}
}


The update happens every frame, which is rendered.

bool Frame() {
	if (incr) {
		// Update the rotation variable each frame.
		rotation += incriment;
		if (rotation > 360.0f) { rotation = 0.0f; }

		incr = false;
	}

	Render(rotation); // rotation angle
}

Ideally, updates should use the time at which the frame was (or will be) displayed rather than the time “right now”. But that’s far from straightforward unless you can guarantee rendering as fast as the video refresh rate.

I think that’s covered.

The problem isn’t the setup.
The problem is transitioning between passive, and active rotation smoothly.

I tried combining the active and passive rotations, as in this video
The transition is smooth, but weird, and not in the direction I want.
It does have a smooth transition, which is what I am trying to achieve.

1 Like