Browse Source

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
Noor Wachid 5 năm trước cách đây
mục cha
commit
abb94bd2ff
1 tập tin đã thay đổi với 12 bổ sung0 xóa
  1. 12 0
      src/raymath.h

+ 12 - 0
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
 //----------------------------------------------------------------------------------