Fix T38895: Unstable behavior using VehicleWrapper after Bullet 2.82 update

The Bullet 2.82 update uses a different method for ray casting that
seems incompatible with our older files. So, for now we just force the
vehicle physics to use the older ray casting method.
This commit is contained in:
Mitchell Stokes 2014-05-16 10:40:23 -07:00
parent 1923a8f23a
commit 2e20c16897
Notes: blender-bot 2023-02-14 11:06:09 +01:00
Referenced by issue #40234, Sculpt models take a long time to select on wire frame mode.
Referenced by issue #38895, Unstable behavior using VehicleWrapper in blender 2.70 test build
1 changed files with 39 additions and 1 deletions

View File

@ -295,6 +295,44 @@ public:
};
class BlenderVehicleRaycaster: public btDefaultVehicleRaycaster
{
btDynamicsWorld* m_dynamicsWorld;
public:
BlenderVehicleRaycaster(btDynamicsWorld* world)
:btDefaultVehicleRaycaster(world), m_dynamicsWorld(world)
{
}
virtual void* castRay(const btVector3& from,const btVector3& to, btVehicleRaycasterResult& result)
{
// RayResultCallback& resultCallback;
btCollisionWorld::ClosestRayResultCallback rayCallback(from,to);
// We override btDefaultVehicleRaycaster so we can set this flag, otherwise our
// vehicles go crazy (http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=9662)
rayCallback.m_flags |= btTriangleRaycastCallback::kF_UseSubSimplexConvexCastRaytest;
m_dynamicsWorld->rayTest(from, to, rayCallback);
if (rayCallback.hasHit())
{
const 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 (void*)body;
}
}
return 0;
}
};
#endif //NEW_BULLET_VEHICLE_SUPPORT
@ -2824,7 +2862,7 @@ int CcdPhysicsEnvironment::CreateConstraint(class PHY_IPhysicsController* ctrl
{
btRaycastVehicle::btVehicleTuning* tuning = new btRaycastVehicle::btVehicleTuning();
btRigidBody* chassis = rb0;
btDefaultVehicleRaycaster* raycaster = new btDefaultVehicleRaycaster(m_dynamicsWorld);
btDefaultVehicleRaycaster* raycaster = new BlenderVehicleRaycaster(m_dynamicsWorld);
btRaycastVehicle* vehicle = new btRaycastVehicle(*tuning,chassis,raycaster);
WrapperVehicle* wrapperVehicle = new WrapperVehicle(vehicle,ctrl0);
m_wrapperVehicles.push_back(wrapperVehicle);