Commits

Anonymous committed 4339a9b

Comments (0)

Files changed (3)

src/pgBodyObject.c

 
 void PG_Bind_RectShape(pgBodyObject* body, double width, double height, double seta)
 {
+	printf("body pointer in bind:%d\n",body);
 	if(body->shape == NULL)
 		body->shape = PG_RectShapeNew(body, width, height, seta);
 	else
 	//TODO: parse args later on
 	pgBodyObject* op;
 	if(PyType_Ready(type)==-1) return NULL;
-	op = (pgBodyObject*)type->tp_alloc(type, 0);
+	//op = (pgBodyObject*)type->tp_alloc(type, 0);
+	op = PyObject_New(pgBodyObject,type);
+	Py_INCREF(op);
 	PG_BodyInit(op);
+	printf("body pointer in body new:%d\n",op);
 	return (PyObject*)op;
 }
 

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
+	{
+		printf("body in get point list:%d\n",((pgBodyObject*)body));
+		if (body->shape == NULL)
+		{
+			//printf("Shape NULL\n"); //for test
+			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]);
+			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);
+		}
+		printf("body pointer in get list:%d\n",body);
+		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,""	},
+	{NULL, NULL, 0, NULL} 
+};

src/pgWorldObject.c

 	{
 		pgBodyObject* body = (pgBodyObject*)(PyList_GetItem((PyObject*)(world->bodyList), i));		
 		PG_FreeUpdateBodyVel(world, body, stepTime);
-		
+		printf("body pointer in body free:%d\n",body);	
 	}
 }
 
 	{
 		refBody = (pgBodyObject*)(PyList_GetItem((PyObject*)(world->bodyList), i));
 		printf("update AABB shape:%d\n",refBody->shape); 
+		printf("body pointer in body AABB:%d\n",refBody);
 		refBody->shape->UpdateAABB(refBody);
 	}
 	
 		contact = (pgJointObject*)(PyList_GetItem((PyObject*)(world->contactList), i));
 		contact->SolveConstraintPosition(contact, step);
 	}
+	
 }
 
 void _PG_JointSolve(pgWorldObject* world,double stepTime)
 void PG_Update(pgWorldObject* world,double stepTime)
 {
 	int i;
-
+	pgBodyObject* refBody;
+	printf("world update:%d\n",world);
 	_PG_FreeBodySimulation(world, stepTime);
-	
 	_PG_BodyCollisionDetection(world, stepTime);
-	printf("OK");
+	printf("OK\n");
 	for (i = 0;i < MAX_SOLVE_INTERAT;i++)
 	{
 		_PG_JointSolve(world, stepTime);
 	}
 	
 	_PG_BodyPositionUpdate(world, stepTime);
+	refBody = (pgBodyObject*)(PyList_GetItem((PyObject*)(world->bodyList), 0));
+	printf("body pointer in world update:%d\n",refBody);
 }
 
 
 int PG_AddBodyToWorld(pgWorldObject* world,pgBodyObject* body)
 {
+	printf("body pointer in body add:%d\n",body);
 	return PyList_Append((PyObject*)world->bodyList,(PyObject*)body);
 }
 
+
+
 int PG_RemoveBodyFromWorld(pgWorldObject* world,pgBodyObject* body)
 {
 	return 0;
 	Py_RETURN_NONE;
 }
 
-static PyObject* _world_add_body(pgWorldObject* world,PyObject* pybody)
+static PyObject* _world_add_body(pgWorldObject* world,PyObject* args)
 {
-	pgBodyObject* body = (pgBodyObject*)pybody;
+	pgBodyObject* body;
+	if (!PyArg_ParseTuple(args,"O",&body))
+	{
+		PyErr_SetString(PyExc_ValueError,"arg is not body type");
+		return NULL;
+	}
 	if(PG_AddBodyToWorld(world,body))
 	{
 		Py_RETURN_FALSE;