commit 93fe37a61e826fb836a8a12f718f078e3b72c8b9
Author: David Martínez Martí <deavid@deavidbox.(none)>
Date:   Thu Dec 17 23:22:55 2009 +0100

    Various corrections to terrain collisions

diff --git a/soya/definitions/ode/ctype.pxd b/soya/definitions/ode/ctype.pxd
index 56b5ee6..a2a70d2 100644
--- a/soya/definitions/ode/ctype.pxd
+++ b/soya/definitions/ode/ctype.pxd
@@ -471,6 +471,7 @@ cdef extern from "ode/ode.h":
 		ctypedef dColliderFn * dGetColliderFnFn (int num)
 		ctypedef void dGeomDtorFn (dGeomID o)
 		ctypedef int dAABBTestFn (dGeomID o1, dGeomID o2, dReal aabb[6])
+		void dSetColliderOverride (int i, int j, dColliderFn *fn)
 
 		ctypedef struct dGeomClass:
 			int bytes
diff --git a/soya/init.pyx b/soya/init.pyx
index 6e1127f..e0210e1 100644
--- a/soya/init.pyx
+++ b/soya/init.pyx
@@ -363,6 +363,7 @@ SOUND_DOPPLER_FACTOR can be used to increase or decrease the Doppler effect."""
 		renderer.engine_option = renderer.engine_option | INITED
 		
 		if not root_widget is None: root_widget.resize(0, 0, width, height)
+		geomterrain_init()
 		
 		import atexit
 		atexit.register(quit)
diff --git a/soya/ode/collision.pyx b/soya/ode/collision.pyx
index 06efc87..4578ebb 100644
--- a/soya/ode/collision.pyx
+++ b/soya/ode/collision.pyx
@@ -26,9 +27,13 @@ cdef void collide_callback(void* data, dGeomID o1, dGeomID o2):
 		g2  = <object>gv2
 		contacts = collide(g1, g2)
 		if len(contacts):
-			geom = g1
-			body = geom.body
-			world = body.ode_parent
+			#print "collide_callback called (two obj collide %s, %s) and %d contacts found" % (repr(g1.body),repr(g2.body),len(contacts))
+			
+			if hasattr(g1.body,'ode_parent'):
+				world = g1.body.ode_parent
+			else:
+				world = g2.body.ode_parent
+				
 			contact_group = world._contact_group
 			if hasattr(g1.body,'hit'):
 				g1.body.hit(g2.body,contacts)
@@ -39,10 +44,10 @@ cdef void collide_callback(void* data, dGeomID o1, dGeomID o2):
 					return
 				elif not g1.body.pushable:
 					for contact in contacts:
-						contact[0]=None
+						contact.eraseGeom1()
 				elif not g2.body.pushable:
 					for contact in contacts:
-						contact[1]=None
+						contact.eraseGeom2()
 				
 			for contact in contacts:
 				#print "bouh"
@@ -74,12 +79,13 @@ def collide(_Geom geom1, _Geom geom2, int max_contacts=8):
 	cdef dContactGeom c[150]
 	cdef int i, n
 	cdef Contact cont
-	
+	cdef long nb_contact
 	if max_contacts < 1 or max_contacts > 150:
 			raise ValueError, "max_contacts must be between 1 and 150"
 	# WTH is n ?
 	nb_contact = dCollide(geom1._OdeGeomID, geom2._OdeGeomID,
 	                      max_contacts, c, sizeof(dContactGeom))
+	#print "called dCollide with 1: %d and 2: %d and got %d contacts." % (dGeomGetClass(geom1._OdeGeomID),dGeomGetClass(geom2._OdeGeomID),nb_contact)
 	res = []
 	body = geom1.body
 	if body is None:
diff --git a/soya/ode/contact.pyx b/soya/ode/contact.pyx
index 5e1be74..bdcf1c1 100644
--- a/soya/ode/contact.pyx
+++ b/soya/ode/contact.pyx
@@ -54,6 +55,13 @@ cdef class Contact:
 				self._contact.geom.g2 = gid
 			else:
 				raise IndexError("(%i) Only two body may be stored into a Contact"%index)
+		
+		def eraseGeom1(self):
+			self._contact.geom.g1 = NULL
+			
+		def eraseGeom2(self):
+			self._contact.geom.g2 = NULL
+			
 				
 		def __contains__(self,_Geom geom):
 			return geom._OdeGeomID == self._contact.geom.g1 or geom._OdeGeomID ==self._contact.geom.g2
diff --git a/soya/ode/geom-terrain.pyx b/soya/ode/geom-terrain.pyx
index ae689fc..4eb317a 100644
--- a/soya/ode/geom-terrain.pyx
+++ b/soya/ode/geom-terrain.pyx
 cdef dColliderFn * _TerrainGetColliderFn(int gclass):
+		print "called _TerrainGetColliderFn:"
 
 		if gclass in (dSphereClass, dBoxClass, dCapsuleClass, dCylinderClass):
 				return _TerrainCollide
@@ -475,5 +478,8 @@ cdef int dTerrainClass
 
 dTerrainClass = dCreateGeomClass(&dTerrainGeomClass)
 
+cdef void geomterrain_init():
+	dSetColliderOverride(dTerrainClass,0, _TerrainCollide)
 
+print "Created new terrain class: %d" % dTerrainClass
 
