Last active
March 17, 2017 11:32
-
-
Save fwilleke80/9e88e083fbfea81f091dc4ac9280d2e9 to your computer and use it in GitHub Desktop.
[C4D] Map a value from one range to another
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
/// 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