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

    quaternion in c4d[Solved]

    Scheduled Pinned Locked Moved PYTHON Development
    2 Posts 0 Posters 250 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 03/02/2013 at 14:43, xxxxxxxx wrote:

      Hi

      i am trying to import some tracking data (faceshift) into c4d.
      everything works fine, except that i can not get the head-rotation work properly.

      the head rotation i get from faceshift is in quaternion format and consist of 4 float values (x,y,z,w)

      i tried doing something like this:

      newMatrix=c4d.utils.RotAxisToMatrix(c4d.Vector(x,y,z),w)
      headTarget.SetMl(newMatrix)

      i tried a lot with swapping or negating the values x,y,z and w, but had no luck so far.

      i know that faceshift and c4d do not use the same coordinates systems (left handed vs right handed), because to get the head-translation correctly i need to negate the z-value.

      hope someone can show me the way....

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

        On 03/02/2013 at 15:55, xxxxxxxx wrote:

        OK I solved it myself:

        Here is how i got it working:

        newMatrix = quaternionToMatrix(x,y,z,w)
                  headTarget.SetRelRot(c4d.utils.MatrixToHPB(newMatrix))

        def quaternionToMatrix(x,y,z,w) :
          xx      = x * x;
          xy      = x * y;
          xz      = x * z;
          xw      = x * w;
          yy      = y * y;
          yz      = y * z;
          yw      = y * w;
          zz      = z * z;
          zw      = z * w;
          vec1=c4d.Vector()
          vec2=c4d.Vector()
          vec3=c4d.Vector()
          vecOff=c4d.Vector()
          vec1.x  = 1 - 2 * ( yy + zz );
          vec1.y  =     2 * ( xy - zw );
          vec1.z  =     2 * ( xz + yw );
          vec2.x  =     2 * ( xy + zw );
          vec2.y  = 1 - 2 * ( xx + zz );
          vec2.z  =     2 * ( yz - xw );
          vec3.x  =     2 * ( xz - yw );
          vec3.y  =     2 * ( yz + xw );
          vec3.z = 1 - 2 * ( xx + yy );
          newMatrix=c4d.Matrix(vecOff,vec1,vec2,vec3)       
          return newMatrix

        here is the link where i found the function:
        http://web.archive.org/web/20041029003853/http://web.archive.org/web/20041029003853/http://www.j3d.org/matrix_faq/matrfaq_latest.html#Q54

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