- Timestamp:
- Oct 20, 2008, 5:40:38 PM (16 years ago)
- Location:
- code/branches/physics/src/bullet/BulletCollision/CollisionDispatch
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/physics/src/bullet/BulletCollision/CollisionDispatch/btCollisionObject.h
r1963 r1972 238 238 239 239 240 SIMD_FORCE_INLINEbtBroadphaseProxy* getBroadphaseHandle()240 btBroadphaseProxy* getBroadphaseHandle() 241 241 { 242 242 return m_broadphaseHandle; 243 243 } 244 244 245 SIMD_FORCE_INLINEconst btBroadphaseProxy* getBroadphaseHandle() const245 const btBroadphaseProxy* getBroadphaseHandle() const 246 246 { 247 247 return m_broadphaseHandle; -
code/branches/physics/src/bullet/BulletCollision/CollisionDispatch/btCollisionWorld.cpp
r1963 r1972 33 33 #include "LinearMath/btStackAlloc.h" 34 34 35 //#define USE_BRUTEFORCE_RAYBROADPHASE 136 //RECALCULATE_AABB is slower, but benefit is that you don't need to call 'stepSimulation' or 'updateAabbs' before using a rayTest37 //#define RECALCULATE_AABB_RAYCAST 138 35 39 36 //When the user doesn't provide dispatcher or broadphase, create basic versions (and delete them in destructor) … … 230 227 if (collisionShape->isConvex()) 231 228 { 232 BT_PROFILE("rayTestConvex");233 229 btConvexCast::CastResult castResult; 234 230 castResult.m_fraction = resultCallback.m_closestHitFraction; … … 274 270 if (collisionShape->isConcave()) 275 271 { 276 BT_PROFILE("rayTestConcave");277 272 if (collisionShape->getShapeType()==TRIANGLE_MESH_SHAPE_PROXYTYPE) 278 273 { … … 380 375 } 381 376 } else { 382 BT_PROFILE("rayTestCompound");383 377 //todo: use AABB tree or other BVH acceleration structure! 384 378 if (collisionShape->isCompound()) … … 603 597 } 604 598 605 606 struct btSingleRayCallback : public btBroadphaseRayCallback 607 { 608 609 btVector3 m_rayFromWorld; 610 btVector3 m_rayToWorld; 611 const btCollisionWorld* m_world; 612 btCollisionWorld::RayResultCallback& m_resultCallback; 613 614 btSingleRayCallback(const btVector3& rayFromWorld,const btVector3& rayToWorld,const btCollisionWorld* world,btCollisionWorld::RayResultCallback& resultCallback) 615 :m_rayFromWorld(rayFromWorld), 616 m_rayToWorld(rayToWorld), 617 m_world(world), 618 m_resultCallback(resultCallback) 619 { 620 621 } 622 623 virtual bool process(const btBroadphaseProxy* proxy) 599 void btCollisionWorld::rayTest(const btVector3& rayFromWorld, const btVector3& rayToWorld, RayResultCallback& resultCallback) const 600 { 601 602 603 btTransform rayFromTrans,rayToTrans; 604 rayFromTrans.setIdentity(); 605 rayFromTrans.setOrigin(rayFromWorld); 606 rayToTrans.setIdentity(); 607 608 rayToTrans.setOrigin(rayToWorld); 609 610 /// go over all objects, and if the ray intersects their aabb, do a ray-shape query using convexCaster (CCD) 611 612 int i; 613 for (i=0;i<m_collisionObjects.size();i++) 624 614 { 625 615 ///terminate further ray tests, once the closestHitFraction reached zero 626 if (m_resultCallback.m_closestHitFraction == btScalar(0.f)) 627 return false; 628 629 btCollisionObject* collisionObject = (btCollisionObject*)proxy->m_clientObject; 630 616 if (resultCallback.m_closestHitFraction == btScalar(0.f)) 617 break; 618 619 btCollisionObject* collisionObject= m_collisionObjects[i]; 631 620 //only perform raycast if filterMask matches 632 if(m_resultCallback.needsCollision(collisionObject->getBroadphaseHandle())) 633 { 621 if(resultCallback.needsCollision(collisionObject->getBroadphaseHandle())) { 634 622 //RigidcollisionObject* collisionObject = ctrl->GetRigidcollisionObject(); 635 //btVector3 collisionObjectAabbMin,collisionObjectAabbMax;636 637 #ifdef RECALCULATE_AABB638 623 btVector3 collisionObjectAabbMin,collisionObjectAabbMax; 639 624 collisionObject->getCollisionShape()->getAabb(collisionObject->getWorldTransform(),collisionObjectAabbMin,collisionObjectAabbMax); 640 #else 641 //getBroadphase()->getAabb(collisionObject->getBroadphaseHandle(),collisionObjectAabbMin,collisionObjectAabbMax); 642 btVector3& collisionObjectAabbMin = collisionObject->getBroadphaseHandle()->m_aabbMin; 643 btVector3& collisionObjectAabbMax = collisionObject->getBroadphaseHandle()->m_aabbMax; 644 #endif 645 btScalar hitLambda = m_resultCallback.m_closestHitFraction; 625 626 btScalar hitLambda = resultCallback.m_closestHitFraction; 646 627 btVector3 hitNormal; 647 if (btRayAabb(m_rayFromWorld,m_rayToWorld,collisionObjectAabbMin,collisionObjectAabbMax,hitLambda,hitNormal)) 648 { 649 btTransform rayFromTrans,rayToTrans; 650 rayFromTrans.setIdentity(); 651 rayFromTrans.setOrigin(m_rayFromWorld); 652 rayToTrans.setIdentity(); 653 rayToTrans.setOrigin(m_rayToWorld); 654 655 m_world->rayTestSingle(rayFromTrans,rayToTrans, 628 if (btRayAabb(rayFromWorld,rayToWorld,collisionObjectAabbMin,collisionObjectAabbMax,hitLambda,hitNormal)) 629 { 630 rayTestSingle(rayFromTrans,rayToTrans, 656 631 collisionObject, 657 632 collisionObject->getCollisionShape(), 658 633 collisionObject->getWorldTransform(), 659 m_resultCallback); 660 } 661 } 662 return true; 663 } 664 }; 665 666 void btCollisionWorld::rayTest(const btVector3& rayFromWorld, const btVector3& rayToWorld, RayResultCallback& resultCallback) const 667 { 668 BT_PROFILE("rayTest"); 669 /// go over all objects, and if the ray intersects their aabb, do a ray-shape query using convexCaster (CCD) 670 btSingleRayCallback rayCB(rayFromWorld,rayToWorld,this,resultCallback); 671 672 #ifndef USE_BRUTEFORCE_RAYBROADPHASE 673 m_broadphasePairCache->rayTest(rayFromWorld,rayToWorld,rayCB); 674 #else 675 for (int i=0;i<this->getNumCollisionObjects();i++) 676 { 677 rayCB.process(m_collisionObjects[i]->getBroadphaseHandle()); 678 } 679 #endif //USE_BRUTEFORCE_RAYBROADPHASE 634 resultCallback); 635 } 636 } 637 638 } 680 639 681 640 } -
code/branches/physics/src/bullet/BulletCollision/CollisionDispatch/btCollisionWorld.h
r1963 r1972 108 108 } 109 109 110 const btBroadphaseInterface* getBroadphase() const111 {112 return m_broadphasePairCache;113 }114 115 110 btBroadphaseInterface* getBroadphase() 116 111 {
Note: See TracChangeset
for help on using the changeset viewer.