Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware 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

    Global to Local pos

    Cinema 4D SDK
    python
    2
    9
    1.5k
    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.
    • Passion3DP
      Passion3D
      last edited by Passion3D

      Hi
      How to convert global position to local.
      I want to convert global position of Object to local position of his parent

      1 Reply Last reply Reply Quote 0
      • M
        mp5gosu
        last edited by

        Here you will find any information about matrices and thus everything about positioning, scaling, rotation, etc.

        1 Reply Last reply Reply Quote 1
        • Passion3DP
          Passion3D
          last edited by Passion3D

          I'm not an expert in math 😉 i tried but don"t work
          My english is null and google translate isn't always correct
          Can you give me an example?

          1 Reply Last reply Reply Quote 0
          • M
            mp5gosu
            last edited by mp5gosu

            No problem. 🙂

            Now to your question: You can simply call GetMl() on your child object. This returns you the local matrix of the object. Now to access the position, ask the matrix for the offset:

            myObject.GetMl().off
            

            It's the very first example code in the documentation I linked in my previous post.

            @passion3d said in Global to Local pos:

            google translate isn't always correct

            You should try Deepl

            1 Reply Last reply Reply Quote 1
            • Passion3DP
              Passion3D
              last edited by

              My question may not be clear enough.
              I have an object1 that has a child Object2
              I want to move Object2 to a global position, so I have to convert the global position from destination to local position with respect to its parent.

              1 Reply Last reply Reply Quote 0
              • M
                mp5gosu
                last edited by mp5gosu

                You don't have to!

                There's also a function available: SetMg()

                I warmly suggest you to read the Matrix Fundamentals since it has been written to demystify the matrix math. It also has various code examples for all kinds of transformations, including your scenario.

                edit: Now that I think about your question: Do you want to move the parent with the child?

                1 Reply Last reply Reply Quote 2
                • Passion3DP
                  Passion3D
                  last edited by

                  no, i want move the child but not the parent

                  1 Reply Last reply Reply Quote 0
                  • M
                    mp5gosu
                    last edited by mp5gosu

                    Sorry, got you slightly wrong then.

                    Try this:

                        m = op.GetMg() # get the object's matrix
                        m.off = c4d.Vector(50) # modify the position
                        op.SetMg(m) #set the modified matrix
                        c4d.EventAdd() # update C4D
                    

                    This code simply moves the child, completely decoupled from its parent in absolute world coordinates.

                    1 Reply Last reply Reply Quote 2
                    • Passion3DP
                      Passion3D
                      last edited by Passion3D

                      Thank you @mp5gosu 😉
                      This is exactly what I was looking for.
                      In fact, C4D does the calculations itself. I thought I had to do the matrix multiplication, and I didn't understand how to do it.
                      Finally it's very simple 🙂

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