interpolation/Rescale/FloatFixed
< Interpolation | Rescale
LSL Portal | Functions | Events | Types | Operators | Constants | Flow Control | Script Library | Categorized Library | Tutorials |
Summary
Function: float fSclFix( float from_a, float from_b, float to_a, float to_b, float from );Rescales a value from one range to another range.
The value is also clamped between the range.
Returns a float
• float | from_a | |||
• float | from_b | |||
• float | to_a | |||
• float | to_b | |||
• float | from |
Specification
<lsl>float fSclFix(float from_min, float from_max, float to_min, float to_max, float from) {
from = to_min + ((to_max-to_min) * ((from_min-from) / (from_min-from_max))); if(to_min < to_max) { if(from < to_min) from = to_min; else if(from > to_max) from = to_max; } else { if(from < to_max) from = to_max; else if(from > to_min) from = to_min; } return from;
} // Released into public domain. By Nexii Malthus.</lsl>
Examples
<lsl>float value = fSclFix(0.0, 1.0, -5, 15, 0.6); // value == 7</lsl>