Raycast filter collisionID

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Raycast filter collisionID

Postby Nitrogenycs » Fri Feb 20, 2009 9:50 am

Hey,

my raycast filter callback looks like this

Code: Select all
static dFloat raycastFilter(const NewtonBody* body, const dFloat* hitNormal, int collisionID, void* userData, dFloat intersectParam)
{
      // I want to get the NewtonCollision* here, how to do that?
}


I tried with code like

Code: Select all
// setting up the collision
NewtonCollisionSetUserID( myCollision, reinterpret_cast<int>( this ) );

static dFloat raycastFilter(const NewtonBody* body, const dFloat* hitNormal, int collisionID, void* userData, dFloat intersectParam)
{
     MyCollision* myCollision = reinterpret_cast< MyCollision* >( collisionID );
}


but this does not work, because collisionID seems to be the face number (I'm trying a tree collision). My prefilter looks like this and it works:

Code: Select all
// setting up the collision
NewtonCollisionSetUserID( myCollision, reinterpret_cast<int>( this ) );

static uint raycastPrefilter(const NewtonBody* body, const NewtonCollision* collision, void* userData)
{
   MyCollision* myCollision = reinterpret_cast< MyCollision* >( NewtonCollisionGetUserID(collision) );
}


Any suggestions how to get the NewtonCollision* from inside the raycastFilter?

If it is not possible right now I suggest to add a NewtonCollision* to the raycast filter callback. I also suggest to add two functions like NewtonCollisionSetUserData and NewtonCollisionGetUserData, analogous to NewtonBodySetUserData and NewtonBodyGetUserData.

-Matthias
Nitrogenycs
 
Posts: 12
Joined: Fri Apr 07, 2006 4:45 am

Re: Raycast filter collisionID

Postby agi_shi » Fri Feb 20, 2009 10:18 am

Just use NewtonBodyGetCollision().
agi_shi
 
Posts: 263
Joined: Fri Aug 17, 2007 6:54 pm

Re: Raycast filter collisionID

Postby Nitrogenycs » Fri Feb 20, 2009 11:08 am

No, this doesn't work in the case of compound collisions.
Nitrogenycs
 
Posts: 12
Joined: Fri Apr 07, 2006 4:45 am

Re: Raycast filter collisionID

Postby Julio Jerez » Fri Feb 20, 2009 11:33 am

to get info form cmpund collison you nee to set the compoudn collison callbacks.
then it will report detail infomation of each of the shapes.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Raycast filter collisionID

Postby Nitrogenycs » Fri Feb 20, 2009 12:58 pm

Hmmm, do you mean using NewtonMaterialSetCollisionCallback ? How does this interact with ray casting? Or do you mean a different function? Looked all over the Newton.h header, but nothing striking there...

What I want the raycast to do is give me the NewtonCollision* which intersected the ray. E.g. if I have a body consisting of an upper part and a lower part and both are in a compound geometry I want to be able to tell whether the ray intersected with the upper or the lower geometry. Right now I only know it collides with the compound geometry (can get that compound collision with NewtonBodyGetCollision).
I am quite sure Newton knows the exact NewtonCollision with which the ray intersects. If it didn't know, it couldn't calculate the point of intersection.So it seems as if Newton could just pass that NewtonCollision into the filter callback.
It's useful to know the exact collision, because sometimes I want to do different things depending which exact geometry was hit.
Nitrogenycs
 
Posts: 12
Joined: Fri Apr 07, 2006 4:45 am

Re: Raycast filter collisionID

Postby Julio Jerez » Fri Feb 20, 2009 1:29 pm

Um I do not find it, I knwo it is there but I will have to see tonight.

The ID is not a pointer it the a user ID to set into the shape using thei sfuntion
void NewtonCollisionSetUserID (const NewtonCollision* convexCollision, unsigned id);

for example a collision mesh is and array of Polygonal shape teh matrial ID is tha value.
in you case say you are making a cmplound collision of a box and a sphere
you can do this:

Code: Select all
// this will detach the ref count from for the world, and the shape will no be shared and you can add local information to teh shape.
NewtonCollisionMakeUnique (newtonWorld,  box);
NewtonCollisionMakeUnique (newtonWorld,  spheer);
...

// add user ID to each shpe of the compound partd
NewtonCollisionSetUserID (box, id0);
NewtonCollisionSetUserID (sphere, id0);
..

// make compound colliosion
...



then in you call back

Code: Select all
static dFloat raycastFilter(const NewtonBody* body, const dFloat* hitNormal, int collisionID, void* userData, dFloat intersectParam)
{
      // I want to get the NewtonCollision* here, how to do that?

     collision = NewtonBodyGetCollision();

    //check tah this si teh compund shape.
     NewtonCollisionInfoRecord collisionInfo;
     NewtonCollisionGetInfo (collision, NewtonCollisionInfoRecord* collisionInfo);
     if (collisionInfo.m_collisionType == SERIALIZE_ID_COMPOUND) {
     }

    switch ( collisionInfo.m_collisionType)
   {
         case SERIALIZE_ID_COMPOUND:
        {

             int count =  collisionInfo.m_chidrenCount
            for (int i = 0 i < count; i ++) {
                   if (NewtonCollisionGetUserID (m_chidren[i]) == collisionID) {
                             // found my subshape
                             // do what ever you want
                    }
             }
                 
           // othe cases here
           case: ANY_OTHR_CASE
        }
   }

}
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 18 guests

cron