Hi, I am a new user of Box2D. I am trying to get the intersection between two polygons. Here is the code I have written
b2Vec2 vertices1[9];//PolygonA
vertices1[0].Set(0.0f, 0.0f);
vertices1[1].Set(1.0f, 0.0f);
vertices1[2].Set(1.5f, 0.5f);
vertices1[3].Set(1.5f, 1.0f);
vertices1[4].Set(1.3f, 1.3f);
vertices1[5].Set(1.0f, 1.5f);
vertices1[6].Set(0.5f, 1.5f);
vertices1[7].Set(0.3f, 1.3f);
vertices1[8].Set(0.0f, 0.5f);
int count1= 9;
b2PolygonShape* polygon1= new b2PolygonShape;
b2Transform transform1;
transform1.SetIdentity();
b2Vec2 vertices2[3];//PolygonB
vertices2[0].Set(.50f, 0.25f);
vertices2[1].Set(0.50f, 1.25f);
vertices2[2].Set(-0.5f, 1.25f);
int count2= 3;
b2PolygonShape* polygon2= new b2PolygonShape;
polygon2->Set(vertices2, count2);
b2Transform transform2;
transform2.SetIdentity();
b2Manifold* manifold= new b2Manifold;
b2CollidePolygons(manifold, polygon1, transform1, polygon2, transform2);
for(unsigned int i=0; i<manifold->pointCount; i++)
{
//cout<<
b2ManifoldPoint ipoint= manifold->points[i];
b2Vec2 point= ipoint.localPoint;
cout<<point.x<<","<<point.y<<endl;
}
I was expecting only one point (0.5,0.25) as it is the vertex of polygon B that is inside polygon A. But it is showing two points (0.5,0.25 and 0.5,0.52). Can anybody tell me why is it like this? What exactly manifold returns?
Thanks
Sagar
b2Vec2 vertices1[9];//PolygonA
vertices1[0].Set(0.0f, 0.0f);
vertices1[1].Set(1.0f, 0.0f);
vertices1[2].Set(1.5f, 0.5f);
vertices1[3].Set(1.5f, 1.0f);
vertices1[4].Set(1.3f, 1.3f);
vertices1[5].Set(1.0f, 1.5f);
vertices1[6].Set(0.5f, 1.5f);
vertices1[7].Set(0.3f, 1.3f);
vertices1[8].Set(0.0f, 0.5f);
int count1= 9;
b2PolygonShape* polygon1= new b2PolygonShape;
b2Transform transform1;
transform1.SetIdentity();
b2Vec2 vertices2[3];//PolygonB
vertices2[0].Set(.50f, 0.25f);
vertices2[1].Set(0.50f, 1.25f);
vertices2[2].Set(-0.5f, 1.25f);
int count2= 3;
b2PolygonShape* polygon2= new b2PolygonShape;
polygon2->Set(vertices2, count2);
b2Transform transform2;
transform2.SetIdentity();
b2Manifold* manifold= new b2Manifold;
b2CollidePolygons(manifold, polygon1, transform1, polygon2, transform2);
for(unsigned int i=0; i<manifold->pointCount; i++)
{
//cout<<
b2ManifoldPoint ipoint= manifold->points[i];
b2Vec2 point= ipoint.localPoint;
cout<<point.x<<","<<point.y<<endl;
}
I was expecting only one point (0.5,0.25) as it is the vertex of polygon B that is inside polygon A. But it is showing two points (0.5,0.25 and 0.5,0.52). Can anybody tell me why is it like this? What exactly manifold returns?
Thanks
Sagar