This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rotation = MathHelper.Lerp(rotation, nextRotation, 0.06f); |
I used the following code that I found on app hub.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private float CurveAngle(float from, float to, float step) | |
{ | |
if (step == 0) return from; | |
if (from == to || step == 1) return to; | |
Vector2 fromVector = new Vector2((float)Math.Cos(from), (float)Math.Sin(from)); | |
Vector2 toVector = new Vector2((float)Math.Cos(to), (float)Math.Sin(to)); | |
Vector2 currentVector = Slerp(fromVector, toVector, step); | |
return (float)Math.Atan2(currentVector.Y, currentVector.X); | |
} | |
private Vector2 Slerp(Vector2 from, Vector2 to, float step) | |
{ | |
if (step == 0) return from; | |
if (from == to || step == 1) return to; | |
double theta = Math.Acos(Vector2.Dot(from, to)); | |
if (theta == 0) return to; | |
double sinTheta = Math.Sin(theta); | |
return (float)(Math.Sin((1 - step) * theta) / sinTheta) * from + (float)(Math.Sin(step * theta) / sinTheta) * to; | |
} |