Hello,
I trying to learn how to create custom objects by setting vertices. For that I am trying to create a simple polygon which is about 15 pixels high and which runs over the whole bottom screen. In other words: a floor. I am using the following code:
But this does not work. Why's that? If I use this code instead, everything works:
So, what's the problem in my code (the first)? Again, I want to use vertices!
I trying to learn how to create custom objects by setting vertices. For that I am trying to create a simple polygon which is about 15 pixels high and which runs over the whole bottom screen. In other words: a floor. I am using the following code:
Code:
b2Vec2 vertices[4];
vertices[0].Set(0, 0);
vertices[1].Set(640/PTM_RATIO, 0);
vertices[2].Set(640/PTM_RATIO, 15);
vertices[3].Set(0, 15/PTM_RATIO);
b2PolygonShape polygonShape;
polygonShape.Set(vertices, 4);
bottomFixture = groundBody->CreateFixture(&polygonShape, 0);
vertices[0].Set(0, 0);
vertices[1].Set(640/PTM_RATIO, 0);
vertices[2].Set(640/PTM_RATIO, 15);
vertices[3].Set(0, 15/PTM_RATIO);
b2PolygonShape polygonShape;
polygonShape.Set(vertices, 4);
bottomFixture = groundBody->CreateFixture(&polygonShape, 0);
But this does not work. Why's that? If I use this code instead, everything works:
Code:
// Define the ground shape
b2EdgeShape groundBox;
// Bottom
groundBox.Set(b2Vec2(0,0 - bottomOffset), b2Vec2(screenSize.width/PTM_RATIO,0 - bottomOffset));
bottomFixture = groundBody->CreateFixture(&groundBox, 0);
// Top
groundBox.Set(b2Vec2(0,(screenSize.height/PTM_RATIO) + topOffset), b2Vec2(screenSize.width/PTM_RATIO,(screenSize.height/PTM_RATIO) + topOffset));
topFixture = groundBody->CreateFixture(&groundBox, 0);
// Left
groundBox.Set(b2Vec2(0 - leftOffset,screenSize.height/PTM_RATIO), b2Vec2(0 - leftOffset,0));
leftFixture = groundBody->CreateFixture(&groundBox, 0);
// Right
groundBox.Set(b2Vec2((screenSize.width/PTM_RATIO) + rightOffset,screenSize.height/PTM_RATIO), b2Vec2((screenSize.width/PTM_RATIO) + rightOffset,0));
rightFixture = groundBody->CreateFixture(&groundBox, 0);*/
b2EdgeShape groundBox;
// Bottom
groundBox.Set(b2Vec2(0,0 - bottomOffset), b2Vec2(screenSize.width/PTM_RATIO,0 - bottomOffset));
bottomFixture = groundBody->CreateFixture(&groundBox, 0);
// Top
groundBox.Set(b2Vec2(0,(screenSize.height/PTM_RATIO) + topOffset), b2Vec2(screenSize.width/PTM_RATIO,(screenSize.height/PTM_RATIO) + topOffset));
topFixture = groundBody->CreateFixture(&groundBox, 0);
// Left
groundBox.Set(b2Vec2(0 - leftOffset,screenSize.height/PTM_RATIO), b2Vec2(0 - leftOffset,0));
leftFixture = groundBody->CreateFixture(&groundBox, 0);
// Right
groundBox.Set(b2Vec2((screenSize.width/PTM_RATIO) + rightOffset,screenSize.height/PTM_RATIO), b2Vec2((screenSize.width/PTM_RATIO) + rightOffset,0));
rightFixture = groundBody->CreateFixture(&groundBox, 0);*/
So, what's the problem in my code (the first)? Again, I want to use vertices!