Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

added collision callback. untested

  • Loading branch information...
commit 960b1a0828de4ae4a1c2779a1a5a7a6521df7c0b 1 parent a35e67f
termhn authored July 02, 2011
6  Bullet Wrapping/Wrapper/CC3PhysicsWorld.h
@@ -47,9 +47,11 @@ class btCollisionShape;
47 47
     btDefaultCollisionConfiguration *collisionConfiguration;
48 48
     btSequentialImpulseConstraintSolver *solver;
49 49
     btCollisionDispatcher *dispatcher;
50  
-
  50
+    
51 51
 	NSDate * _lastStepTime;
52 52
 	NSMutableArray * _physicsObjects;
  53
+    CC3PhysicsObject3D *_collisionObject1;
  54
+    CC3PhysicsObject3D *_collisionObject2;
53 55
     
54 56
     BOOL isstatic;
55 57
 
@@ -108,4 +110,6 @@ class btCollisionShape;
108 110
  */
109 111
 - (CC3PhysicsObject3D *) createPhysicsObject:(CC3Node *)node shape:(btCollisionShape *)shape mass:(float)mass restitution:(float)restitution position:(CC3Vector)position;
110 112
 
  113
+- (void) onCollision:(CC3PhysicsObject3D *)object1 body2:(CC3PhysicsObject3D *)object2 point1:(CC3Vector)point1 point2:(CC3Vector)point2;
  114
+
111 115
 @end
40  Bullet Wrapping/Wrapper/CC3PhysicsWorld.mm
@@ -138,13 +138,51 @@ - (void) synchTransformation {
138 138
         object.node.location = CC3VectorMake(gPos.getX(), gPos.getY(), gPos.getZ());
139 139
         object.node.quaternion = quaternion;
140 140
     }
141  
-    
  141
+    int numManifolds = _discreteDynamicsWorld->getDispatcher()->getNumManifolds();
  142
+	for (int i=0;i<numManifolds;i++)
  143
+	{
  144
+        btVector3 ptA;
  145
+        btVector3 ptB;
  146
+        int objectNum = 0;
  147
+		btPersistentManifold* contactManifold =  _discreteDynamicsWorld->getDispatcher()->getManifoldByIndexInternal(i);
  148
+		btCollisionObject* obA = static_cast<btCollisionObject*>(contactManifold->getBody0());
  149
+		btCollisionObject* obB = static_cast<btCollisionObject*>(contactManifold->getBody1());
  150
+        
  151
+		int numContacts = contactManifold->getNumContacts();
  152
+		for (int j=0;j<numContacts;j++)
  153
+		{
  154
+			btManifoldPoint& pt = contactManifold->getContactPoint(j);
  155
+			if (pt.getDistance()<0.f)
  156
+			{
  157
+				ptA = pt.getPositionWorldOnA();
  158
+				ptB = pt.getPositionWorldOnB();
  159
+			}
  160
+		}
  161
+        for (CC3PhysicsObject3D *object in _physicsObjects) {
  162
+            if (object.rigidBody == obA or object.rigidBody == obB) {
  163
+                if (objectNum == 1) {
  164
+                    _collisionObject1 = object;
  165
+                    objectNum ++;
  166
+                } else {
  167
+                    _collisionObject2 = object;
  168
+                }
  169
+            }
  170
+        }
  171
+        CC3Vector cptA = cc3v(ptA.getX(), ptA.getY(), ptA.getZ());
  172
+        CC3Vector cptB = cc3v(ptB.getX(), ptB.getY(), ptB.getZ());
  173
+        [self onCollision:_collisionObject1 body2:_collisionObject2 point1:cptA point2:cptB];
  174
+	}
142 175
 }
143 176
 
144 177
 - (void) setGravity:(float)x y:(float)y z:(float)z {
145 178
 	_discreteDynamicsWorld->setGravity(btVector3(x, y, z));
146 179
 }
147 180
 
  181
+- (void) onCollision:(CC3PhysicsObject3D *)object1 body2:(CC3PhysicsObject3D *)object2 point1:(CC3Vector)point1 point2:(CC3Vector)point2
  182
+{
  183
+    
  184
+}
  185
+
148 186
 - (CC3PhysicsObject3D *) createPhysicsObject:(CC3Node *)node shape:(btCollisionShape *)shape mass:(float)mass restitution:(float)restitution position:(CC3Vector)position {
149 187
 	// Create a motion state for the object
150 188
 	btDefaultMotionState* motionState = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1), btVector3(position.x, position.y, position.z)));

0 notes on commit 960b1a0

Please sign in to comment.
Something went wrong with that request. Please try again.