Commits

Anonymous committed b7c7926

python wrapping: add shape object, move get_point_list to body object

  • Participants
  • Parent commits 7cb9b1a
  • Branches physics

Comments (0)

Files changed (4)

File src/pgBodyObject.c

 	}
 }
 
+#define FLOAT_TO_INT_MUL 10
+
+static PyObject * _pg_getPointListFromBody(PyObject *self, PyObject *args)
+{
+	pgBodyObject* body = (pgBodyObject*)self;
+	int i;
+	PyListObject* list;
+
+	/*if (!PyArg_ParseTuple(args,"O",&body))
+	{
+		PyErr_SetString(PyExc_ValueError,"arg is not body type");
+		return NULL;
+	}
+	else*/
+	{
+		if (body->shape == NULL)
+		{
+			PyErr_SetString(PyExc_ValueError,"Shape is NULL");
+			return NULL;
+		}
+		list = (PyListObject*)PyList_New(4);
+		for (i = 0;i < 4;i++)
+		{
+			pgVector2* pVertex = &(((pgRectShape*)(body->shape))->point[i]);
+			pgVector2 golVertex = PG_GetGlobalPos(body,pVertex);
+			PyTupleObject* tuple = (PyTupleObject*)PyTuple_New(2);
+
+			long ix = golVertex.real * FLOAT_TO_INT_MUL;
+			long iy = golVertex.imag * FLOAT_TO_INT_MUL;
+			PyIntObject* xnum = PyInt_FromLong(ix);
+			PyIntObject* ynum = PyInt_FromLong(iy);
+			PyTuple_SetItem((PyObject*)tuple,0,xnum);
+			PyTuple_SetItem((PyObject*)tuple,1,ynum);
+			PyList_SetItem((PyObject*)list,i,(PyObject*)tuple);
+		}
+		return (PyObject*)list;
+	}
+}
+
 //===============================================================
 
 
 
 static PyMethodDef _pgBody_methods[] = {
 	{"bind_rect_shape",_pgBody_bindRectShape,METH_VARARGS,""},
+	{"get_point_list",_pg_getPointListFromBody,METH_VARARGS,""	},
     {NULL, NULL, 0, NULL}   /* Sentinel */
 };
 

File src/pgHelpFunctions.c

 #include "pgBodyObject.h"
 #include "pgShapeObject.h"
 
-#define FLOAT_TO_INT_MUL 10
-
-//these functions are for pygame rendering
-static PyObject * _pg_getPointListFromBody(PyObject *self, PyObject *args)
-{
-	pgBodyObject* body;
-	int i;
-	PyListObject* list;
-	
-	if (!PyArg_ParseTuple(args,"O",&body))
-	{
-		PyErr_SetString(PyExc_ValueError,"arg is not body type");
-		return NULL;
-	}
-	else
-	{
-		if (body->shape == NULL)
-		{
-			PyErr_SetString(PyExc_ValueError,"Shape is NULL");
-			return NULL;
-		}
-		list = (PyListObject*)PyList_New(4);
-		for (i = 0;i < 4;i++)
-		{
-			pgVector2* pVertex = &(((pgRectShape*)(body->shape))->point[i]);
-			pgVector2 golVertex = PG_GetGlobalPos(body,pVertex);
-			PyTupleObject* tuple = (PyTupleObject*)PyTuple_New(2);
-			
-			long ix = golVertex.real * FLOAT_TO_INT_MUL;
-			long iy = golVertex.imag * FLOAT_TO_INT_MUL;
-			PyIntObject* xnum = PyInt_FromLong(ix);
-			PyIntObject* ynum = PyInt_FromLong(iy);
-			PyTuple_SetItem((PyObject*)tuple,0,xnum);
-			PyTuple_SetItem((PyObject*)tuple,1,ynum);
-			PyList_SetItem((PyObject*)list,i,(PyObject*)tuple);
-		}
-		return (PyObject*)list;
-	}
-}
-
+//#define FLOAT_TO_INT_MUL 10
+//
+////these functions are for pygame rendering
 //static PyObject * _pg_getPointListFromBody(PyObject *self, PyObject *args)
 //{
-//	pgRectShape* shape;
+//	pgBodyObject* body;
 //	int i;
 //	PyListObject* list;
-//
-//	if (!PyArg_ParseTuple(args,"O",&shape))
+//	
+//	if (!PyArg_ParseTuple(args,"O",&body))
 //	{
-//		PyErr_SetString(PyExc_ValueError,"arg is not shape type");
+//		PyErr_SetString(PyExc_ValueError,"arg is not body type");
 //		return NULL;
 //	}
 //	else
 //	{
-//		if (shape == NULL)
+//		if (body->shape == NULL)
 //		{
 //			PyErr_SetString(PyExc_ValueError,"Shape is NULL");
 //			return NULL;
 //		}
 //		list = (PyListObject*)PyList_New(4);
 //		for (i = 0;i < 4;i++)
-//		{|
-//
-//			pgVector2* pVertex = &(shape->point[i]);
+//		{
+//			pgVector2* pVertex = &(((pgRectShape*)(body->shape))->point[i]);
+//			pgVector2 golVertex = PG_GetGlobalPos(body,pVertex);
 //			PyTupleObject* tuple = (PyTupleObject*)PyTuple_New(2);
-//			long ix = pVertex->real * FLOAT_TO_INT_MUL;
-//			long iy = pVertex->imag * FLOAT_TO_INT_MUL;
+//			
+//			long ix = golVertex.real * FLOAT_TO_INT_MUL;
+//			long iy = golVertex.imag * FLOAT_TO_INT_MUL;
 //			PyIntObject* xnum = PyInt_FromLong(ix);
 //			PyIntObject* ynum = PyInt_FromLong(iy);
 //			PyTuple_SetItem((PyObject*)tuple,0,xnum);
 //		return (PyObject*)list;
 //	}
 //}
-
+//
+////static PyObject * _pg_getPointListFromBody(PyObject *self, PyObject *args)
+////{
+////	pgRectShape* shape;
+////	int i;
+////	PyListObject* list;
+////
+////	if (!PyArg_ParseTuple(args,"O",&shape))
+////	{
+////		PyErr_SetString(PyExc_ValueError,"arg is not shape type");
+////		return NULL;
+////	}
+////	else
+////	{
+////		if (shape == NULL)
+////		{
+////			PyErr_SetString(PyExc_ValueError,"Shape is NULL");
+////			return NULL;
+////		}
+////		list = (PyListObject*)PyList_New(4);
+////		for (i = 0;i < 4;i++)
+////		{|
+////
+////			pgVector2* pVertex = &(shape->point[i]);
+////			PyTupleObject* tuple = (PyTupleObject*)PyTuple_New(2);
+////			long ix = pVertex->real * FLOAT_TO_INT_MUL;
+////			long iy = pVertex->imag * FLOAT_TO_INT_MUL;
+////			PyIntObject* xnum = PyInt_FromLong(ix);
+////			PyIntObject* ynum = PyInt_FromLong(iy);
+////			PyTuple_SetItem((PyObject*)tuple,0,xnum);
+////			PyTuple_SetItem((PyObject*)tuple,1,ynum);
+////			PyList_SetItem((PyObject*)list,i,(PyObject*)tuple);
+////		}
+////		return (PyObject*)list;
+////	}
+////}
+//
 PyMethodDef pgHelpMethods[] = {
-	{"get_point_list",_pg_getPointListFromBody,METH_VARARGS,""	},
+	//{"get_point_list",_pg_getPointListFromBody,METH_VARARGS,""	},
 	{NULL, NULL, 0, NULL} 
 };

File src/pgModuleInit.c

 extern PyTypeObject pgJointType;
 extern PyTypeObject pgDistanceJointType;
 
-////Shape types
-//extern PyTypeObject pgShapeType;
-//extern PyTypeObject pgRectShapeType;
+//Shape types
+extern PyTypeObject pgShapeType;
+extern PyTypeObject pgRectShapeType;
 
 //help functions
 extern PyMethodDef pgHelpMethods[];
         pgDistanceJointType.tp_base = &pgJointType;
 	if (PyType_Ready(&pgDistanceJointType) < 0)
 		return;
-	/*if (PyType_Ready(&pgShapeType) < 0)
+	if (PyType_Ready(&pgShapeType) < 0)
 		return;
 	if (PyType_Ready(&pgRectShapeType) < 0)
-		return;*/
+		return;
 
 		/* Increase their ref counts. */
 	Py_INCREF (&pgWorldType);
 	Py_INCREF (&pgBodyType);
 	Py_INCREF (&pgJointType);
 	Py_INCREF (&pgDistanceJointType);
-	/*Py_INCREF (&pgShapeType);
-	Py_INCREF (&pgRectShapeType);*/
+	Py_INCREF (&pgShapeType);
+	Py_INCREF (&pgRectShapeType);
 
 	/* Init the module and add the object types. */
 	mod = Py_InitModule3("physics", pgHelpMethods, "Simple 2D physics module");
 	PyModule_AddObject (mod, "Body", (PyObject *) &pgBodyType);
 	PyModule_AddObject (mod, "Joint", (PyObject *) &pgJointType);
 	PyModule_AddObject (mod, "DistanceJoint", (PyObject *) &pgDistanceJointType);
-	/*PyModule_AddObject (mod, "Shape", (PyObject *) &pgShapeType);
-	PyModule_AddObject (mod, "RectShape", (PyObject *) &pgRectShapeType);*/
+	PyModule_AddObject (mod, "Shape", (PyObject *) &pgShapeType);
+	PyModule_AddObject (mod, "RectShape", (PyObject *) &pgRectShapeType);
 }
 

File src/pgShapeObject.c

 #include <assert.h>
 #include <float.h>
 
-//PyTypeObject pgShapeType;
-//PyTypeObject pgRectShapeType;
+PyTypeObject pgShapeType;
+PyTypeObject pgRectShapeType;
 
 //functions of pgShapeObject
 
 	shape->Collision = NULL;
 }
 
-//pgShapeObject* _PG_ShapeNewInternal(PyTypeObject *type)
-//{
-//	pgShapeObject* op = (pgShapeObject*)type->tp_alloc(type, 0);
-//	PG_ShapeObjectInit(op);
-//	return op;
-//}
-//
+pgShapeObject* _PG_ShapeNewInternal(PyTypeObject *type)
+{
+	pgShapeObject* op = (pgShapeObject*)type->tp_alloc(type, 0);
+	PG_ShapeObjectInit(op);
+	return op;
+}
+
 void PG_ShapeObjectDestroy(pgShapeObject* shape)
 {
 	if(shape != NULL)
 		shape->Destroy(shape);
 	PyObject_Free(shape);
 }
-//
-//PyObject* _pgShapeNew(PyTypeObject *type, PyObject *args, PyObject *kwds)
-//{
-//	/* In case we have arguments in the python code, parse them later
-//	* on.
-//	*/
-//	PyObject* shape;
-//	if(PyType_Ready(type)==-1) return NULL;
-//
-//	shape = (PyObject*) _PG_ShapeNewInternal(type);
-//	return shape;
-//}
-//
-//static int _pgShape_init(pgShapeObject* shape,PyObject *args, PyObject *kwds)
-//{
-//	PG_ShapeObjectInit(shape);
-//	return 0;
-//}
-//
-//PyTypeObject pgShapeType =
-//{
-//	PyObject_HEAD_INIT(NULL)
-//	0,
-//	"physics.Shape",            /* tp_name */
-//	sizeof(pgShapeObject),      /* tp_basicsize */
-//	0,                          /* tp_itemsize */
-//	(destructor)PG_ShapeObjectDestroy,/* tp_dealloc */
-//	0,                          /* tp_print */
-//	0,                          /* tp_getattr */
-//	0,                          /* tp_setattr */
-//	0,                          /* tp_compare */
-//	0,                          /* tp_repr */
-//	0,                          /* tp_as_number */
-//	0,                          /* tp_as_sequence */
-//	0,                          /* tp_as_mapping */
-//	0,                          /* tp_hash */
-//	0,                          /* tp_call */
-//	0,                          /* tp_str */
-//	0,                          /* tp_getattro */
-//	0,                          /* tp_setattro */
-//	0,                          /* tp_as_buffer */
-//	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
-//	"",                         /* tp_doc */
-//	0,                          /* tp_traverse */
-//	0,                          /* tp_clear */
-//	0,                          /* tp_richcompare */
-//	0,                          /* tp_weaklistoffset */
-//	0,                          /* tp_iter */
-//	0,                          /* tp_iternext */
-//	0,		   	/* tp_methods */
-//	0,            /* tp_members */
-//	0,          /* tp_getset */
-//	0,                          /* tp_base */
-//	0,                          /* tp_dict */
-//	0,                          /* tp_descr_get */
-//	0,                          /* tp_descr_set */
-//	0,                          /* tp_dictoffset */
-//	_pgShape_init,                          /* tp_init */
-//	0,                          /* tp_alloc */
-//	_pgShapeNew,                /* tp_new */
-//	0,                          /* tp_free */
-//	0,                          /* tp_is_gc */
-//	0,                          /* tp_bases */
-//	0,                          /* tp_mro */
-//	0,                          /* tp_cache */
-//	0,                          /* tp_subclasses */
-//	0,                          /* tp_weaklist */
-//	0                           /* tp_del */
-//};
+
+PyObject* _pgShapeNew(PyTypeObject *type, PyObject *args, PyObject *kwds)
+{
+	/* In case we have arguments in the python code, parse them later
+	* on.
+	*/
+	PyObject* shape;
+	if(PyType_Ready(type)==-1) return NULL;
+
+	shape = (PyObject*) _PG_ShapeNewInternal(type);
+	return shape;
+}
+
+static int _pgShape_init(pgShapeObject* shape,PyObject *args, PyObject *kwds)
+{
+	PG_ShapeObjectInit(shape);
+	return 0;
+}
+
+PyTypeObject pgShapeType =
+{
+	PyObject_HEAD_INIT(NULL)
+	0,
+	"physics.Shape",            /* tp_name */
+	sizeof(pgShapeObject),      /* tp_basicsize */
+	0,                          /* tp_itemsize */
+	(destructor)PG_ShapeObjectDestroy,/* tp_dealloc */
+	0,                          /* tp_print */
+	0,                          /* tp_getattr */
+	0,                          /* tp_setattr */
+	0,                          /* tp_compare */
+	0,                          /* tp_repr */
+	0,                          /* tp_as_number */
+	0,                          /* tp_as_sequence */
+	0,                          /* tp_as_mapping */
+	0,                          /* tp_hash */
+	0,                          /* tp_call */
+	0,                          /* tp_str */
+	0,                          /* tp_getattro */
+	0,                          /* tp_setattro */
+	0,                          /* tp_as_buffer */
+	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
+	"",                         /* tp_doc */
+	0,                          /* tp_traverse */
+	0,                          /* tp_clear */
+	0,                          /* tp_richcompare */
+	0,                          /* tp_weaklistoffset */
+	0,                          /* tp_iter */
+	0,                          /* tp_iternext */
+	0,		   	/* tp_methods */
+	0,            /* tp_members */
+	0,          /* tp_getset */
+	0,                          /* tp_base */
+	0,                          /* tp_dict */
+	0,                          /* tp_descr_get */
+	0,                          /* tp_descr_set */
+	0,                          /* tp_dictoffset */
+	(initproc)_pgShape_init,                          /* tp_init */
+	0,                          /* tp_alloc */
+	_pgShapeNew,                /* tp_new */
+	0,                          /* tp_free */
+	0,                          /* tp_is_gc */
+	0,                          /* tp_bases */
+	0,                          /* tp_mro */
+	0,                          /* tp_cache */
+	0,                          /* tp_subclasses */
+	0,                          /* tp_weaklist */
+	0                           /* tp_del */
+};
 
 
 
 	return (pgShapeObject*)p;
 }
 
+
+static int _pgRectShape_init(pgRectShape* joint,PyObject *args, PyObject *kwds)
+{
+	if(pgJointType.tp_init((PyObject*)joint, args, kwds) < 0)
+	{
+		return -1;
+	}
+
+	return 0;
+}
+
+//-------------box's collision test------------------
+//TEST: these functions have been partly tested.
+
+//we use a simple SAT to select the contactNormal:
+//Supposing the relative velocity between selfBody and incidBody in
+//two frame is "small", the face(actually is an edge in 2D) with minimum 
+//average penetrating depth is considered to be contact face, then we
+//get the contact normal.
+//note: this method is not available in CCD(continue collision detection)
+//since the velocity is not small.
+//static double _SAT_GetContactNormal1(pgAABBBox* clipBox, PyObject* contactList,
+//								  int from, int to)
+//{
+//	int i;
+//	int id;
+//	double deps[4], min_dep;
+//	pgContact* p;
+//	pgVector2 normal;
+//		
+//	memset(deps, 0, sizeof(deps));
+//	for(i = from; i <= to; ++i)
+//	{
+//		p = (pgContact*)PyList_GetItem(contactList, i);
+//		deps[0] += p->pos.real - clipBox->left; //left
+//		deps[1] += p->pos.imag - clipBox->bottom; //bottom
+//		deps[2] += clipBox->right - p->pos.real; //right
+//		deps[3] += clipBox->top - p->pos.imag; //top
+//	}
+//	
+//	//find min penetrating face
+//	id = 0;
+//	min_dep = deps[0];
+//	for(i = 1; i < 4; ++i)
+//	{
+//		if(min_dep > deps[i])
+//		{
+//			min_dep = deps[i];
+//			id = i;
+//		}
+//	}
+//	PG_Set_Vector2(normal, 0, 0);
+//	//generate contactNormal
+//	switch(id)
+//	{
+//	case 0://left
+//		PG_Set_Vector2(normal, -1, 0);
+//		break;
+//	case 1://bottom
+//		PG_Set_Vector2(normal, 0, -1);
+//		break;
+//	case 2://right
+//		PG_Set_Vector2(normal, 1, 0);
+//		break;
+//	case 3://top
+//		PG_Set_Vector2(normal, 0, 1);
+//		break;
+//	}
+//
+//    for(i = from; i <= to; ++i)
+//    {
+//        p = (pgContact*)PyList_GetItem(contactList, i);
+//        p->normal = normal;
+//    }
+//
+//	return min_dep;
+//}
+//
+//#define _swap(a, b, t) {(t) = (a); (a) = (b); (b) = (t);}
+//
+////TODO: now just detect Box-Box collision, later add Box-Circle
+//int PG_RectShapeCollision1(pgBodyObject* selfBody, pgBodyObject* incidBody, PyObject* contactList)
+//{
+//	int i, i1, k;
+//	int from, to, _from[2], _to[2];
+//	int apart;
+//	pgVector2 ip[4];
+//	int has_ip[4]; //use it to prevent from duplication
+//	pgVector2 pf, pt;
+//	pgRectShape *self, *incid, *tmp;
+//	pgBodyObject * tmpBody;
+//	pgAABBBox clipBox;
+//	pgContact* contact;
+//	pgVector2* pAcc;
+//	PyObject* list[2];
+//	double dist[2];
+//
+//	list[0] = PyList_New(0);
+//	list[1] = PyList_New(0);
+//
+//	self = (pgRectShape*)selfBody->shape;
+//	incid = (pgRectShape*)incidBody->shape;
+//
+//	apart = 1;	
+//	for(k = 0; k < 2; ++k)
+//	{
+//		//transform incidBody's coordinate according to selfBody's coordinate
+//		for(i = 0; i < 4; ++i)
+//			ip[i] = PG_GetRelativePos(selfBody, incidBody, &(incid->point[i]));
+//		//clip incidBody by selfBody
+//		clipBox = PG_GenAABB(self->bottomLeft.real, self->topRight.real,
+//			self->bottomLeft.imag, self->topRight.imag);
+//		memset(has_ip, 0, sizeof(has_ip));
+//		_from[k] = PyList_Size(list[k]);
+//		
+//		for(i = 0; i < 4; ++i)
+//		{
+//			i1 = (i+1)%4;
+//			if(PG_LiangBarskey(&clipBox, &ip[i], &ip[i1], &pf, &pt))
+//			{
+//				apart = 0;
+//				if(pf.real == ip[i].real && pf.imag == ip[i].imag)
+//				{
+//					has_ip[i] = 1;
+//				}
+//				else
+//				{
+//					contact = (pgContact*)PG_ContactNew(selfBody, incidBody);
+//					contact->pos = pf;
+//					PyList_Append(list[k], (PyObject*)contact);
+//				}
+//				
+//				if(pt.real == ip[i1].real && pt.imag == ip[i1].imag)
+//				{	
+//					has_ip[i1] = 1;
+//				}
+//				else
+//				{
+//					contact = (pgContact*)PG_ContactNew(selfBody, incidBody);
+//					contact->pos = pt;
+//					PyList_Append(list[k], (PyObject*)contact);
+//				}
+//
+//			}
+//		}
+//
+//		if(apart)
+//			goto END;
+//
+//		for(i = 0; i < 4; ++i)
+//		{
+//			if(has_ip[i])
+//			{
+//				contact = (pgContact*)PG_ContactNew(selfBody, incidBody);
+//				contact->pos = ip[i];
+//				PyList_Append(list[k], (PyObject*)contact);
+//			}
+//		}
+//		//now all the contact points are added to list
+//		_to[k] = PyList_Size(list[k]) - 1;
+//		dist[k] = _SAT_GetContactNormal(&clipBox, list[k], _from[k], _to[k]);
+//
+//		//now swap refBody and incBody, and do it again
+//		_swap(selfBody, incidBody, tmpBody);
+//		_swap(self, incid, tmp);
+//	}
+//
+//	from = PyList_Size(contactList);
+//	for(i = 0; i < 2; ++i)
+//	{
+//		i1 = (i+1)%2;
+//		if(dist[i] <= dist[i1])
+//		{
+//			for(k = _from[i]; k <= _to[i]; ++k)
+//			{
+//				contact = (pgContact*)PyList_GetItem(list[i], k);
+//				PyList_Append(contactList, (PyObject*)contact);
+//				Py_XINCREF((PyObject*)contact);
+//			}
+//			break;
+//		}
+//		_swap(selfBody, incidBody, tmpBody);
+//	}
+//	to = PyList_Size(contactList) - 1;
+//
+//	pAcc = PyObject_Malloc(sizeof(pgVector2));
+//	pAcc->real = pAcc->imag = 0;
+//	for(i = from; i <= to; ++i)
+//	{
+//		contact = (pgContact*)PyList_GetItem(contactList, i);
+//
+//		c_rotate(&(contact->pos), selfBody->fRotation);
+//		contact->pos = c_sum(contact->pos, selfBody->vecPosition);
+//		c_rotate(&(contact->normal), selfBody->fRotation);
+//
+//		contact->ppAccMoment = PyObject_Malloc(sizeof(pgVector2*));
+//		*(contact->ppAccMoment) = pAcc;
+//
+//		contact->weight = (to - from)+1;
+//	}
+//
+//
+//END:
+//	Py_XDECREF(list[0]);
+//	Py_XDECREF(list[1]);
+//	return 1;
+//}
+
+
+////all the points are in refbox's locate coordinate system
+//static double _SAT_GetContactNormal(pgAABBBox* clipBox, pgVector2* clist, 
+//									int csize, pgVector2* normal)
+//{	
+//	int i;
+//	int id;
+//	double deps[4], min_dep;
+//	pgVector2* p;
+//		
+//	memset(deps, 0, sizeof(deps));
+//	for(i = 0; i < csize; ++i)
+//	{
+//		p = &clist[i];
+//		deps[0] += fabs(p->real - clipBox->left); //left
+//		deps[1] += fabs(p->imag - clipBox->bottom); //bottom
+//		deps[2] += fabs(clipBox->right - p->real); //right
+//		deps[3] += fabs(clipBox->top - p->imag); //top
+//	}
+//	
+//	//find min penetrating face
+//	id = 0;
+//	min_dep = deps[0];
+//	for(i = 1; i < 4; ++i)
+//	{
+//		if(min_dep > deps[i])
+//		{
+//			min_dep = deps[i];
+//			id = i;
+//		}
+//	}
+//	PG_Set_Vector2(*normal, 0, 0);
+//	//generate contactNormal
+//	switch(id)
+//	{
+//	case 0://left
+//		PG_Set_Vector2(*normal, -1, 0);
+//		break;
+//	case 1://bottom
+//		PG_Set_Vector2(*normal, 0, -1);
+//		break;
+//	case 2://right
+//		PG_Set_Vector2(*normal, 1, 0);
+//		break;
+//	case 3://top
+//		PG_Set_Vector2(*normal, 0, 1);
+//		break;
+//	default:
+//		assert(0);
+//		break;
+//	}
+//
+//	return min_dep;
+//}
+//
+//
+//static int _PG_RectShapeCollision(pgBodyObject* selfBody, pgBodyObject* incidBody,
+//								  pgVector2* clist, int* csize, pgVector2 *normal, double* depth)
+//{
+//	pgRectShape * self, * incid;
+//	pgVector2 gp[4], ans_p1, ans_p2;
+//	int has_ip[4];
+//	pgAABBBox clipBox;
+//	int i, i1;
+//	int axis;
+//	int valid_p1, valid_p2;
+//	pgVector2 cpoints[2][10], n[2];
+//	int csizes[2];
+//	double dep[2];
+//	int id;
+//	int apart[2];
+//
+//	self = (pgRectShape*)selfBody->shape;
+//	incid = (pgRectShape*)incidBody->shape;
+//
+//	clipBox = PG_GenAABB(self->bottomLeft.real, self->topRight.real,
+//		self->bottomLeft.imag, self->topRight.imag);
+//
+//	for(i = 0; i < 4; ++i)
+//		gp[i] = PG_GetRelativePos(selfBody, incidBody, &(incid->point[i]));
+//	
+//	for(axis = CA_X; axis <= CA_Y; ++axis)
+//	{
+//		memset(has_ip, 0, sizeof(has_ip));
+//		apart[axis] = 1;
+//		csizes[axis] = 0;
+//		for(i = 0; i < 4; ++i)
+//		{
+//			i1 = (i+1)%4;
+//			if(PG_PartlyLB(&clipBox, &gp[i], &gp[i1], axis, 
+//				&ans_p1, &ans_p2, &valid_p1, &valid_p2))
+//			{
+//				apart[axis] = 0;
+//				if(valid_p1)
+//				{
+//					if(c_equal(&ans_p1, &gp[i]))
+//						has_ip[i] = 1;
+//					else
+//						cpoints[axis][csizes[axis]++] = ans_p1;
+//				}
+//				if(valid_p2)
+//				{
+//					if(c_equal(&ans_p2, &gp[i1]))
+//						has_ip[i1] = 1;
+//					else
+//						cpoints[axis][csizes[axis]++] = ans_p2;
+//				}
+//			}
+//		}
+//
+//		for(i = 0; i < 4; ++i)
+//			if(has_ip[i])
+//				cpoints[axis][csizes[axis]++] = gp[i];
+//		dep[axis] = _SAT_GetContactNormal(&clipBox, cpoints[axis], csizes[axis], &n[axis]);
+//	}
+//
+//	if(apart[CA_X] && apart[CA_Y]) return 0;
+//	//assert(csizes[0] > 0 && csizes[1] > 0);
+//	
+//	id = dep[CA_X] < dep[CA_Y] ? CA_X : CA_Y;
+//	if(csizes[id] == 0)
+//		id = (id + 1)%2;
+//	*csize = csizes[id];
+//	for(i = 0; i < csizes[id]; ++i)
+//		clist[i] = cpoints[id][i];
+//	*normal = n[id];
+//	*depth = dep[id];
+//
+//	return 1;
+//}
+//
+//int PG_RectShapeCollision(pgBodyObject* selfBody, pgBodyObject* incidBody, 
+//						  PyObject* contactList)
+//{
+//	pgVector2 clist1[10], clist2[10], *clist, n1, n2, *n;
+//	int csize1, csize2, *csize;
+//	double dep1, dep2;
+//	int is_collided;
+//	pgBodyObject *self, *incid;
+//	int i;
+//	pgContact* contact;
+//	pgVector2* pAcc;
+//
+//	is_collided = _PG_RectShapeCollision(selfBody, incidBody, clist1, 
+//				  &csize1, &n1, &dep1);
+//	if(!is_collided) return 0;
+//	is_collided = _PG_RectShapeCollision(incidBody, selfBody, clist2, 
+//				  &csize2, &n2, &dep2);
+//	assert(is_collided);
+//
+//	if(dep1 < dep2)
+//	{
+//		clist = clist1;
+//		csize = &csize1;
+//		n = &n1;
+//		self = selfBody;
+//		incid = incidBody;
+//	}
+//	else
+//	{
+//		clist = clist2;
+//		csize = &csize2;
+//		n = &n2;
+//		self = incidBody;
+//		incid = selfBody;
+//	}
+//	assert(*csize > 0);
+//
+//
+//	pAcc = PyObject_Malloc(sizeof(pgVector2));
+//	pAcc->real = pAcc->imag = 0;
+//	for(i = 0; i < *csize; ++i)
+//	{
+//		contact = (pgContact*)PG_ContactNew(self, incid);
+//		contact->pos = clist[i];
+//		contact->normal = *n;
+//		c_rotate(&(contact->pos), self->fRotation);
+//		contact->pos = c_sum(contact->pos, self->vecPosition);
+//		c_rotate(&(contact->normal), self->fRotation);
+//
+//		contact->ppAccMoment = PyObject_Malloc(sizeof(pgVector2*));
+//		*(contact->ppAccMoment) = pAcc;
+//		contact->weight = *csize;
+//		PyList_Append(contactList, (PyObject*)contact);
+//	}
+//
+//	return 1;
+//}
+
+
+
 static int _Get_Depth(pgBodyObject* refBody, pgBodyObject* incBody,
 					   int* faceId, double* min_dep, pgVector2* gp_in_ref, 
 					   pgAABBBox* clipBox)
 	return 1;
 
 }
+
+
+PyTypeObject pgRectShapeType =
+{
+	PyObject_HEAD_INIT(NULL)
+	0,
+	"physics.RectShape",            /* tp_name */
+	sizeof(pgRectShape),      /* tp_basicsize */
+	0,                          /* tp_itemsize */
+	(destructor) 0,				/* tp_dealloc */
+	0,                          /* tp_print */
+	0,                          /* tp_getattr */
+	0,                          /* tp_setattr */
+	0,                          /* tp_compare */
+	0,                          /* tp_repr */
+	0,                          /* tp_as_number */
+	0,                          /* tp_as_sequence */
+	0,                          /* tp_as_mapping */
+	0,                          /* tp_hash */
+	0,                          /* tp_call */
+	0,                          /* tp_str */
+	0,                          /* tp_getattro */
+	0,                          /* tp_setattro */
+	0,                          /* tp_as_buffer */
+	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
+	"",                         /* tp_doc */
+	0,                          /* tp_traverse */
+	0,                          /* tp_clear */
+	0,                          /* tp_richcompare */
+	0,                          /* tp_weaklistoffset */
+	0,                          /* tp_iter */
+	0,                          /* tp_iternext */
+	0,							/* tp_methods */
+	0,	/* tp_members */
+	0,							/* tp_getset */
+	0,							/* tp_base */
+	0,                          /* tp_dict */
+	0,                          /* tp_descr_get */
+	0,                          /* tp_descr_set */
+	0,                          /* tp_dictoffset */
+	(initproc)_pgRectShape_init,  /* tp_init */
+	0,                          /* tp_alloc */
+	0,							/* tp_new */
+	0,                          /* tp_free */
+	0,                          /* tp_is_gc */
+	0,                          /* tp_bases */
+	0,                          /* tp_mro */
+	0,                          /* tp_cache */
+	0,                          /* tp_subclasses */
+	0,                          /* tp_weaklist */
+	0                           /* tp_del */
+};
+
+