Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SFML/Graphics.hpp>
- #include <Box2D/Box2D.h>
- int main()
- {
- sf::RenderWindow window(sf::VideoMode(300, 200), "SFML works!");
- sf::Text text("Hello SFML");
- //world
- b2Vec2 gravity(0.0f, -10.0f);
- b2World world(gravity);
- b2BodyDef groundBodyDef;
- groundBodyDef.position.Set(0.0f, -10.0f);
- b2Body* groundBody = world.CreateBody(&groundBodyDef);
- b2PolygonShape groundBox;
- groundBox.SetAsBox(50.0f, 10.0f);
- groundBody->CreateFixture(&groundBox, 0.0f);
- b2BodyDef bodyDef;
- bodyDef.type = b2_dynamicBody;
- bodyDef.position.Set(0.0f, 4.0f);
- b2Body* body = world.CreateBody(&bodyDef);
- b2PolygonShape dynamicBox;
- dynamicBox.SetAsBox(1.0f, 1.0f);
- b2FixtureDef fixtureDef;
- fixtureDef.shape = &dynamicBox;
- fixtureDef.density = 1.0f;
- fixtureDef.friction = 0.3f;
- body->CreateFixture(&fixtureDef);
- while (window.isOpen())
- {
- sf::Event event;
- while (window.pollEvent(event))
- {
- if (event.type == sf::Event::Closed)
- window.close();
- }
- //window.draw(Text);
- float32 timeStep = 1.0f/60.0f;
- int32 velocityIterations = 6;
- int32 positionIterations = 2;
- world.Step(timeStep, velocityIterations, positionIterations);
- window.clear();
- window.display();
- }
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement