GeRayCollider again



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

    On 14/08/2006 at 02:42, xxxxxxxx wrote:

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

    ---------
    Hi,

    I already read all the topics concerning geRayCollider but I can't get my code working. The goal is very easy: I have two objects and I want to send a ray to find the nearest point of ojb2 from the originof obj1. So, I did it like that (I adapted a code I found in this forum) :

    AutoAlloc<GeRayCollider> rc;
    if (!rc) return FALSE;
    if(rc->Init(obj2, TRUE))
    {
         Matrix obj1Mat = obj1->GetMg();
         Matrix obj2Mat = obj2->GetMg();
         Matrix invertObj2Mat = !obj2Mat;
         Vector wtail = obj1Mat.off;
         Vector whead = obj2Mat.off;
         Vector otail = invertObj2Mat * wtail;
         Vector oray = (whead-wtail) ^ invertObj2Mat;

    if(rc->Intersect(otail, !oray, 1000000.0))
         {
              GeRayColResult res;
              if (rc->GetNearestIntersection(&res;))
              {
                   GePrint("Collided");
              }
         }
    }
    I call this in the method MouseInput of a ToolData plugin, it is just a test.

    I did something wrong but I can't find what. The both vector otail and oray are correct and in obj2 coordinates. What I don't understand is the call of Intersect with !oray. I tried also without inverting but it doesn't work better... Well if someone has an idea...

    Thanks in advance.

    Vincent



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

    On 15/08/2006 at 01:23, xxxxxxxx wrote:

    Hi,

    the "!" operator returns a vector of unit length and lets the direction unchanged.

    Beside that, you say that you want to find the nearest point of obj2. This code doesn't really do that. It could even be that the origins are located way off the actual object center.

    If you are sure that there should be an intersection point.. i'm sorry, i can't tell you what's wrong. It looks pretty okay to me.


Log in to reply