Anonymous avatar Anonymous committed 7cec159

Add a test case of multiple joint solver

Comments (0)

Files changed (2)

 	PG_AddJointToWorld(s_world,joint);
 }
 
+void TestBasic4Init()
+{
+	#define BODY_NUM 2
+
+	int i;
+	pgBodyObject* body[BODY_NUM + 1];
+	pgJointObject* joint[BODY_NUM];
+	pgVector2 a1,a2;
+	PG_Set_Vector2(a1,0,0);
+	PG_Set_Vector2(a2,0,100);
+
+	s_world = PG_WorldNew();
+	s_world->fStepTime = 0.03;
+
+	body[0] = NULL;
+	for (i = 1;i < BODY_NUM + 1;i++)
+	{
+		body[i] = PG_BodyNew();
+		PG_Set_Vector2(body[i]->vecPosition,0,(-i*50 + 100))
+		PG_Set_Vector2(body[i]->vecLinearVelocity,0,0)
+		PG_AddBodyToWorld(s_world,body[i]);
+	}
+
+	PG_Set_Vector2(body[BODY_NUM]->vecLinearVelocity,50,0)
+
+	i = 0;
+	joint[i] = PG_DistanceJointNew(body[i+1],body[i],0,50,a1,a2);
+	PG_AddJointToWorld(s_world,joint[i]);
+	for (i = 1;i < BODY_NUM;i++)
+	{
+		joint[i] = PG_DistanceJointNew(body[i],body[i+1],0,50,a1,a2);
+		PG_AddJointToWorld(s_world,joint[i]);
+	}
+
+
+}
+
 //===============================================
 
 void InitWorld()
 {
-	TestBasic3Init();
+	TestBasic4Init();
 }
 
 int main (int argc, char** argv)

src/pgWorldObject.c

 #include "pgBodyObject.h"
 #include "pgJointObject.h"
 
+#define MAX_SOLVE_INTERAT 20
+
 void _PG_FreeBodySimulation(pgWorldObject* world,double stepTime)
 {
 	Py_ssize_t size = PyList_Size((PyObject*)(world->bodyList));
 
 void PG_Update(pgWorldObject* world,double stepTime)
 {
+	int i;
+
 	_PG_FreeBodySimulation(world, stepTime);
 	_PG_BodyCollisionDetection(world);
-	_PG_JointSolve(world,stepTime);
+	for (i = 0;i < MAX_SOLVE_INTERAT;i++)
+	{
+		_PG_JointSolve(world,stepTime);
+	}
+	
 	_PG_BodyPositionUpdate(world, stepTime);
 }
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.