Commits

minz  committed fa2b496

a python memory bug has been fixed, test1.py can run now

  • Participants
  • Parent commits 247d887
  • Branches physics

Comments (0)

Files changed (4)

File 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
 	k = dt / body->fMass;
 	totalVelAdd = c_mul_complex_with_real(totalF, k);
 	body->vecLinearVelocity = c_sum(body->vecLinearVelocity, totalVelAdd);
+	
 }
 
 void PG_FreeUpdateBodyPos(pgWorldObject* world,pgBodyObject* body,double dt)
 	body->fRotation = 0.0;
 	body->fTorque = 0.0;
 	body->shape = NULL;
+	body->bStatic = 0;
 	PG_Set_Vector2(body->vecForce,0.0,0.0);
 	PG_Set_Vector2(body->vecImpulse,0.0,0.0);
 	PG_Set_Vector2(body->vecLinearVelocity,0.0,0.0);
 	op = PyObject_New(pgBodyObject,type);
 	Py_INCREF(op);
 	PG_BodyInit(op);
-	printf("body pointer in body new:%d\n",op);
 	return (PyObject*)op;
 }
 
 	double width,height,seta;
 	if (!PyArg_ParseTuple(args,"ddd",&width,&height,&seta))
 	{
-		//printf("fail\n"); //for test
 		PyErr_SetString(PyExc_ValueError,"parameters are wrong");
 		return NULL;
 	}
 		}
 		else
 		{
-			printf("bind shape:%d\n",((pgBodyObject*)body)->shape);
 			Py_RETURN_NONE;
 			//return ((pgBodyObject*)body)->shape;
 		}

File src/pgHelpFunctions.c

+#include "pgVector2.h"
 #include "pgBodyObject.h"
 #include "pgShapeObject.h"
 
 	}
 	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]);
+			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);
 			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;
 	}
 }

File 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);	
 	}
 }
 
 	for(i = 0; i < size; ++i)
 	{
 		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);
 	}
 	
 	{
 		pgBodyObject* body = (pgBodyObject*)(PyList_GetItem((PyObject*)(world->bodyList),i));
 		PG_FreeUpdateBodyPos(world,body,stepTime);
+		
 	}
 }
 
 {
 	int i;
 	pgBodyObject* refBody;
-	printf("world update:%d\n",world);
 	_PG_FreeBodySimulation(world, stepTime);
 	_PG_BodyCollisionDetection(world, stepTime);
-	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);
 }
 
 {
 	double dt = 0.1;
 	//double dt = PyFloat_AsDouble(pyfloat);
-	printf("%f,%d\n",dt,world);
-	
+		
 	PG_Update(world,dt);
 	Py_RETURN_NONE;
 }
 
 static PyObject* _pgWorld_getBodyList(pgWorldObject* world,void* closure)
 {
+	Py_INCREF ((PyObject*)world->bodyList);
 	return (PyObject*)world->bodyList;
 }
 
 
 def init_world():
     w = physics.World()
+    w.gravity = 0+1j
     body1 = physics.Body()
     body1.bind_rect_shape(2,2,0)
-    body1.position = 1+2j
+    body1.position = 10+20j
+    body1.velocity = 1+0j;
     w.add_body(body1)
     return w