Hi! I need some help to flip a fixture...
When i create a body,normally it collides with other object.
If i flip the body, with the following function, it doesn't collides anymore.
I don't understand... i reverse the vertices to make sure they are in counter-clockwise order.
It should be work :/
If i reverse the vertices and i destroy the old fixture, then i create a new one with the reversed vertices, it work...
Something "magic" happens on CreateFixture? 🙂
PS: i'm sorry for my bad english 🙁
When i create a body,normally it collides with other object.
If i flip the body, with the following function, it doesn't collides anymore.
I don't understand... i reverse the vertices to make sure they are in counter-clockwise order.
It should be work :/
If i reverse the vertices and i destroy the old fixture, then i create a new one with the reversed vertices, it work...
Something "magic" happens on CreateFixture? 🙂
PS: i'm sorry for my bad english 🙁
Code: Select all
-(void)flipFixture:(BOOL)horizzontally
{
b2Fixture* fix = physBody->GetFixtureList();
while(fix)
{
b2Shape* shape = fix->GetShape();
if(shape->GetType()== b2Shape::e_polygon)
{
// flipping x or y coordinates
b2PolygonShape* ps = (b2PolygonShape*)shape;
for(int i=0;i<ps->m_vertexCount;i++)
horizzontally ? ps->m_vertices[i].x *= -1 : ps->m_vertices[i].y *= -1;
//revert the vertices
b2Vec2* reVert = new b2Vec2[ps->m_vertexCount];
int j = ps->m_vertexCount -1;
for(int i=0; i<ps->m_vertexCount;i++)
reVert[i] = ps->m_vertices[j--];
#if 0 //destroy the fixture and create a new flipped fixture
b2PolygonShape polyShapeSx;
polyShapeSx.Set(&reVert[0], ps->m_vertexCount);
physBody->DestroyFixture(fix);
physBody->CreateFixture(&polyShapeSx, 1.0f);
return;
#else
//copy the reverted vertices to the shape array.
for(int k=0; k<ps->m_vertexCount;k++)
ps->m_vertices[k] = reVert[k];
#endif
}
fix = fix->GetNext();
}
}