diff trunk/chipmunkd/cpArbiter.d @ 23:4ceef5833c8c

updated to chipmunk 5.3.3
author Extrawurst
date Fri, 10 Dec 2010 02:10:27 +0100
parents df4ebc8add66
children 4541ca17975b
line wrap: on
line diff
--- a/trunk/chipmunkd/cpArbiter.d	Thu Dec 09 22:25:04 2010 +0100
+++ b/trunk/chipmunkd/cpArbiter.d	Fri Dec 10 02:10:27 2010 +0100
@@ -37,6 +37,8 @@
 //cpVect cpContactsSumImpulses(cpContact *contacts, int numContacts);
 //cpVect cpContactsSumImpulsesWithFriction(cpContact *contacts, int numContacts);
 
+enum CP_MAX_CONTACTS_PER_ARBITER = 6;
+
 enum cpArbiterState {
 	cpArbiterStateNormal,
 	cpArbiterStateFirstColl,
@@ -55,8 +57,8 @@
 	// These variables are NOT in the order defined by the collision handler.
 	// Using CP_ARBITER_GET_SHAPES and CP_ARBITER_GET_BODIES will save you from
 	// many headaches
-	cpShape* private_a;
-	cpShape* private_b;
+	cpShape* a;
+	cpShape* b;
 	
 	// Calculated before calling the pre-solve collision handler
 	// Override them with custom values if you want specialized behavior
@@ -97,9 +99,9 @@
 cpArbiterGetShapes(/+const+/ cpArbiter *arb, cpShape **a, cpShape **b)
 {
 	if(arb.swappedColl){
-		(*a) = arb.private_b, (*b) = arb.private_a;
+		(*a) = arb.b, (*b) = arb.a;
 	} else {
-		(*a) = arb.private_a, (*b) = arb.private_b;
+		(*a) = arb.a, (*b) = arb.b;
 	}
 }
 
@@ -125,6 +127,12 @@
 	return arb.state == cpArbiterState.cpArbiterStateFirstColl;
 }
 
+static int
+cpArbiterGetCount(const cpArbiter *arb)
+{
+	return arb.numContacts;
+}
+
 static cpVect
 cpArbiterGetNormal(const cpArbiter *arb, int i)
 {
@@ -138,6 +146,43 @@
 	return arb.contacts[i].p;
 }
 
+
+static cpFloat 
+cpArbiteGetDepth(const cpArbiter *arb, int i)
+{
+	return arb.contacts[i].dist;
+}
+
+struct cpContactPointSet {
+	int count;
+	
+	struct TPoint
+	{
+		cpVect point, normal;
+		cpFloat dist = 0;
+	}
+	
+	TPoint[CP_MAX_CONTACTS_PER_ARBITER] points;
+}
+
+static cpContactPointSet
+cpArbiterGetContactPointSet(const cpArbiter *arb)
+{
+	cpContactPointSet set;
+	set.count = cpArbiterGetCount(arb);
+	
+	int i;
+	for(i=0; i<set.count; i++){
+		set.points[i].point = arb.contacts[i].p;
+		set.points[i].normal = arb.contacts[i].p;
+		set.points[i].dist = arb.contacts[i].dist;
+	}
+	
+	return set;
+}
+
+// cpArbiter.c --------------------------
+
 cpFloat cp_bias_coef = 0.1f;
 cpFloat cp_collision_slop = 0.1f;
 
@@ -218,11 +263,18 @@
 cpArbiter*
 cpArbiterInit(cpArbiter *arb, cpShape *a, cpShape *b)
 {
+	arb.handler = null;
+	arb.swappedColl = cpFalse;
+	   
+	arb.e = 0.0f;
+	arb.u = 0.0f;
+	arb.surface_vr = cpvzero;
+	
 	arb.numContacts = 0;
 	arb.contacts = null;
 	
-	arb.private_a = a;
-	arb.private_b = b;
+	arb.a = a;
+	arb.b = b;
 	
 	arb.stamp = 0;
 	arb.state = cpArbiterState.cpArbiterStateFirstColl;
@@ -271,8 +323,6 @@
 				}
 			}
 		}
-
-//		cpfree(arb.contacts);
 	}
 	
 	arb.contacts = contacts;
@@ -286,8 +336,8 @@
 	arb.surface_vr = cpvsub(a.surface_v, b.surface_v);
 	
 	// For collisions between two similar primitive types, the order could have been swapped.
-	arb.private_a = a;
-	arb.private_b = b;
+	arb.a = a;
+	arb.b = b;
 	
 	// mark it as new if it's been cached
 	if(arb.state == cpArbiterState.cpArbiterStateCached) arb.state = cpArbiterState.cpArbiterStateFirstColl;
@@ -296,8 +346,8 @@
 void
 cpArbiterPreStep(cpArbiter *arb, cpFloat dt_inv)
 {
-	cpBody *a = arb.private_a._body;
-	cpBody *b = arb.private_b._body;
+	cpBody *a = arb.a._body;
+	cpBody *b = arb.b._body;
 	
 	for(int i=0; i<arb.numContacts; i++){
 		cpContact *con = &arb.contacts[i];
@@ -322,8 +372,8 @@
 void
 cpArbiterApplyCachedImpulse(cpArbiter *arb)
 {
-	cpShape *shapea = arb.private_a;
-	cpShape *shapeb = arb.private_b;
+	cpShape *shapea = arb.a;
+	cpShape *shapeb = arb.b;
 		
 	arb.u = shapea.u * shapeb.u;
 	arb.surface_vr = cpvsub(shapeb.surface_v, shapea.surface_v);
@@ -340,8 +390,8 @@
 void
 cpArbiterApplyImpulse(cpArbiter *arb, cpFloat eCoef)
 {
-	cpBody *a = arb.private_a._body;
-	cpBody *b = arb.private_b._body;
+	cpBody *a = arb.a._body;
+	cpBody *b = arb.b._body;
 
 	for(int i=0; i<arb.numContacts; i++){
 		cpContact *con = &arb.contacts[i];