Easy question about Ray Test

william
Posts: 3
Joined: Tue Sep 15, 2009 4:12 pm

Easy question about Ray Test

Post by william »

Hi I'm new with bullet, I started to play around with ray testing and such. I tried to get collisions between a ray and the objects in the world this way:

Code: Select all

btCollisionWorld::ClosestRayResultCallback ray( from, to );
Its working allright, but I need to know what objects have been hit by the ray. How can I do this?
william
Posts: 3
Joined: Tue Sep 15, 2009 4:12 pm

Re: Easy question about Ray Test

Post by william »

No one knows?
Nacho
Posts: 31
Joined: Tue Mar 04, 2008 1:41 pm

Re: Easy question about Ray Test

Post by Nacho »

In btCollisionWorld::ClosestRayResultCallback there is a member called m_collisionObject (really is member of RayResultCallback class). It tells you the collide object.

Code: Select all

btCollisionObject* pColObject=ray.m_collisionObject;
When you get it, you would want know if it is a rigid body, a ghost...:

Code: Select all

if( pColObject->getInternalType()==btCollisionObject::CO_RIGID_BODY)
{
    btRigidBody* pRigidBody=static_cast<btRigidBody*>(pColObject);
}
else if( pColObject->getInternalType()==btCollisionObject::CO_GHOST_OBJECT)
{
    btGhostObject* pGhost=static_cast<btGhostObject*>(pColObject);
}
Nacho.
william
Posts: 3
Joined: Tue Sep 15, 2009 4:12 pm

Re: Easy question about Ray Test

Post by william »

Thank you very much :)