浏览代码

Fixed bullet collision callback - my bad.

Mark Sibly 7 年之前
父节点
当前提交
c1145fea9b
共有 1 个文件被更改,包括 16 次插入7 次删除
  1. 16 7
      modules/mojo3d/scene/native/collisiondetect.cpp

+ 16 - 7
modules/mojo3d/scene/native/collisiondetect.cpp

@@ -14,15 +14,24 @@ void collisionCallback( btDynamicsWorld *world,btScalar timeStep ){
 	
 	
 	for( int i=0;i<numManifolds;++i ){
 	for( int i=0;i<numManifolds;++i ){
 
 
-		btPersistentManifold *manifold=world->getDispatcher()->getManifoldByIndexInternal( i );
+		btPersistentManifold *contactManifold=world->getDispatcher()->getManifoldByIndexInternal( i );
         
         
-		const btCollisionObject *body0=manifold->getBody0();
-		const btCollisionObject *body1=manifold->getBody1();
-       
-//		printf( "Collision! body0=%p body1=%p\n",body0,body1 );fflush( stdout );
+		const btCollisionObject *body0=contactManifold->getBody0();
+		const btCollisionObject *body1=contactManifold->getBody1();
 		
 		
-		*_collp++=body0->getUserPointer();
-		*_collp++=body1->getUserPointer();
+        int numContacts=contactManifold->getNumContacts();
+        
+        for( int j=0;j<numContacts;++j ){
+        
+            btManifoldPoint &pt=contactManifold->getContactPoint(j);
+            
+            if( pt.getDistance()<0.0f ){
+	            
+				*_collp++=body0->getUserPointer();
+				*_collp++=body1->getUserPointer();
+				break;
+			}
+        }
 	}
 	}
 }
 }