Created
July 26, 2012 07:30
-
-
Save tenpn/3180757 to your computer and use it in GitHub Desktop.
MapValue() takes an input in one range and remaps it to another. Very useful for AI and scripting.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static float MapValue(float inVal, float inFrom, float inTo, float outFrom, float outTo) | |
{ | |
float inScale = (inFrom != inTo) | |
? ( ( inVal - inFrom ) / ( inTo - inFrom ) ) | |
: 0.0f; | |
float outVal = outFrom + ( inScale * ( outTo - outFrom ) ); | |
outVal = (outFrom < outTo ) | |
? SomeClampFunction( outVal, outFrom, outTo ) | |
: SomeClampFunction( outVal, outTo, outFrom ); | |
return outVal; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment