0 Members and 1 Guest are viewing this topic.
#include <SFML/System.hpp>#include <SFML/Graphics.hpp>#include <SFML/Window.hpp>#include <iostream>#include <cmath>typedef sf::Vector2f VECTOR;VECTOR rect1[4] = {VECTOR(400,200),VECTOR(500,200),VECTOR(500,400),VECTOR(400,400)};//VECTOR rect2[4] = {VECTOR(350,200),VECTOR(450,200),VECTOR(450,400),VECTOR(350,400)};void DrawRect(sf::RenderWindow & App, const VECTOR rect[], int r, int g, int b){ for(int i=0;i<4;i++) App.Draw(sf::Shape::Line(rect[i].x,rect[i].y, rect[i+(i==3? -3 : 1)].x,rect[i+(i==3? -3 : 1)].y,1,sf::Color(r,g,b)));}int main(){ sf::RenderWindow App(sf::VideoMode(800,600,32),"Vector"); sf::Texture imgR1; imgR1.LoadFromFile("rect1.png"); imgR1.SetSmooth(false); sf::Sprite R1(imgR1); R1.SetPosition(200,200); R1.SetOrigin(0,0); int angle=0; R1.SetRotation(angle); App.SetFramerateLimit(60); while(App.IsOpened()) { sf::Event Event; App.PollEvent(Event); if(Event.Type == sf::Event::Closed) App.Close(); if(Event.Key.Code == sf::Keyboard::Escape) App.Close(); if((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Keyboard::Right)) { R1.SetRotation(angle--); rect1[0] = R1.TransformToGlobal(rect1[0]); rect1[1] = R1.TransformToGlobal(rect1[1]); rect1[2] = R1.TransformToGlobal(rect1[2]); rect1[3] = R1.TransformToGlobal(rect1[3]); } if((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Keyboard::Left)) { R1.SetRotation(angle++); rect1[0] = R1.TransformToGlobal(rect1[0]); rect1[1] = R1.TransformToGlobal(rect1[1]); rect1[2] = R1.TransformToGlobal(rect1[2]); rect1[3] = R1.TransformToGlobal(rect1[3]); } App.Clear(); DrawRect(App,rect1,255,0,0); App.Draw(R1); App.Display(); } return 0;}