From ee95a1cb2834d3116e65dc5e28f9fad24455e525 Mon Sep 17 00:00:00 2001 From: Paul Joannon Date: Thu, 16 Jun 2022 13:44:50 +0200 Subject: Fix Lerp documentation and implement RangeLerp --- .../mono/glue/GodotSharp/GodotSharp/Core/Mathf.cs | 25 +++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'modules/mono/glue/GodotSharp') diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Mathf.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Mathf.cs index ce213da6a7..2b820070d6 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Mathf.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Mathf.cs @@ -276,10 +276,14 @@ namespace Godot /// Returns a normalized value considering the given range. /// This is the opposite of . /// - /// The interpolated value. + /// The start value for interpolation. /// The destination value for interpolation. - /// A value on the range of 0.0 to 1.0, representing the amount of interpolation. - /// The resulting value of the inverse interpolation. + /// The interpolated value. + /// + /// The resulting value of the inverse interpolation. + /// The returned value will be between 0.0 and 1.0 if is + /// between and (inclusive). + /// public static real_t InverseLerp(real_t from, real_t to, real_t weight) { return (weight - from) / (to - from); @@ -515,6 +519,21 @@ namespace Godot return rad * _rad2DegConst; } + /// + /// Maps a from [, ] + /// to [, ]. + /// + /// The value to map. + /// The start value for the input interpolation. + /// The destination value for the input interpolation. + /// The start value for the output interpolation. + /// The destination value for the output interpolation. + /// The resulting mapped value mapped. + public static real_t RangeLerp(real_t value, real_t inFrom, real_t inTo, real_t outFrom, real_t outTo) + { + return Lerp(outFrom, outTo, InverseLerp(inFrom, inTo, value)); + } + /// /// Rounds to the nearest whole number, /// with halfway cases rounded towards the nearest multiple of two. -- cgit v1.2.3