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

    C++ The product of the Matrix and another type function does not exist?

    Cinema 4D SDK
    4
    8
    1.1k
    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.
    • Y
      yaya
      last edited by

      Hello!
      I develop my plugin on C++ and trying to receive the same line of Python code:

      matrixA= c4d.utils.MatrixMove(c4d.Vector(0,10,0)) 
      matrixB = myObject.GetMg().__mul__(matrixA)
      

      MatrixMove func exists in a C++ help. But I can't find in C++ help the analogue of .mul function.

      So does this function from a Python help: https://bit.ly/30dc2Ps
      https://developers.maxon.net/docs/py/2023_2/modules/c4d/Matrix/index.html?highlight=mul#Matrix.mul

      exists for a C++?

      1 Reply Last reply Reply Quote 0
      • CairynC
        Cairyn
        last edited by

        operator * does not work for you?

        1 Reply Last reply Reply Quote 0
        • ManuelM
          Manuel
          last edited by

          Hi,
          Cairyn is right, the operator you are looking for is *

          Cheers
          Manuel

          MAXON SDK Specialist

          MAXON Registered Developer

          Y 1 Reply Last reply Reply Quote 0
          • Y
            yaya @Manuel
            last edited by

            @m_magalhaes @Cairyn

            Hello guys.
            No, the simple operator * between two matrixes shows an error.
            Right now I've write it like this:

            matrixB = myObject->GetAbsPos() * matrixA;
            

            also via operator*.

            But I am not sure will GetAbsPos return the same (according I need only the position offset of matrix).

            ferdinandF 1 Reply Last reply Reply Quote 0
            • ferdinandF
              ferdinand @yaya
              last edited by ferdinand

              Hello @yaya,

              matrixB = myObject->GetAbsPos() * matrixA;

              First of all, BaseObject::GetAbsPos returns a Vector, which in turn makes your calculation at least implicitly wrong, since you call the result matrixB, implying that it is a matrix. But the product of a matrix M and a vector p is the vector p' transformed by M. There is also the fact that order matters in the C++ SDK, i.e., you are forced to write expressions in the canonical matrix-first order (in Python you are not restricted in such fashion, because Python handles operator overloading differently).

              Vector p; Matrix M;
              
              // Valid expression since Mat3 has an operator overload for M * p
              Vector q = M * p;
              // Invalid expression since Vec3 does not have an operator overload for p * M
              Vector r = p * M;
              

              It might also be noteworthy that Matrix and Vector are only aliases originating from our classic API. The types have been replaced by a more versatile templated model of the atomic arithmetic types. Vector is just a typedef for maxon::Vec3<maxon::Float64, 1> and Matrix for maxon::Mat3<maxon::Vector64>. You can find the relevant template descriptions in the Mat3< V > Struct Template and Vec3< T, STRIDE > Struct Template references.

              Cheers,
              Ferdinand

              MAXON SDK Specialist
              developers.maxon.net

              Y 3 Replies Last reply Reply Quote 0
              • Y
                yaya @ferdinand
                last edited by yaya

                Hello @ferdinand

                Thank you for a such detailed answer.
                It is hard for me to understand all of it by eye, and I can't say right now is it what I search.
                I need to receive in the result the point in 3d space which is attached to another point like it is a child of parent (only position is needed).

                So all construction serves to achieve a Vector point of a new position shifted by 10 units in a one of its local axis. (Vector(0,10,0))

                I will finish my python-C++ rewriting and will test your example above.
                Thank you!

                1 Reply Last reply Reply Quote 0
                • Y
                  yaya @ferdinand
                  last edited by

                  This post is deleted!
                  1 Reply Last reply Reply Quote 0
                  • Y
                    yaya @ferdinand
                    last edited by

                    Hello @ferdinand
                    I've tested it a bit and now I've finished with this:

                    instead of this:

                    matrixA= c4d.utils.MatrixMove(c4d.Vector(0,10,0)) 
                    matrixB = myObject.GetMg().__mul__(matrixA)
                    

                    to this:

                    Matrix matrix = MatrixMove(Vector(0, 10, 0)); 
                    Vector vector = myObject->GetMg() * matrix.off;
                    

                    It looks it works for me.
                    Thank you again!

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