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
    • Recent
    • Tags
    • Users
    • Login

    Mouse location relative to a polygon.

    Scheduled Pinned Locked Moved SDK Help
    7 Posts 0 Posters 526 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

      THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

      On 11/10/2010 at 15:52, xxxxxxxx wrote:

      User Information:
      Cinema 4D Version:   12 
      Platform:   Windows  ;   
      Language(s) :     C++  ;

      ---------
      Hey everyone,

      I am trying to determine where the mouse cursor is relative to the center of a polygon.  If the mouse cursor is in the upper half of a polygon I would like one thing to happen,  if the cursor is in the bottom half of the polygon I would like another thing to happen.  Does anyone know how I would determine the location of the mouse cursor relative to the center of a polygon.  Is ViewportSelect() what I will use to do this?  Can someone help me out with this?

      Thanks,

      Shawn

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

        THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

        On 11/10/2010 at 23:19, xxxxxxxx wrote:

        One option is to use raytracing (GeRayCollider in the collider library) to shoot a ray from the viewplane along the viewing direction. From this you can get the barycentric coordinates (i.e., relative coordinates within the polygon) of the intersection point.

        Best regards
        /Filip

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

          THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

          On 12/10/2010 at 13:40, xxxxxxxx wrote:

          Is there a sample of this somewhere?

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

            THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

            On 12/10/2010 at 16:07, xxxxxxxx wrote:

            Okay so I am able to get the barycentric coordinates with the following code.

              
              
                  AutoAlloc<GeRayCollider> rc;  
                  if (!rc) return FALSE;  
                  rc->Init(objPoly, TRUE);  
              
                  Vector wtail = bd->SW(Vector(mousex,mousey,0));  
                  Vector whead = bd->SW(Vector(mousex,mousey,10000.0));  
                  Vector otail = (!objPoly->GetMg()) * wtail;  
                  Vector oray = (whead - wtail) ^ (!objPoly->GetMg());  
              
                  rc->Intersect(otail, !oray, 10000.0);  
              
                  GeRayColResult res;  
                  if (rc->GetNearestIntersection(&res))  
                  {  
                     Real x = res.barrycoords.x;  
                     Real y = res.barrycoords.x;  
                     Real z = res.barrycoords.x;  
              
                     if ( (x > 0 && x < .300) || (y > 0 && y < .300) || (z > 0 && z < .300))  
                     {  
                         GePrint("VERTICAL");  
                     }  
              
                     if ( (x > .300 && x < .700) || (y > .300 && y < .700) || (z > .300 && z < .700))  
                     {  
                         GePrint("HORIZONTAL");  
                     }  
              
              
                     GePrint("Barry Coords: Vector(" + RealToString(x) + "," + RealToString(y) + ","  \+ RealToString(z) + ")");  
              
            

            So from what I am seeing, the barrycoords are different depending on the mode you are in. Is there an explaination somewhere of how those coordinates are represented for each mode (Points, polygons, and edges)

            Thanks,

            Shawn

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

              THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

              On 12/10/2010 at 16:08, xxxxxxxx wrote:

              DOH!   I used all x's ... sorry .. my mistake.  🙂

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

                THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                On 12/10/2010 at 23:44, xxxxxxxx wrote:

                And here's some background on barycentric coordinates:

                http://en.wikipedia.org/wiki/Barycentric_coordinate_system\_(mathematics)

                Best regards
                /Filip

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

                  THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                  On 13/10/2010 at 14:16, xxxxxxxx wrote:

                  Thanks for the info and link FilipM  🙂

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