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

    object/poly behind mouse cursor

    SDK Help
    0
    14
    1.1k
    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
      Helper
      last edited by

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

      On 06/07/2008 at 11:23, xxxxxxxx wrote:

      User Information:
      Cinema 4D Version:    
      Platform:      
      Language(s) :

      ---------
      Hi,

      i want to get info about the polygon 'behind' the mouse cursor, that is its position and normal direction.

      i realize there's the viewportSelect::getPolyInfo() and so on, but i cant quite get it to work 😞

      it seems i have to init the viewportselect with an object, but im not sure which object to use, bc as i see it, all objects of the scene may potentially be behind the mouse cursor.. sp why do i have to choose one and init the viewportselect with it ?

      anybody has some experience with this ?

      thanks,
      cineast

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

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

        On 06/07/2008 at 11:37, xxxxxxxx wrote:

        im gettings the feeling im on the wrong track using viewportselect.

        maybe its better to use geRayCollider and shoot a ray from the mouse cursor screen pos into viewport space.
        the rayCollider::Intersect needs an object as argument too though, to check if it collides with the ray..

        so do i have to loop through all objects in my scece to figure out which one is behind the mouse cursor ?

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

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

          On 07/07/2008 at 01:58, xxxxxxxx wrote:

          ok nevermind, meanwhile i found the solution in another post here..

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

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

            On 14/07/2008 at 02:48, xxxxxxxx wrote:

            It would be maybe interesting for the other forum members to know how you solved the problem. Maybe you can share what you have found out.

            cheers,
            Matthias

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

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

              On 14/07/2008 at 03:01, xxxxxxxx wrote:

              of course, forgot about tat sry 😉

              im using GeRayCollider to shoot rays from my eye through the mouse cursor, just like superman would do 😉

              in the code below im checking if the ray hits the currently active object:

              > \> AutoAlloc<GeRayCollider> rc;      \> if (!rc) return FALSE; \> // the object i want to know if it was hit \> BaseObject\* obj = doc->GetActiveObject(); \> \> Vector wtail = bd->SW(Vector(mx,my,0)); \> Vector whead = bd->SW(Vector(mx,my,10000.0)); \> Vector otail = (!obj->GetMg()) \* wtail; \> Vector oray = (whead - wtail) ^ (!obj->GetMg()); \> \> // init rayCollider with object to check ray collisions on           \> rc->Init(obj,TRUE); \> // check for intersection, 10000 is the length of the ray \> rc->Intersect(otail, !oray, 10000.0);                                               \> \> // if a ray has hit the object \> if(rc->GetNearestIntersection(&res;)){ \> . \> . \> // res.hitpos has the hit position \> // and res.f_normal is the normal vec of the hit polygon \> . \> . \> } \>

              the stuff with the computation on the right vector, i found using the forum search here.

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

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

                On 14/07/2008 at 03:03, xxxxxxxx wrote:

                Thanks for sharing

                cheers,
                Matthias

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

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

                  On 02/04/2011 at 05:25, xxxxxxxx wrote:

                  Hi,

                  I am trying this exact thing and am not getting any results.

                  Here's the code I am using.

                    
                    
                    BaseObject* pObj = doc->GetActiveObject();  
                    if(!pObj) return FALSE;  
                    
                    AutoAlloc<GeRayCollider> cRay;  
                    if (!cRay) return FALSE;  
                    
                    GeRayColResult res;  
                    
                    // Make sure RayCollider is there  
                    if (!cRay)  
                    {  
                        GePrint("ERROR - RayCollider not Initialized");  
                        return FALSE;  
                    }  
                    
                    Vector wtail =    bd->SW(Vector(x, y, UM_START));  
                    Vector whead =    bd->SW(Vector(x, y, UM_END)) - wtail;  
                    Vector otail = (!pObj->GetMg()) * wtail;  
                    Vector oray     = (whead - wtail) ^ (!pObj->GetMg());  
                    
                    
                    cRay->Init(pObj, TRUE);  
                    cRay->Intersect(otail, !oray, 10000.0);  
                    
                    
                    if (cRay->GetNearestIntersection(&res))  
                    {  
                        GePrint("A COLLISION HAS OCCURED");  
                        return TRUE;  
                    }  
                    
                    return TRUE;  
                    
                  

                  I am not seeing anything in the console that says "A COLLISION HAS OCCURED"  when I put my mouse over the active object...    Does anyone see a reason why my code wouldn't work?

                  Thanks,

                  Shawn

                  EDIT:  DOH!  I figured it out.  My collider was too short.  🙂  Remember size does matter.  😉

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

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

                    On 02/04/2011 at 11:44, xxxxxxxx wrote:

                    Is there a more complete example of this?

                    I'm assuming that bd is a parameter used with this class method:
                    virtual DRAWRESULT Draw  (BaseObject *op, DRAWPASS type, BaseDraw *bd, BaseDrawHelp *bh);

                    So I'm also assuming that the DRAWRESULT method needs to also be used.
                    But what goes inside of it?

                    Can anyone provide a more complete example of this?

                    -ScottA

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

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

                      On 02/04/2011 at 11:51, xxxxxxxx wrote:

                      what specifically would you like to achieve with it?  I could be more specific if I knew what you were looking to do.  🙂

                      To answer your first question,  bd is the BaseDraw that is allocated in my function.  In my case I am calling my function from the Draw() function which also allocates a BaseBraw so I just use the bd from that function and pass it to my own.

                      If you'd like I can repost the code I posted above with more comments to explain what each thing does.  🙂

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

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

                        On 02/04/2011 at 12:21, xxxxxxxx wrote:

                        Hi Shawn,
                        I'm just trying to learn how to do basic ray collision that prints a message to the console when the mouse is over an object.

                        I think I understand the code that's been posted so far. But it's only a small portion of the entire .cpp file. And I'm having trouble building the stuff that's not been listed to make it work.
                        Namely the classes and the methods.

                        -ScottA

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

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

                          On 02/04/2011 at 12:32, xxxxxxxx wrote:

                          The code above is coming from a ToolData plugin.   You could put the following code in the Draw() function of a tooldata plugin,

                            
                            
                          TOOLDRAW MyClass::Draw(BaseDocument* doc, BaseContainer& data, BaseDraw* bd, BaseDrawHelp* bh, BaseThread* bt, TOOLDRAWFLAGS flags){  
                              
                              
                              BaseObject* pObj = doc->GetActiveObject();  
                                if(!pObj) return TOOLDRAW_0;  
                                
                                AutoAlloc<GeRayCollider> cRay;  
                                if (!cRay) return TOOLDRAW_0;  
                                
                                GeRayColResult res;  
                                
                                // Make sure RayCollider is there  
                                if (!cRay)  
                                {  
                                    GePrint("ERROR - RayCollider not Initialized");  
                                    return TOOLDRAW_0;  
                                }  
                                
                                Vector wtail =    bd->SW(Vector(mouseX, mouseY, 0));  
                                Vector whead =    bd->SW(Vector(mouseX, mouseY, 100000));  
                                Vector otail = (!pObj->GetMg()) * wtail;  
                                Vector oray     = (whead - wtail) ^ (!pObj->GetMg());  
                                
                                
                                cRay->Init(pObj, TRUE);  
                                cRay->Intersect(otail, !oray, 10000.0);  
                                
                                
                                if (cRay->GetNearestIntersection(&res))  
                                {  
                                    GePrint("A COLLISION HAS OCCURED");  
                                }  
                                
                                return TOOLDRAW_0;  
                                
                              }  
                              
                          
                          mouseX and mouseY are global Reals.  Both declared as global variables.   Then in the GetCursorInfo()  you would simply put   
                          
                            
                                
                              Bool MyClass::GetCursorInfo(BaseDocument* doc, BaseContainer& data, BaseDraw* bd, Real x, Real y, BaseContainer& bc){  
                                
                              mouseX = x;  
                              mouseY = y;  
                              if (x > -1.0f)     SpecialEventAdd(EVMSG_UPDATEHIGHLIGHT);  
                                
                              return TRUE;  
                                
                              }  
                              
                          
                          This should give you a working model to learn from.   :)  
                            
                            
                          Hope that helps.  
                            
                          ~Shawn  
                          

                          _<_h4_>__<_h4_>_/h4>

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

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

                            On 02/04/2011 at 13:06, xxxxxxxx wrote:

                            Thanks Shawn.
                            Got it working now.👍

                            BTW: Did you ever figure out how to merge documents?

                            -ScottA

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

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

                              On 02/04/2011 at 13:11, xxxxxxxx wrote:

                              I did.   I don't have the code here though because i am not home..  send me a PM at c4d cafe to remind me and i will send it to you when i get home.  I keep forgetting to send it to you cuz when i get outa work i get focused on other things  lol

                              sorry about that.  🙂

                              ~Shawn

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

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

                                On 02/04/2011 at 14:07, xxxxxxxx wrote:

                                I'm not a member there.

                                My e-mail is:  [email protected]

                                Thanks,
                                -ScottA

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