Hello. I am the author of the irrBullet wrapper for Irrlicht. Bullet is a great physics library!
I have one problem. My raycast vehicles work fine until I add collision filters to the objects in the the simulation world. Then it simply stops contacts and acts as if the vehicle's wheel don't even exist.
I have the filters so that the vehicle collides with terrain, and the terrain collides with vehicles, so why wouldn't the raycast vehicle work at all? I've looked through the source files of the raycast vehicle but can't find any mention of filters, so it must be in the rigid body or collision object's code.
An answer to this would be great! Thanks.
- Josiah
Why do raycast vehicles not work with collision filters?
-
- Posts: 6
- Joined: Wed Apr 29, 2009 11:45 pm
-
- Posts: 6
- Joined: Wed Apr 29, 2009 11:45 pm
Re: Why do raycast vehicles not work with collision filters?
Any ideas? I can't figure out why such a strange problem happens.
-
- Posts: 456
- Joined: Tue Dec 25, 2007 1:06 pm
Re: Why do raycast vehicles not work with collision filters?
First of all, I've never tried to use raycast vehicles + collision masks myself.Cobra wrote:I have the filters so that the vehicle collides with terrain, and the terrain collides with vehicles, so why wouldn't the raycast vehicle work at all? I've looked through the source files of the raycast vehicle but can't find any mention of filters, so it must be in the rigid body or collision object's code.
Anyway I believe that raycasts can be done with collision masks themselves in this way (note: this is a generic raycast, not specific to raycast vehicles; also this code is a bit old, I hope it works):
Code: Select all
btCollisionWorld::ClosestRayResultCallback rayCallback(rayFrom,rayTo);
m_dynamicsWorld->rayTest(rayFrom,rayTo,rayCallback);
rayCallback.m_collisionFilterMask = btBroadphaseProxy::AllFilter & ~btBroadphaseProxy::SensorTrigger;
if (rayCallback.hasHit())
{
btRigidBody* body = btRigidBody::upcast(rayCallback.m_collisionObject);
[...]
}
Code: Select all
rayCallback.m_collisionFilterMask = btBroadphaseProxy::AllFilter & ~btBroadphaseProxy::SensorTrigger;
Hope it helps.
-
- Posts: 6
- Joined: Wed Apr 29, 2009 11:45 pm
Re: Why do raycast vehicles not work with collision filters?
Ah, I see. I really appreciate your reply. If I would have looked a little harder, I would have seen that I can derive my own class from btVehicleRaycaster and used that with the raycast vehicle.
I fixed it using this:
I fixed it using this:
Code: Select all
void* IVehicleRaycaster::castRay(const btVector3& from,const btVector3& to, btVehicleRaycasterResult& result)
{
btCollisionWorld::ClosestRayResultCallback rayCallback(from,to);
if(useFilter)
{
rayCallback.m_collisionFilterMask = collisionFilterMask;
rayCallback.m_collisionFilterGroup = collisionFilterGroup;
}
m_dynamicsWorld->rayTest(from, to, rayCallback);
if (rayCallback.hasHit())
{
btRigidBody* body = btRigidBody::upcast(rayCallback.m_collisionObject);
if (body && body->hasContactResponse())
{
result.m_hitPointInWorld = rayCallback.m_hitPointWorld;
result.m_hitNormalInWorld = rayCallback.m_hitNormalWorld;
result.m_hitNormalInWorld.normalize();
result.m_distFraction = rayCallback.m_closestHitFraction;
return body;
}
}
return 0;
}