Interpolation/Rescale
Jump to navigation
Jump to search
| LSL Portal | Functions | Events | Types | Operators | Constants | Flow Control | Script Library | Categorized Library | Tutorials | Interpolation |
Rescale
Float Rescale | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Rescales a value from one range to another range. <lsl> float fScl(float from0, float from1, float to0, float to1, float t) { return to0 + ( (to1 - to0) * ( (from0 - t) / (from0-from1) ) ); } </lsl>
Released to Public Domain. By Nexii Malthus
|
Float Rescale Fixed | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Rescales a value from one range to another range. The value is clamped between the range. <lsl> float fSclFix(float from0, float from1, float to0, float to1, float t) { t = to0 + ( (to1 - to0) * ( (from0 - t) / (from0-from1) ) );
if(to0 < to1) {
if(t < to0) t = to0; else if(t > to1) t = to1;
} else {
if(t < to1) t = to1; else if(t > to0) t = to0;
}
return t;
} </lsl>
Released to Public Domain. By Nexii Malthus
|