Skip to content

Instantly share code, notes, and snippets.

@tenpn tenpn/MapValue.cs
Created Jul 26, 2012

Embed
What would you like to do?
MapValue() takes an input in one range and remaps it to another. Very useful for AI and scripting.
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
You can’t perform that action at this time.