Hello,
I am trying to make it where multiple boxes fall down in a physics simulation. I'm using SFML 2 and Box2D. I managed to get most of it down. However when I run the program, the box just stays up in the air, it doesen't do anything. Any help as to why? Note: That I only have posted the code that I think needs to be looked at. I can post more if it is needed.
sf::RectangleShape box3;
b2PolygonShape dynamicBox3;
b2FixtureDef fixtureDef3;
//set up initial variables
vector <b2FixtureDef> fixtures;
vector <b2Body*> bodies;
vector <sf::RectangleShape> shapes;
box3.setPosition(sf::Vector2f(100, 5));
box3.setSize(sf::Vector2f(30, 30));
box3.setFillColor(sf::Color(0, 0, 255));
shapes.push_back(box3);
bodyDef3.type = b2_dynamicBody;
ballVec3.Set(30, 30);
bodyDef3.angularVelocity = 0.0f;
bodyDef3.linearVelocity = ballVec3;
bodyDef3.position.Set(50, 0);
bodyDef3.awake = true;
Body3 = World->CreateBody(&bodyDef3);
dynamicBox3.SetAsBox(10.0f, 10.0f);
fixtureDef3.shape = &dynamicBox3;
fixtureDef3.density = 2.0f;
fixtureDef3.friction = 2.0f;
fixtureDef3.restitution = .05f;
Body3->CreateFixture(&fixtureDef3);
fixtures.push_back(fixtureDef3);
bodies.push_back(Body3);
//update section
for (int i = 0; i < bodies.size(); i++)
{
b2Vec2 pos3 = bodies[i]->GetPosition();
float angle3 = bodies[i]->GetAngle();
box3.setPosition(pos3.x, pos3.y);
box3.setRotation(angle3);
}
//Drawing section
for (vector<sf::RectangleShape>::iterator it = shapes.begin(); it != shapes.end(); it++)
{
GameWin.draw(*it);
}