I'm having troubles getting a normalized float to smoothly rotate some sprites. I'm using interpolation to rotate my sprites. At a certain point in the rotation the sprite will jump, at the same spot every time.
name.angle = (name.getBody().getTransform().getRotation() * alpha + name.prevAngle * (1.0f - alpha));
I've looked online and found a couple ways to normalize an angle between -pi and +pi but I can't get them to work in my situation.
The following doesn't work
if (name.angle > Math.PI)
name.angle += 2 * Math.PI;
else if (name.angle < -Math.PI)
name.angle -= 2 * Math.PI;
The following does work
name.angle = name.angle < 0 ? MathUtils.PI2 - (-name.angle % MathUtils.PI2) : name.angle % MathUtils.PI2;