Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    How Clamp Lower/Upper Value? (MapRange)

    SDK Help
    0
    4
    919
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H
      Helper
      last edited by

      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

      1 Reply Last reply Reply Quote 0
      • H
        Helper
        last edited by

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

        Hi,

        You can simply use ClampValue().

        1 Reply Last reply Reply Quote 0
        • H
          Helper
          last edited by

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

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

          1 Reply Last reply Reply Quote 0
          • H
            Helper
            last edited by

            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
            1 Reply Last reply Reply Quote 0
            • First post
              Last post