AllenYuan

Untitled

Jun 2nd, 2020
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. #include <SFML/Graphics.hpp>
  2. using namespace sf;
  3.  
  4. int width = 1024;
  5. int height = 768;
  6.  
  7. // draw a quadrilateral in w with color c, parameterized by two center points of opposing sides
  8. // (x1, y1), (x2, y2) and 2 radiuses w1, w2.
  9. // You may wonder why we parameterize with w1 and w2 instead of 2 more points...this paramterization
  10. // makes the math for perspectives easier
  11. void drawQuad(RenderWindow &w, Color c, int x1, int y1, int w1, int x2, int y2, int w2)
  12. {
  13. ConvexShape shape(4);
  14. shape.setFillColor(c);
  15. shape.setPoint(0, Vector2f(x1-w1, y1));
  16. shape.setPoint(1, Vector2f(x2-w2, y2));
  17. shape.setPoint(2, Vector2f(x2+w2, y2));
  18. shape.setPoint(3, Vector2f(x1+w1, y1));
  19. w.draw(shape);
  20. }
  21.  
  22. int main()
  23. {
  24. RenderWindow app(VideoMode(width, height), "Outrun Racing!");
  25. app.setFramerateLimit(60);
  26.  
  27. while (app.isOpen())
  28. {
  29. Event e;
  30. while (app.pollEvent(e))
  31. {
  32. if (e.type == Event::Closed)
  33. app.close();
  34. }
  35.  
  36. app.clear();
  37. drawQuad(app, Color::Green, 500, 500, 200, 500, 300, 100);
  38. app.display();
  39. }
  40.  
  41. return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment