diff options
Diffstat (limited to 'extern/bullet/Extras/PhysicsInterface/CcdPhysics/CcdPhysicsEnvironment.cpp')
-rw-r--r-- | extern/bullet/Extras/PhysicsInterface/CcdPhysics/CcdPhysicsEnvironment.cpp | 123 |
1 files changed, 40 insertions, 83 deletions
diff --git a/extern/bullet/Extras/PhysicsInterface/CcdPhysics/CcdPhysicsEnvironment.cpp b/extern/bullet/Extras/PhysicsInterface/CcdPhysics/CcdPhysicsEnvironment.cpp index 5c117301ffb..b68e730b4c6 100644 --- a/extern/bullet/Extras/PhysicsInterface/CcdPhysics/CcdPhysicsEnvironment.cpp +++ b/extern/bullet/Extras/PhysicsInterface/CcdPhysics/CcdPhysicsEnvironment.cpp @@ -717,89 +717,7 @@ void CcdPhysicsEnvironment::setGravity(float x,float y,float z) } } -#ifdef DASHDASJKHASDJK -class RaycastingQueryBox : public QueryBox -{ - - SimdVector3 m_aabbMin; - - SimdVector3 m_aabbMax; - - - -public: - - RaycastCallback m_raycastCallback; - - - RaycastingQueryBox(QueryBoxConstructionInfo& ci,const SimdVector3& from,const SimdVector3& to) - : QueryBox(ci), - m_raycastCallback(from,to) - { - for (int i=0;i<3;i++) - { - float fromI = from[i]; - float toI = to[i]; - if (fromI < toI) - { - m_aabbMin[i] = fromI; - m_aabbMax[i] = toI; - } else - { - m_aabbMin[i] = toI; - m_aabbMax[i] = fromI; - } - } - - } - virtual void AddCollider( BroadphaseProxy* proxy) - { - //perform raycast if wanted, and update the m_hitFraction - - if (proxy->GetClientObjectType() == TRIANGLE_MESH_SHAPE_PROXYTYPE) - { - //do it - RigidBody* body = (RigidBody*)proxy->m_clientObject; - TriangleMeshInterface* meshInterface = (TriangleMeshInterface*) - body->m_minkowski1; - - //if the hit is closer, record the proxy! - float curFraction = m_raycastCallback.m_hitFraction; - - meshInterface->ProcessAllTriangles(&m_raycastCallback,m_aabbMin,m_aabbMax); - - if (m_raycastCallback.m_hitFraction < curFraction) - { - m_raycastCallback.m_hitProxy = proxy; - } - - } - - } -}; -struct InternalVehicleRaycaster : public VehicleRaycaster -{ - - CcdPhysicsEnvironment* m_env; - -public: - - InternalVehicleRaycaster(CcdPhysicsEnvironment* env) - : m_env(env) - { - - } - - virtual void* CastRay(const SimdVector3& from,const SimdVector3& to, VehicleRaycasterResult& result) - { - - return 0; - } - -}; - -#endif int CcdPhysicsEnvironment::createConstraint(class PHY_IPhysicsController* ctrl0,class PHY_IPhysicsController* ctrl1,PHY_ConstraintType type, float pivotX,float pivotY,float pivotZ, float axisX,float axisY,float axisZ) @@ -869,7 +787,7 @@ PHY_IPhysicsController* CcdPhysicsEnvironment::rayTest(PHY_IPhysicsController* i float& hitX,float& hitY,float& hitZ,float& normalX,float& normalY,float& normalZ) { - int minFraction = 1.f; + float minFraction = 1.f; SimdTransform rayFromTrans,rayToTrans; rayFromTrans.setIdentity(); @@ -899,12 +817,15 @@ PHY_IPhysicsController* CcdPhysicsEnvironment::rayTest(PHY_IPhysicsController* i ConvexShape* convexShape = (ConvexShape*) body->GetCollisionShape(); VoronoiSimplexSolver simplexSolver; SubsimplexConvexCast convexCaster(&pointShape,convexShape,&simplexSolver); + if (convexCaster.calcTimeOfImpact(rayFromTrans,rayToTrans,body->getCenterOfMassTransform(),body->getCenterOfMassTransform(),rayResult)) { //add hit rayResult.m_normal.normalize(); if (rayResult.m_fraction < minFraction) { + + minFraction = rayResult.m_fraction; nearestHit = ctrl; normalX = rayResult.m_normal.getX(); @@ -916,6 +837,42 @@ PHY_IPhysicsController* CcdPhysicsEnvironment::rayTest(PHY_IPhysicsController* i } } } + else + { + if (body->GetCollisionShape()->IsConcave()) + { + + TriangleMeshShape* triangleMesh = (TriangleMeshShape*)body->GetCollisionShape(); + + SimdTransform worldToBody = body->getCenterOfMassTransform().inverse(); + + SimdVector3 rayFromLocal = worldToBody * rayFromTrans.getOrigin(); + SimdVector3 rayToLocal = worldToBody * rayToTrans.getOrigin(); + + RaycastCallback rcb(rayFromLocal,rayToLocal); + rcb.m_hitFraction = minFraction; + + SimdVector3 aabbMax(1e30f,1e30f,1e30f); + + triangleMesh->ProcessAllTriangles(&rcb,-aabbMax,aabbMax); + if (rcb.m_hitFound)// && (rcb.m_hitFraction < minFraction)) + { + nearestHit = ctrl; + minFraction = rcb.m_hitFraction; + SimdVector3 hitNormalWorld = body->getCenterOfMassTransform()(rcb.m_hitNormalLocal); + + normalX = hitNormalWorld.getX(); + normalY = hitNormalWorld.getY(); + normalZ = hitNormalWorld.getZ(); + SimdVector3 hitWorld; + hitWorld.setInterpolate3(rayFromTrans.getOrigin(),rayToTrans.getOrigin(),rcb.m_hitFraction); + hitX = hitWorld.getX(); + hitY = hitWorld.getY(); + hitZ = hitWorld.getZ(); + + } + } + } } return nearestHit; |