Esempio n. 1
0
        // always returns with normalized length
        public static Vector2 Slerp(Vector2 fromV, Vector2 toV, float t) {

            // oh god this little knot has so many hidden trig and sqrts.
            var fromAng = fromV.Angle2D();
            var toAng = toV.Angle2D();
            float angleDelta = toAng - fromAng;

            // make sure we're taking the shortest route
            float flipper = angleDelta < 0f ? 360f : -360f;
            float maybeFlip = Mathf.Abs(angleDelta) > 180f ? flipper : 0f;
            float shortestDelta = angleDelta + maybeFlip;

            float angleToMove = shortestDelta * t;
            var newDir = fromV.RotateBy2D(angleToMove).normalized;
            return newDir;
        }