Difference between revisions of "Interpolation/Rescale/FloatFixed"

From Second Life Wiki
Jump to navigation Jump to search
(Created page with "{{LSL_Function |mode=user |func=fSclFix |p1_type=float|p1_name=from_a |p2_type=float|p2_name=from_b |p3_type=float|p3_name=to_a |p4_type=float|p4_name=to_b |p5_type=float|p5_name…")
 
m (<lsl> tag to <source>)
 
(One intermediate revision by one other user not shown)
Line 2: Line 2:
|mode=user
|mode=user
|func=fSclFix
|func=fSclFix
|p1_type=float|p1_name=from_a
|p1_type=float|p1_name=from_min|p1_desc=Minimum of range From
|p2_type=float|p2_name=from_b
|p2_type=float|p2_name=from_max|p2_desc=Maximum of range From
|p3_type=float|p3_name=to_a
|p3_type=float|p3_name=to_min|p3_desc=Minimum of range To
|p4_type=float|p4_name=to_b
|p4_type=float|p4_name=to_max|p4_desc=Maximum of range To
|p5_type=float|p5_name=from
|p5_type=float|p5_name=from|p5_desc=Value in range From
|return_type=float
|return_type=float
|return_value=returns clamped and rescaled value
|return_value=returns clamped and rescaled value
Line 13: Line 13:


The value is also clamped between the range.  
The value is also clamped between the range.  
|spec=<lsl>float fSclFix(float from_min, float from_max, float to_min, float to_max, float from) {
|spec=<source lang="lsl2">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)));
     from = to_min + ((to_max-to_min) * ((from_min-from) / (from_min-from_max)));
     if(to_min < to_max) {
     if(to_min < to_max) {
Line 22: Line 22:
     return from;
     return from;
}
}
// Released into public domain. By Nexii Malthus.</lsl>
// Released into public domain. By Nexii Malthus.</source>
|examples=<lsl>float value = fSclFix(0.0, 1.0, -5, 15, 0.6); // value == 7</lsl>
|examples=<source lang="lsl2">float value = fSclFix(0.0, 1.0, -5, 15, 0.6); // value == 7</source>
|cat1=Examples
|cat1=Examples
}}
}}

Latest revision as of 16:07, 24 January 2015

Summary

Function: float fSclFix( float from_min, float from_max, float to_min, float to_max, float from );

Rescales a value from one range to another range.

The value is also clamped between the range.
Returns a float

• float from_min Minimum of range From
• float from_max Maximum of range From
• float to_min Minimum of range To
• float to_max Maximum of range To
• float from Value in range From

Specification

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.

Examples

float value = fSclFix(0.0, 1.0, -5, 15, 0.6); // value == 7