From 82faaca87cadfe7b5cc1a0ea6ccc8a7426a0595d Mon Sep 17 00:00:00 2001 From: James Khan Date: Sat, 1 Jun 2019 12:39:13 +0100 Subject: [PATCH] Add unInterpolateLinear to FastMath class --- jme3-core/src/main/java/com/jme3/math/FastMath.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/jme3-core/src/main/java/com/jme3/math/FastMath.java b/jme3-core/src/main/java/com/jme3/math/FastMath.java index 1bbf37fca..e1683d214 100644 --- a/jme3-core/src/main/java/com/jme3/math/FastMath.java +++ b/jme3-core/src/main/java/com/jme3/math/FastMath.java @@ -992,4 +992,16 @@ final public class FastMath { | ((((f & 0x7f800000) - 0x38000000) >> 13) & 0x7c00) | ((f >> 13) & 0x03ff)); } + + /** + * Converts a range of min/max to a 0-1 range. + * @param value the value between min-max (inclusive). + * @param min the minimum of the range. + * @param max the maximum of the range. + * @return A value between 0-1 if the given value is between min/max. + */ + public static float unInterpolateLinear(float value, float min, float max) { + return (value - min) / (max - min); + } + }