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

    Screen Space Obj Center

    Scheduled Pinned Locked Moved PYTHON Development
    2 Posts 0 Posters 475 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 09/01/2018 at 08:45, xxxxxxxx wrote:

      Has anyone done anything with working out the Min/Max X,Y of points in screen space before? I'm trying to work out the screen space center of an object and need these two vectors to work out the middle.

      Any help would be awesome Smilie Thank you


        
      SHARE >(http://forums.cgsociety.org/newreply.php?do=newreply&p=8369829)

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

        On 10/01/2018 at 03:55, xxxxxxxx wrote:

        Hi more4d, thanks for writing us.

        With reference to your request, assuming you'r just interested in the object's center it's enough to retrieve the object's bounding box position via BaseObject::GetMp()  and simply transform it using BaseView::WS(). This way you can in a few lines get the position of the object's center in screen space.

          
          # get the active BaseDraw  
          bd = doc.GetActiveBaseDraw()  
            
          # check both active BaseDraw and active BaseObject  
          if bd is None:  
              return  
          if op is None:  
              return  
            
          # retrieve object's bounding-box coordinates in world space  
          opBBoxWorld = op.GetMg() * op.GetMp()  
            
          # transform from world-space to screen-space using BaseView::WS()  
          opBBoxScreen =  bd.WS(opBBoxWorld)  
            
          # print results  
          print "Object's center in world-space: ", opBBoxWorld  
          print "Object's center in screen-space: (x:", opBBoxScreen.x, ",  y:", opBBoxScreen.y, ")"  
        

        In case instead you need to refine your investigation to all the vertexes of the object, just loop over them and transform in screen-space using the same technique described above.

        For the sake of completeness, it could worth having a look here where details are explained.

        Best, Riccardo

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