How Clamp Lower/Upper Value? (MapRange)



  • On 20/01/2018 at 07:26, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:   18-19 
    Platform:      Mac OSX  ; 
    Language(s) :     C++  ;

    ---------
    Hi everybody! A small question.  How clamp Lower/Upper Values in MapRange? 
    I rewrite plugin from python to c++. Thanks to all users for helping to me)))

    inline Float MapRange(Float value, Float min_input, Float max_input, Float min_output, Float max_output, SplineData *curve = NULL)
    {
        Float inrange = max_input - min_input;
        
        if (CompareFloatTolerant(inrange, 0.0))
        {
            value = 0.0;
        }
        else
        {
            value = (value - min_input) / inrange;
        }
        
        if (curve)
        {
            value = curve->GetPoint(value).y;
        }
        
        return  min_output + (max_output - min_output) * value;
    }

    I took the source code here https://c4dprogramming.wordpress.com/2012/09/13/range-mapping/#more-98



  • On 22/01/2018 at 02:39, xxxxxxxx wrote:

    Hi,

    You can simply use ClampValue().



  • On 22/01/2018 at 03:02, xxxxxxxx wrote:

    Can u give me a example please? (How to use ClampValue())



  • On 22/01/2018 at 03:33, xxxxxxxx wrote:

    ClampValue(value, lowerLimit, upperLimit) returns:

    • lowerLimit if value is less than lowerLimit
    • upperLimit if value is greater than upperLimit
    • else value

Log in to reply