getting collided triangle in btBvhTriangleMeshShape

DoMeN
Posts: 2
Joined: Tue May 04, 2010 6:33 am

getting collided triangle in btBvhTriangleMeshShape

Post by DoMeN »

Hy.

I'm new to Bullet and I was wondering if it's possible to assign custom data pointer to every triangle in a btBvhTriangleMeshShape and then when using btCollisionWorld::ClosestRayResultCallback to ray test I'd like to get the triangle that was hit and use the custom data pointer stored in it?

If the part wit custom data pointer isn't possible, is there at least any way of getting the material data of the triangle that was collided with the btCollisionWorld::ClosestRayResultCallback ray?

The code that I'm currently using to determine if an object was hit is:

Code: Select all

btCollisionWorld::ClosestRayResultCallback ray_callback(ray_from,ray_to);
    p_dynamics_world->rayTest(ray_from,ray_to,ray_callback); // btDiscreteDynamicsWorld
    if(ray_callback.hasHit())
    {
        btRigidBody* body = btRigidBody::upcast(ray_callback.m_collisionObject);
        if(body)
        {
           /// get custom data pointer stored inside rigid body and handle the event
        }
    }
I'd like to expend it's functionality to get the collided triangle if the btRigidBody has collision shape of type btBvhTriangleMeshShape like described in the questions above.

Regards,
Domen
sparkprime
Posts: 508
Joined: Fri May 30, 2008 2:51 am
Location: Ossining, New York

Re: getting collided triangle in btBvhTriangleMeshShape

Post by sparkprime »

What I do is keep an array on the side for this -- you can get the triangle index and then look up in your own array. I think slicing user data into the shape datastructure might be a little bad for performance in the non-colliding case, depending on how sensitive it is to cache locality and/or alignment.
DoMeN
Posts: 2
Joined: Tue May 04, 2010 6:33 am

Re: getting collided triangle in btBvhTriangleMeshShape

Post by DoMeN »

What I do is keep an array on the side for this -- you can get the triangle index and then look up in your own array.
I thought about that aswell but don't know how to get the index of a triangle that was hit. Could you please write the name of the function that I have to call to get it?

Thanks,
Domen
sparkprime
Posts: 508
Joined: Fri May 30, 2008 2:51 am
Location: Ossining, New York

Re: getting collided triangle in btBvhTriangleMeshShape

Post by sparkprime »

It's a parameter of your ray callback function