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

    Direction vector

    General Talk
    2
    3
    634
    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.
    • WickedPW
      WickedP
      last edited by

      Hi folks,

      I can't get this right. Sometime a go I posted a topic on CreateRay(). I got a (spherical?) example which was awesome, and I could play around with it to some degree. But I'm not grasping how I can expand on this.

      Instead of a spherical lens, if I have two angles that I want to 'add' to my camera's rotation, how do I create a direction vector from the camera matrix with this? How would this look in math/coding terms with the following added to the camera rotation:

      yaw = 4.5°
      pitch = 3.7°
      

      I'm trying to create a direction vector that's based on two angles from my camera's centre. So 4.5° left/right and 3.7° up/down kind of thing.

      WP.

      wickedp.com

      1 Reply Last reply Reply Quote 0
      • r_giganteR
        r_gigante
        last edited by

        Hi wickedP, thanks for reaching out us.

        With regard to your request, the solution is pretty easy: using the GetRotationMatrixX() and GetRotationMatrixY() you get two transformation matrixes that in the end should be multiplied by your camera transformation matrix.

        6a9c60fa-9b6b-437a-8f5d-a2387c6718c4-image.png
        In Python it looks like

            # get the cam
            cam = doc.GetActiveObject()
        
            #get the ray (it's just another camera with 0.2 aperture)
            ray = cam.GetNext()
        
            # create the yaw and pitch matrixes
            pitchMatrix = c4d.utils.MatrixRotX(c4d.utils.DegToRad(3.7))
            yawMatrix = c4d.utils.MatrixRotY(c4d.utils.DegToRad(4.5))
        
            # combine them and set the ray tranformation matrix
            ray.SetMg(pitchMatrix * yawMatrix * cam.GetMg())
            
            c4d.EventAdd()
        
        1 Reply Last reply Reply Quote 0
        • WickedPW
          WickedP
          last edited by

          Thanks Ricky,

          but I'm not sure if that's what I'm after. That looks like normal object rotation, but I'm trying to make a direction vector. The example given in a previous post did something like this:

          CreateRay(Ray* dst,Real x,Real y)
          {
          	CameraMatrix = MyCam->GetMg();
          	
          	Vector H = CameraMatrix.v1;
          	Vector V = CameraMatrix.v2;
          	Vector A = CameraMatrix.v3;
          	Vector direction_vector = H + V + A;
          	
          	// how do I "add" 4.5° yaw to the direction_vector?
          	// similarly for pitch
          	
          	dst->v = direction_vector;
          	dst->p = CameraMatrix.off;
          }
          

          How do I "add" 4.5 degrees to the yaw with something like this (taking into account the camera's rotation as well)? I'd like to see the math so I can play around with that.

          If it's easier, think of it like this - I'm trying to create the standard camera ray without any lens effects (trying to keep it simple). How is the standard camera ray done?

          WP.

          wickedp.com

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