GeRayCollider problem in Perspective view



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

    On 21/10/2005 at 18:39, xxxxxxxx wrote:

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

    ---------
    Howdy,

    I have a problem with my tool plugin and the GeRayCollider in the perspective view. It's not detecting a collision when one part of the mesh is behind another part if there is a lot of distance between the parts.

    When the foot is below the hand in the perspective view it picks up points of the foot:

    But when the the polygons of the foot are moved closer to the hand then it is detecting a collision.

    It works fine in the Top View no matter how much distance is between the hand and foot:

    Here is the code:

      
    Bool TestTool::MouseInput(BaseDocument *doc, BaseContainer &data;, BaseDraw *bd,EditorWindow *win, const BaseContainer &msg;)  
    {  
         opActive = doc->GetActiveObject(); if(!opActive) return TRUE;  
      
         Vector     rayEnd, rayStart, opt, mpt, *padr = ToPoint(opActive)->GetPoint();  
         LONG     index, ptCount = ToPoint(opActive)->GetPointCount();  
         Matrix     rayMatrix;  
      
         mx = msg.GetReal(BFM_INPUT_X);  
         my = msg.GetReal(BFM_INPUT_Y);  
         LONG button;  
           
         switch (msg.GetLong(BFM_INPUT_CHANNEL))  
         {  
              case BFM_INPUT_MOUSELEFT : button=KEY_MLEFT; break;  
              case BFM_INPUT_MOUSERIGHT: button=KEY_MRIGHT; break;  
              default: return TRUE;  
         }  
           
         AutoAlloc<GeRayCollider> rc;  
         if (!rc) return FALSE;  
         rc->Init(opActive, TRUE);  
      
         Real     dx, dy, rad=data.GetReal(1000);  
         mDrag = FALSE;  
         BaseContainer bc, device;  
         BaseSelect *bs = ToPoint(opActive)->GetPointS(); if (!bs) return TRUE;  
         win->MouseDragStart(button,mx,my,MOUSEDRAG_DONTHIDEMOUSE|MOUSEDRAG_NOMOVE);  
         while (win->MouseDrag(&dx;,&dy;,&device;)==MOUSEDRAG_CONTINUE)  
         {  
              mx+=dx;  
              my+=dy;  
              mDrag = TRUE;  
              for(index=0; index<ptCount; index++)  
              {  
                   opt = bd->WS(opActive->GetMg() * padr[index]);  
                   opt.z = 0.0;  
                   mpt.x = mx;  
                   mpt.y = my;  
                   mpt.z = 0.0;  
                   if(Len(opt - mpt) < rad)  
                   {  
                        if(data.GetBool(1001))  
                        {  
                             rayEnd = bd->SW(Vector(mx,my,0));  
                             rayStart = bd->SW(Vector(mx,my,10000.0));  
                             rayDir = !opActive->GetMg() * (rayEnd - rayStart);  
                             rayPt = padr[index] + !rayDir*0.1;  
                             if(!rc->Intersect(rayPt, !rayDir, 10000.0))  
                             {  
                                  bs->Select(index);  
                             }  
                        }  
                        else  
                        {  
                             bs->Select(index);  
                        }  
                   }  
              }  
              DrawViews(DA_ONLY_ACTIVE_VIEW|DA_NO_THREAD|DA_NO_ANIMATION);  
         }  
         mDrag = FALSE;  
         DrawViews(DA_ONLY_ACTIVE_VIEW|DA_NO_THREAD|DA_NO_ANIMATION);  
      
         return TRUE;  
    }
    

    I'm not sure exactly what's wrong. Any ideas?

    Adios,
    Cactus Dan



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

    On 22/10/2005 at 01:30, xxxxxxxx wrote:

    the ray direction should be transformed like
    rayDir = !mg ^ ( rayEnd - rayStart )
    this omits the translation part.

    This could be the problem.. otherwise it looks fine to me.



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

    On 22/10/2005 at 08:10, xxxxxxxx wrote:

    Howdy,

    Hmmm, It's still not working right. I changed the line to this:
    rayDir = (rayEnd - rayStart) ^ !opActive->GetMg();
    because CodeWarrior gave me an error with the matrix on the left side of the XOR operator.

    But I did notice the radius setting of the tool makes a difference. If I set the radius of the tool to 5 or less there's no problem. The higher I set the radius the more points from underneath are selected:

    I wonder if it's because the rays are being shot from the point but parallel to the ray shot from (mx, my, 10000) to (mx, my, 0), and it's missing the collision. Maybe it would be better to shoot the ray from the point to the (mx, my, 0) instead of shooting the ray from (mx, my, 10000) to (mx, my, 0)?

    I'll see if that works.

    Adios,
    Cactus Dan



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

    On 22/10/2005 at 08:26, xxxxxxxx wrote:

    Howdy,

    AHA!!!! That's it! That was the problem. The ray was being shot parallel to the ray shot from the mouses position. I changed these lines:

    rayEnd = bd->SW(Vector(mx,my,0));
    rayStart = bd->SW(Vector(mx,my,10000.0));

    to this:

    rayEnd = bd->SW(opt);
    rayStart = opActive->GetMg() * padr[index];

    Now the ray is being shot from the point's world position to the point's screen position, and it works beautifully!

    Adios,
    Cactus Dan


Log in to reply