Commits

Anonymous committed 75de0ce

  • Participants
  • Parent commits 462dd53
  • Branches physics

Comments (0)

Files changed (6)

 	int i = 0;
 	s_world = PG_WorldNew();
 	s_world->fStepTime = 0.03;
-	PG_Set_Vector2(s_world->vecGravity, 0, -600.f);
+	PG_Set_Vector2(s_world->vecGravity, 0, -2000.f);
 
-	for(i = 0; i < 12; ++i)
+	for(i = 0; i < 10; ++i)
 	{
 		body = PG_BodyNew();
 		//PG_Set_Vector2(body->vecPosition, -100+100*i, 200);
 		
 		body->fRotation = 0.f;
 		body->fAngleVelocity = 0.f;
-		body->fRestitution = 1.f;
+		body->fRestitution = 0.0f;
 		body->fMass = 10;
 		PG_Bind_RectShape(body, 30, 30, 0);
 		PG_AddBodyToWorld(s_world, body);

File include/pgCollision.h

 
 pgJointObject* PG_ContactNew(pgBodyObject* refBody, pgBodyObject* incidBody);
 
-void PG_AppendContact(pgBodyObject* refBody, pgBodyObject* incidBody, PyObject* contactList);
+void PG_DetectCollision(pgBodyObject* refBody, pgBodyObject* incidBody, PyObject* contactList);
 void PG_ApplyContact(PyObject* contactObject, double step);
 
 #endif

File include/pgWorldObject.h

 pgWorldObject* PG_WorldNew();
 void	PG_WorldDestroy(pgWorldObject* world);
 
-void	PG_Update(pgWorldObject* world,double stepTime);
-int		PG_AddBodyToWorld(pgWorldObject* world,pgBodyObject* body);
-int		PG_RemoveBodyFromWorld(pgWorldObject* world,pgBodyObject* body);
-int		PG_AddJointToWorld(pgWorldObject* world,pgJointObject* joint);
-int		PG_RemoveJointFromWorld(pgWorldObject* world,pgJointObject* joint);
+void	PG_Update(pgWorldObject* world, double stepTime);
+int		PG_AddBodyToWorld(pgWorldObject* world, pgBodyObject* body);
+int		PG_RemoveBodyFromWorld(pgWorldObject* world, pgBodyObject* body);
+int		PG_AddJointToWorld(pgWorldObject* world, pgJointObject* joint);
+int		PG_RemoveJointFromWorld(pgWorldObject* world, pgJointObject* joint);
 
 
 #endif

File src/pgAABBBox.c

 	return from_x - eps <= to_x + eps && from_y - eps <= to_y + eps;
 }
 
-PG_IsIn(pgVector2* p, pgAABBBox* box, double eps)
+int PG_IsIn(pgVector2* p, pgAABBBox* box, double eps)
 {
 	return box->left - eps < p->real && p->real < box->right + eps
 		&& box->bottom - eps < p->imag && p->imag < box->top + eps;

File src/pgCollision.c

 }
 
 
-void PG_AppendContact(pgBodyObject* refBody, pgBodyObject* incidBody, PyObject* contactList)
+void PG_DetectCollision(pgBodyObject* refBody, pgBodyObject* incidBody, PyObject* contactList)
 {
 	refBody->shape->Collision(refBody, incidBody, contactList);
 }

File src/pgShapeObject.c

 #include <math.h>
 #include <assert.h>
 #include <float.h>
+#include <GL/glut.h>
 
 PyTypeObject pgShapeType;
 PyTypeObject pgRectShapeType;
 					   int* faceId, double* min_dep, pgVector2* gp_in_ref, 
 					   pgAABBBox* clipBox)
 {
-#define _EPS_DEPTH 1e-8
+#define _EPS_DEPTH 1e-2
 
 	int i, apart;
 	pgRectShape *ref, *inc;
 	pgVector2 refR, incidR;
 	double tmp1, tmp2;
 
+	//for test
+	pgVector2 tgp[4];
+
 
 	overlap = _SAT_Select(selfBody, incidBody,
 						  &ref, &inc,
 		break;
 	}
 
+	//for test
+	for(i = 0; i < 4; ++i)
+		tgp[i] = PG_GetGlobalPos(ref, &(((pgRectShape*)ref->shape)->point[i]));
+	glColor3f(1.f, 0.0f, 0.5f);
+	glBegin(GL_LINES);
+	switch(face_id)
+	{
+	case CF_LEFT:
+		glVertex2f(tgp[0].real, tgp[0].imag);
+		glVertex2f(tgp[3].real, tgp[3].imag);
+		break;
+	case CF_RIGHT:
+		glVertex2f(tgp[1].real, tgp[1].imag);
+		glVertex2f(tgp[2].real, tgp[2].imag);
+		break;
+	case CF_TOP:
+		glVertex2f(tgp[2].real, tgp[2].imag);
+		glVertex2f(tgp[3].real, tgp[3].imag);
+		break;
+	case CF_BOTTOM:
+		glVertex2f(tgp[0].real, tgp[0].imag);
+		glVertex2f(tgp[1].real, tgp[1].imag);
+		break;
+	default:
+		break;
+	}
+	glEnd();
+
 
 	pAcc = PyObject_Malloc(sizeof(pgVector2));
 	pAcc->real = pAcc->imag = 0;