using Unity.Mathematics; namespace UnityEngine.Splines.Interpolators { /// /// Linearly interpolate between two values a and b by ratio t. /// public struct LerpFloat : IInterpolator { /// /// Linearly interpolates between a and b by t. /// /// Start value, returned when t = 0. /// End value, returned when t = 1. /// Interpolation ratio. /// The interpolated result between the two values. public float Interpolate(float a, float b, float t) { return math.lerp(a, b, t); } } /// /// Linearly interpolate between two values a and b by ratio t. /// public struct LerpFloat2 : IInterpolator { /// /// Linearly interpolates between a and b by t. /// /// Start value, returned when t = 0. /// End value, returned when t = 1. /// Interpolation ratio. /// The interpolated result between the two values. public float2 Interpolate(float2 a, float2 b, float t) { return math.lerp(a, b, t); } } /// /// Linearly interpolate between two values a and b by ratio t. /// public struct LerpFloat3 : IInterpolator { /// /// Linearly interpolates between a and b by t. /// /// Start value, returned when t = 0. /// End value, returned when t = 1. /// Interpolation ratio. /// The interpolated result between the two values. public float3 Interpolate(float3 a, float3 b, float t) { return math.lerp(a, b, t); } } /// /// Linearly interpolate between two values a and b by ratio t. /// public struct LerpFloat4 : IInterpolator { /// /// Linearly interpolates between a and b by t. /// /// Start value, returned when t = 0. /// End value, returned when t = 1. /// Interpolation ratio. /// The interpolated result between the two values. public float4 Interpolate(float4 a, float4 b, float t) { return math.lerp(a, b, t); } } /// /// Spherically interpolate between two values a and b by ratio t. /// public struct SlerpFloat2 : IInterpolator { /// /// Spherically interpolates between a and b by t. /// /// Start value, returned when t = 0. /// End value, returned when t = 1. /// Interpolation ratio. /// The spherically interpolated result between the two values. public float2 Interpolate(float2 a, float2 b, float t) { // Using Vector3 API as Mathematics does not provide Slerp for float2. var result = Vector3.Slerp(new Vector3(a.x, a.y, 0f), new Vector3(b.x, b.y, 0f), t); return new float2(result.x, result.y); } } /// /// Spherically interpolate between two values a and b by ratio t. /// public struct SlerpFloat3 : IInterpolator { /// /// Spherically interpolates between a and b by t. /// /// Start value, returned when t = 0. /// End value, returned when t = 1. /// Interpolation ratio. /// The spherically interpolated result between the two values. public float3 Interpolate(float3 a, float3 b, float t) { // Using Vector3 API as Mathematics does not provide Slerp for float3. return Vector3.Slerp(a, b, t); } } /// /// Linearly interpolate between two values a and b by ratio t. /// public struct LerpQuaternion : IInterpolator { /// /// Linearly interpolates between a and b by t. /// /// Start value, returned when t = 0. /// End value, returned when t = 1. /// Interpolation ratio. /// The interpolated result between the two values. public quaternion Interpolate(quaternion a, quaternion b, float t) { return math.nlerp(a, b, t); } } /// /// Linearly interpolate between two values a and b by ratio t. /// public struct LerpColor : IInterpolator { /// /// Linearly interpolates between a and b by t. /// /// Start value, returned when t = 0. /// End value, returned when t = 1. /// Interpolation ratio. /// The interpolated result between the two values. public Color Interpolate(Color a, Color b, float t) { return Color.Lerp(a, b, t); } } /// /// Interpolate between two values a and b by ratio t with smoothing at the start and end. /// public struct SmoothStepFloat : IInterpolator { /// /// Interpolates between a and b by ratio t with smoothing at the limits. /// This function interpolates between min and max in a similar way to Lerp. However, the interpolation will /// gradually speed up from the start and slow down toward the end. This is useful for creating natural-looking /// animation, fading and other transitions. /// /// Start value, returned when t = 0. /// End value, returned when t = 1. /// Interpolation ratio. /// The interpolated result between the two values. public float Interpolate(float a, float b, float t) { return math.smoothstep(a, b, t); } } /// /// Interpolate between two values a and b by ratio t with smoothing at the start and end. /// public struct SmoothStepFloat2 : IInterpolator { /// /// Interpolates between a and b by ratio t with smoothing at the limits. /// This function interpolates between min and max in a similar way to Lerp. However, the interpolation will /// gradually speed up from the start and slow down toward the end. This is useful for creating natural-looking /// animation, fading and other transitions. /// /// Start value, returned when t = 0. /// End value, returned when t = 1. /// Interpolation ratio. /// The interpolated result between the two values. public float2 Interpolate(float2 a, float2 b, float t) { return math.smoothstep(a, b, t); } } /// /// Interpolate between two values a and b by ratio t with smoothing at the start and end. /// public struct SmoothStepFloat3 : IInterpolator { /// /// Interpolates between a and b by ratio t with smoothing at the limits. /// This function interpolates between min and max in a similar way to Lerp. However, the interpolation will /// gradually speed up from the start and slow down toward the end. This is useful for creating natural-looking /// animation, fading and other transitions. /// /// Start value, returned when t = 0. /// End value, returned when t = 1. /// Interpolation ratio. /// The interpolated result between the two values. public float3 Interpolate(float3 a, float3 b, float t) { return math.smoothstep(a, b, t); } } /// /// Interpolate between two values a and b by ratio t with smoothing at the start and end. /// public struct SmoothStepFloat4 : IInterpolator { /// /// Interpolates between a and b by ratio t with smoothing at the limits. /// This function interpolates between min and max in a similar way to Lerp. However, the interpolation will /// gradually speed up from the start and slow down toward the end. This is useful for creating natural-looking /// animation, fading and other transitions. /// /// Start value, returned when t = 0. /// End value, returned when t = 1. /// Interpolation ratio. /// The interpolated result between the two values. public float4 Interpolate(float4 a, float4 b, float t) { return math.smoothstep(a, b, t); } } /// /// Spherically interpolates between quaternions a and b by ratio t. The parameter t is clamped b the range [0, 1]. /// public struct SlerpQuaternion : IInterpolator { /// /// Spherically interpolates between quaternions a and b by ratio t. The parameter t is clamped b the range [0, 1]. /// /// Start value, returned when t = 0. /// End value, returned when t = 1. /// Interpolation ratio. /// A quaternion spherically interpolated between quaternions a and b. public quaternion Interpolate(quaternion a, quaternion b, float t) { return math.slerp(a, b, t); } } }