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

    Quaternion rotation

    Cinema 4D SDK
    3
    5
    1.8k
    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.
    • T
      Tudor
      last edited by r_gigante

      Hello friends,
      I'm trying to work with the Quaternion-Object.
      My cam-Object should align to the direction vector and pointed in this case in X-Direction.
      But if print the q.v value I get a zero vector and the rotation is not applied
      Does I misunderstood the Quaternion-Syntax? I can't find nothing about that.
      –
      Thanks

      import c4d
      
      cam = op.GetObject()
      
      def main():
          direction = c4d.Vector(10,0,0).GetNormalized()
          angle = 0
      
          q = c4d.Quaternion()
          q.SetAxis(direction, angle)
          b = q.GetMatrix()
          b.off = cam.GetAbsPos()
          cam.SetMg(b)
      
          print q.v
      
      1 Reply Last reply Reply Quote 0
      • r_giganteR
        r_gigante
        last edited by r_gigante

        Hi Tudor,

        actually your code is properly behaving, since the angle is set to 0. If, by chance, you set it to PI/2 you will immediately see that the camera promptly rotates and point up to the sky.

        Hope the screenshot clarifies the situation
        0_1543418866361_53a67e22-4f8f-425d-bfb4-5d268a6e4924-image.png

        Best, Riccardo

        1 Reply Last reply Reply Quote 1
        • T
          Tudor
          last edited by Tudor

          I thought I can use this direction vector as Quaternion-Axis. The cam should point than to the target.
          But but it seems i need a different approach.

          import c4d, math
          
          cam = op.GetObject()
          target = op[c4d.ID_USERDATA,1]
          
          def main():
             tarPos = target.GetAbsPos()
             camPos = cam.GetAbsPos()
          
          
             direction = (tarPos - camPos).GetNormalized()
             angle = math.pi/2  #?
          
             q = c4d.Quaternion()
             q.SetAxis(direction, angle)
             b = q.GetMatrix()
             b.off = cam.GetAbsPos()
             cam.SetMg(b)
          
          1 Reply Last reply Reply Quote 1
          • r_giganteR
            r_gigante
            last edited by

            Hi Tudor, that's indeed not the way to proceed.

            Quaternion is just a tool to conveniently represent a rotation in the space. That said the approach you need to follow is just to rotate the camera until it points where your target is.

            Cheers, Riccardo

            1 Reply Last reply Reply Quote 1
            • a_blockA
              a_block
              last edited by

              Hi,

              please, do not delete discussions threads. The contained information might be valuable for future readers.

              Cheers,
              Andreas

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