Advertisement
SargTeX

Untitled

Jun 12th, 2012
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.41 KB | None | 0 0
  1. #include <SFML/Graphics.hpp>
  2. #include <Box2D/Box2D.h>
  3.  
  4. int main()
  5. {
  6.     sf::RenderWindow window(sf::VideoMode(300, 200), "SFML works!");
  7.     sf::Text text("Hello SFML");
  8.    
  9.     //world
  10.     b2Vec2 gravity(0.0f, -10.0f);
  11.     b2World world(gravity);
  12.     b2BodyDef groundBodyDef;
  13.     groundBodyDef.position.Set(0.0f, -10.0f);
  14.     b2Body* groundBody = world.CreateBody(&groundBodyDef);
  15.     b2PolygonShape groundBox;
  16.     groundBox.SetAsBox(50.0f, 10.0f);
  17.     groundBody->CreateFixture(&groundBox, 0.0f);
  18.     b2BodyDef bodyDef;
  19.     bodyDef.type = b2_dynamicBody;
  20.     bodyDef.position.Set(0.0f, 4.0f);
  21.     b2Body* body = world.CreateBody(&bodyDef);
  22.     b2PolygonShape dynamicBox;
  23.     dynamicBox.SetAsBox(1.0f, 1.0f);
  24.     b2FixtureDef fixtureDef;
  25.     fixtureDef.shape = &dynamicBox;
  26.     fixtureDef.density = 1.0f;
  27.     fixtureDef.friction = 0.3f;
  28.     body->CreateFixture(&fixtureDef);
  29.  
  30.     while (window.isOpen())
  31.     {
  32.         sf::Event event;
  33.         while (window.pollEvent(event))
  34.         {
  35.             if (event.type == sf::Event::Closed)
  36.                 window.close();
  37.         }
  38.  
  39.         //window.draw(Text);
  40.        
  41.         float32 timeStep = 1.0f/60.0f;
  42.         int32 velocityIterations = 6;
  43.         int32 positionIterations = 2;
  44.         world.Step(timeStep, velocityIterations, positionIterations);
  45.        
  46.         window.clear();
  47.         window.display();
  48.     }
  49.  
  50.     return EXIT_SUCCESS;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement