void init( const Vec2& p1, const Vec2& p2, int attr )
    {
      b2Vec2 barOrigin = p1;
      b2Vec2 bar = p2 - p1;
      bar *= 1.0f/PIXELS_PER_METREf;
      barOrigin *= 1.0f/PIXELS_PER_METREf;;
      SetAsBox( bar.Length()/2.0f, 0.1f,
		0.5f*bar + barOrigin, vec2Angle( bar ));
      //      SetAsBox( bar.Length()/2.0f+b2_toiSlop, b2_toiSlop*2.0f,
      //	0.5f*bar + barOrigin, vec2Angle( bar ));
      friction = 0.3f;
      if ( attr & ATTRIB_GROUND ) {
	density = 0.0f;
      } else if ( attr & ATTRIB_GOAL ) {
	density = 100.0f;
      } else if ( attr & ATTRIB_TOKEN ) {
	density = 3.0f;
	friction = 0.1f;
      } else {
	density = 5.0f;
      }
      restitution = 0.2f;
    }
Beispiel #2
0
void plPhysics(Player* P, World* W)
{
	/* Mise à jour spécifique de Player */


	P->RdUStatus = P->RdRStatus = P->RdDStatus =
	P->RdLStatus = P->VxURStatus = P->VxULStatus =
	P->VxDLStatus = P->VxDRStatus = nullCollisionInfo();
	polyResolve(plGetShape(P));

	//for (i=0; i<10; i++) polyResolve(P->BodyPolygons[i]);
	for (int i=0; i<12; i++)
	{
		vxResolve(P->vxBodyParts[i], 0.5f, 0.5f);
		rdResolve(P->BodyRigids[i]);
	}

	float dif = vxGetPosition(P->VxDL).x - vxGetOldPos(P->VxDL).x;
	if (dif >= 0.f && ABS(dif) > 0.2f)
		P->Dir = DIR_RIGHT;
	else
		P->Dir = DIR_LEFT;

	List LExtracted = gridGetPolygonList(&W->CollisionGrid, P->Shape);

	Node* it;
	CollisionInfo Info;

	P->State = PL_NOSTATE;
	P->Normal = vec2(0.f, 0.f);

	it = lstFirst(&LExtracted);
	while(!nodeEnd(it))
	{

		Info = polyCollide(plGetShape(P), (Polygon*) nodeGetData(it));
		if(Info.P1 != NULL)
		{
			//printf("Collision\n");
			if (Info.Edge == plGetRdD(P))
			{
				P->GroundAngle = vec2Angle(Info.Normal)-M_PI_2;
				P->Normal = vec2Prod(Info.Normal, -1.f);
				P->State = P->State | PL_HAS_SUPPORT;
				if(P->Normal.y < -0.5f) P->State = P->State | PL_ON_GROUND;
			} else if(Info.V == plGetVxDL(P) || Info.V == plGetVxDR(P))	{
				P->GroundAngle = vec2Angle(Info.Normal)-M_PI_2;
				P->Normal = Info.Normal;
				P->State = P->State | PL_HAS_SUPPORT;
				if(P->Normal.y < -0.5f) P->State = P->State | PL_ON_GROUND;
			}


			/* Test des propriétés de la collision */
			if(Info.Edge == plGetRdU(P)) P->RdUStatus = Info;
			else if(Info.Edge == plGetRdR(P)) P->RdRStatus = Info;
			else if(Info.Edge == plGetRdD(P)) P->RdDStatus = Info;
			else if(Info.Edge == plGetRdL(P)) P->RdLStatus = Info;
			if(Info.V == plGetVxUL(P)) P->VxULStatus = Info;
			else if(Info.V == plGetVxUR(P)) P->VxURStatus = Info;
			else if(Info.V == plGetVxDR(P)) P->VxDRStatus = Info;
			else if(Info.V == plGetVxDL(P)) P->VxDLStatus = Info;


			polyHandleCollision(Info);
		}
		it = nodeGetNext(it);
	}
	lstFree(&LExtracted);
}