Plugin Cafe Homepage
Forum Home Forum Home > Plugin Cafe > SDK Help
  New Posts New Posts
  FAQ FAQ  Forum Search

How Clamp Lower/Upper Value? (MapRange)

Author
Message
  Topic Search Topic Search
evgenyp View Drop Down
Member
Member


Joined: 2017 Mar 25
Online Status: Offline
Posts: 32
Direct Link To This Post Topic: How Clamp Lower/Upper Value? (MapRange)
    Posted: 2018 Jan 20 at 7:26am

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



Edited by evgenyp - 2018 Jan 20 at 7:27am
Back to Top
Yannick Puech View Drop Down
Forum Moderator
Forum Moderator


Joined: 2011 Apr 13
Location: Spain
Online Status: Offline
Posts: 1143
Direct Link To This Post Posted: 2018 Jan 22 at 2:39am
Hi,

You can simply use ClampValue().



MAXON
Developer Support
Back to Top
evgenyp View Drop Down
Member
Member


Joined: 2017 Mar 25
Online Status: Offline
Posts: 32
Direct Link To This Post Posted: 2018 Jan 22 at 3:02am
Can u give me a example please? (How to use ClampValue())
Back to Top
Yannick Puech View Drop Down
Forum Moderator
Forum Moderator


Joined: 2011 Apr 13
Location: Spain
Online Status: Offline
Posts: 1143
Direct Link To This Post Posted: 2018 Jan 22 at 3:33am
ClampValue(value, lowerLimit, upperLimit) returns:
  • lowerLimit if value is less than lowerLimit
  • upperLimit if value is greater than upperLimit
  • else value


MAXON
Developer Support
Back to Top

Forum Jump Forum Permissions View Drop Down

Bulletin Board Software by Web Wiz Forums® version 9.61 [Free Express Edition]
Copyright ©2001-2009 Web Wiz

This page was generated in 0.094 seconds.