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

    Easing script

    Scheduled Pinned Locked Moved PYTHON Development
    3 Posts 0 Posters 554 Views
    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 Offline
      Helper
      last edited by

      On 11/02/2018 at 05:37, xxxxxxxx wrote:

      Hi everybody, I'm trying to add an ease-in expression to a rig. I'm not really a math guy, so I'm referencing Penner's equation and in particular this doc: http://upshots.org/actionscript/jsas-understanding-easing.

      My code for testing looks like this so far:

      import c4d, math
      #Welcome to the world of Python
        
        
      start = 10   #start pos
      end = 300    #end pos
      d = 50       #duration
        
        
      def easein(t,d) :
          ratio = t/d
          print "ratio: ",ratio
          return math.pow(ratio,5)
        
      def main() :
          t = doc.GetTime().GetFrame(doc.GetFps()) #current frame
          factor = easein(t,d)
          out_pos = start + (end-start) * factor
          print "t: ", t
          print "d: ", d
          print "factor: ", factor
          print "out pos: ", out_pos
      

      but the result of (t/d) is always 0.0. I guess is something with the values type but I can't figure it out.
      What am I doing wrong?

      Thanks for any advice or help!
      cheers
      massimiliano

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

        On 12/02/2018 at 01:49, xxxxxxxx wrote:

        Hi,

        you are calculating the ratio as an integer division. Simple solution, either make d a float value (d = 50.0) or force the division to be calculated with floating point (ration = float(t) / float(d)).
        Here's some information on Floating Point Arithmetic in the Python docs.
        Please also note, Cinema 4D use a 2.7.x implementation of Python. There is a change in behavior of integer division compared to Python 3.x, see for example here.

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

          On 12/02/2018 at 12:21, xxxxxxxx wrote:

          Ahh, that makes sense. Thanks for the help!
          Massimiliano

          1 Reply Last reply Reply Quote 0
          • First post
            Last post