From abb94bd2fff7f7722f7f0bee492337dd8bd95b35 Mon Sep 17 00:00:00 2001 From: Noor Wachid <42460975+NoorWachid@users.noreply.github.com> Date: Fri, 15 May 2020 18:08:28 +0700 Subject: [PATCH] Adding Normalize and Remap functions (#1247) * Adding Norm and Remap functions // Normalize input value within input range // Remap input value within input range to output range * Rename Norm to Normalize To make it uniforms with Raylib's functions * Calculate Remap without other functions --- src/raymath.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/raymath.h b/src/raymath.h index 662ce25c2..c00aa06fb 100644 --- a/src/raymath.h +++ b/src/raymath.h @@ -154,6 +154,18 @@ RMDEF float Lerp(float start, float end, float amount) return start + amount*(end - start); } +// Normalize input value within input range +RMDEF float Normalize(float value, float start, float end) +{ + return (value - start) / (end - start); +} + +// Remap input value within input range to output range +RMDEF float Remap(float value, float inputStart, float inputEnd, float outputStart, float outputEnd) +{ + return (value - inputStart) / (inputEnd - inputStart) * (outputEnd - outputStart) + outputStart; +} + //---------------------------------------------------------------------------------- // Module Functions Definition - Vector2 math //----------------------------------------------------------------------------------