Commits

Anonymous committed f63168e

Add joint pygame render wrapper stuff.

Comments (0)

Files changed (5)

include/pgHelpFunctions.h

 int
 DoubleFromObj (PyObject* obj, double* val);
 
+
+PyObject* FromPhysicsVector2ToPygamePoint(pgVector2 v2);
+
 #endif /* _PG_HELPFUNCTIONS_H */
     return -1;
 }
 
+/**
+* Getter for retrieving the bStatic of the passed body.
+*/
+static PyObject* _pgBody_getBStatic (pgBodyObject* body,void* closure)
+{
+	return PyInt_FromLong (body->bStatic);
+}
+
+/**
+* Sets the bStatic of the passed body.
+*/
+static int _pgBody_setBStatic (pgBodyObject* body,PyObject* value,void* closure)
+{
+	if (PyInt_Check (value))
+	{
+		body->bStatic = PyInt_AsLong (value);
+		return 0;
+
+	}
+	PyErr_SetString (PyExc_TypeError, "torque must be a float");
+	return -1;
+}
+
 static PyObject* _pgBody_bindRectShape(PyObject* body,PyObject* args)
 {
 	double width,height,seta;
 	}
 }
 
-#define FLOAT_TO_INT_MUL 10
+
 
 static PyObject * _pg_getPointListFromBody(PyObject *self, PyObject *args)
 {
 		{
 			pgVector2* pVertex = &(((pgRectShape*)(body->shape))->point[i]);
 			pgVector2 golVertex = PG_GetGlobalPos(body,pVertex);
-			PyObject* tuple = PyTuple_New(2);
-
-			long ix = golVertex.real * FLOAT_TO_INT_MUL;
-			long iy = golVertex.imag * FLOAT_TO_INT_MUL;
-			PyObject* xnum = PyInt_FromLong(ix);
-			PyObject* ynum = PyInt_FromLong(iy);
-			PyTuple_SetItem(tuple,0,xnum);
-			PyTuple_SetItem(tuple,1,ynum);
+			PyObject* tuple = FromPhysicsVector2ToPygamePoint(golVertex);
 			PyList_SetItem(list,i,tuple);
 		}
 		return (PyObject*)list;
     {"velocity",(getter)_pgBody_getVelocity,(setter)_pgBody_setVelocity,"velocity",NULL},
     {"position",(getter)_pgBody_getPosition,(setter)_pgBody_setPosition,"position",NULL},
     {"force",(getter)_pgBody_getForce,(setter)_pgBody_setForce,"force",NULL},
+	{"static",(getter)_pgBody_getBStatic,(setter)_pgBody_setBStatic,"whether static",NULL},
     { NULL, NULL, NULL, NULL, NULL}
 };
 

src/pgHelpFunctions.c

 #include "pgBodyObject.h"
 #include "pgShapeObject.h"
 
+#define FLOAT_TO_INT_MUL 10
+
 //#define FLOAT_TO_INT_MUL 10
 //
 ////these functions are for pygame rendering
     return 0;
 }
 
+PyObject* FromPhysicsVector2ToPygamePoint(pgVector2 v2)
+{
+	PyObject* tuple = PyTuple_New(2);
+
+	long ix = v2.real * FLOAT_TO_INT_MUL;
+	long iy = v2.imag * FLOAT_TO_INT_MUL;
+	PyObject* xnum = PyInt_FromLong(ix);
+	PyObject* ynum = PyInt_FromLong(iy);
+	PyTuple_SetItem(tuple,0,xnum);
+	PyTuple_SetItem(tuple,1,ynum);
+	return tuple;
+}
+
 
 PyMethodDef pgHelpMethods[] = {
 	//{"get_point_list",_pg_getPointListFromBody,METH_VARARGS,""	},
 pgJointObject* _PG_JointNewInternal(PyTypeObject *type)
 {
 	pgJointObject* op = (pgJointObject*)type->tp_alloc(type, 0);
+	Py_INCREF(op);
 	//PG_InitJointBase(op);
 	return op;
 }
 
 	localP = c_diff(localP,body->vecPosition);
 	k = body->shape->rInertia / body->fMass;
+	k *= 2;
 	k += c_get_length_square(localP);
 	bb = (distance - c_get_length(L));
 	c_normalize(&L);
 	pgVector2 dvBody1,dvBody2;
 	double dAngleV1,dAngleV2;
 	k1 = body1->shape->rInertia / body1->fMass;
+	k1 *= 2;
 	k2 = body2->shape->rInertia / body2->fMass;
-	
+	k2 *= 2;
 
 	localP1 = c_diff(localP1,body1->vecPosition);
 	localP2 = c_diff(localP2,body2->vecPosition);
 
 	if(body1 && body2)
 	{
-		if (body1->bStatic || body2->bStatic)
+		if (body1->bStatic && body2->bStatic)
 		{
 			return;
 		}
+		if (body1->bStatic)
+		{
+			pgVector2 staticAnchor = PG_GetGlobalPos(body1,&pJoint->anchor1);
+			_PG_DistanceJoint_ComputeOneDynamic(body2,&staticAnchor,&pJoint->anchor2,pJoint->distance,stepTime);
+			return;
+		}
+		if (body2->bStatic)
+		{
+			pgVector2 staticAnchor = PG_GetGlobalPos(body2,&pJoint->anchor2);
+			_PG_DistanceJoint_ComputeOneDynamic(body1,&staticAnchor,&pJoint->anchor1,pJoint->distance,stepTime);
+			return;
+		}
 		_PG_DistanceJoint_ComputeTwoDynamic(pJoint,stepTime);
 				
 	}
 	}
 }
 
+static PyObject* _pgDistanceJoint_getPointList(PyObject *self, PyObject *args)
+{
+	pgDistanceJointObject* joint = (pgDistanceJointObject*)self;
+	PyObject* list  = PyList_New(2);
+
+	pgVector2 p = PG_GetGlobalPos(joint->joint.body1,&joint->anchor1);
+	PyObject* tuple = FromPhysicsVector2ToPygamePoint(p);
+	PyList_SetItem(list,0,tuple);
+
+	if(joint->joint.body2)
+	{
+		p = PG_GetGlobalPos(joint->joint.body2,&joint->anchor2);
+		
+	}
+	else
+	{
+		p = joint->anchor2;
+	}
+
+	tuple = FromPhysicsVector2ToPygamePoint(p);
+	PyList_SetItem(list,1,tuple);
+	return list;
+}
+
+static PyMethodDef _pgDistanceJoint_methods[] = {
+	{"get_point_list",_pgDistanceJoint_getPointList,METH_VARARGS,""	},
+	{NULL, NULL, 0, NULL}   /* Sentinel */
+};
+
 static PyMemberDef _pgDistanceJoint_members[] = 
 {
+	
     {	NULL, 0, 0, 0, NULL}
 }; 
 
 	0,                          /* tp_weaklistoffset */
 	0,                          /* tp_iter */
 	0,                          /* tp_iternext */
-	0,							/* tp_methods */
+	_pgDistanceJoint_methods,							/* tp_methods */
 	_pgDistanceJoint_members,	/* tp_members */
 	_pgDistanceJoint_getseters,	/* tp_getset */
 	0,							/* tp_base */
 {
 	double dt = 0.1;
 	//double dt = PyFloat_AsDouble(pyfloat);
-		
 	PG_Update(world,dt);
 	Py_RETURN_NONE;
 }