Skip to content

Instantly share code, notes, and snippets.

@fwilleke80
Last active March 17, 2017 11:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fwilleke80/9e88e083fbfea81f091dc4ac9280d2e9 to your computer and use it in GitHub Desktop.
Save fwilleke80/9e88e083fbfea81f091dc4ac9280d2e9 to your computer and use it in GitHub Desktop.
[C4D] Map a value from one range to another
/// Maps a value from an input range to an output range
/// e.g. from -180° ... 180° to 0.0 ... 1.0
/// Basically like the range mapper node in XPresso.
///
/// @param[in] value The input value
/// @param[in] minInput Defines the lower limit of the input range
/// @param[in] maxInput Defines the upper limit of the input range
/// @param[in] minOutput Defines the lower limit of the output range
/// @param[in] maxOutput Defines the upper limit of the output range
/// @return The mapped value
static inline Float MapRange(Float value, Float minInput, Float maxInput, Float minOutput, Float maxOutput)
{
if (maxInput - minInput == 0)
return minOutput;
return minOutput + (maxOutput - minOutput) * ((value - minInput) / (maxInput - minInput));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment