1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
| #include <math.h>
#include <iostream>
#include <SFML/Graphics.hpp>
int main()
{
unsigned int WIDTHSCREEN = 800, HEIGHTSCREEN = 600;
sf::RenderWindow app(sf::VideoMode(WIDTHSCREEN, HEIGHTSCREEN), "Rotozoom", sf::Style::Titlebar);
app.setFramerateLimit(60);
sf::RenderWindow render(sf::VideoMode(WIDTHSCREEN, HEIGHTSCREEN), "Render", sf::Style::Titlebar);
render.setFramerateLimit(60);
sf::Clock clock;
std::vector<sf::VertexArray>vecLines;
std::vector<sf::VertexArray>vecQuads;
sf::Vector2f m_position = {100,100};
float angle = 0.0f;
double speedMove = 20;
for (unsigned int i = 0 ; i < HEIGHTSCREEN ; i++)
{
sf::VertexArray line(sf::Lines, WIDTHSCREEN);
for (unsigned int k = 0 ; k < WIDTHSCREEN ; k++)
line[k].position = {0, i};
vecLines.push_back(line);
}
std::vector<std::vector<unsigned int>>vecMap =
{
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0},
{0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0},
{0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0},
{0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0},
{0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0},
{0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0},
{0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0},
{0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0},
{0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0},
{0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0},
{0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0},
{0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0},
{0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0},
{0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0},
{0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0}
};
unsigned int blocSize = 32;
for (unsigned int y = 0 ; y < vecMap.size() ; y++)
{
for (unsigned int x = 0 ; x < vecMap[y].size() ; x++)
{
if (vecMap[y][x])
{
sf::VertexArray quad(sf::Quads, 4);
quad[0].position = {x*blocSize, y*blocSize};
quad[1].position = {x*blocSize+blocSize, y*blocSize};
quad[2].position = {x*blocSize+blocSize, y*blocSize+blocSize};
quad[3].position = {x*blocSize, y*blocSize+blocSize};
for (unsigned int c = 0 ; c < 4 ; c++)
x%2 ? quad[c].color = sf::Color::Red : quad[c].color = sf::Color::Blue;
vecQuads.push_back(quad);
}
}
}
double scale = 200;
while (app.isOpen())
{
sf::Event event;
while (app.pollEvent(event))
{
switch(event.type)
{
case sf::Event::Closed:
app.close();
break;
case sf::Event::KeyReleased:
if (event.key.code == sf::Keyboard::Escape)
app.close();
break;
}
}
render.clear();
for (unsigned int y = 0 ; y < HEIGHTSCREEN ; y++)
{
unsigned int l = 0;
for (unsigned int x = 0 ; x < WIDTHSCREEN ; x++)
{
for (unsigned int i = 0 ; i < vecQuads.size() ; i++)
{
double xDistance = abs(WIDTHSCREEN/2-x);
if (x==vecQuads[i][0].position.x && y>=vecQuads[i][0].position.y && y<= vecQuads[i][3].position.y)
{
vecLines[y][l].position.x = WIDTHSCREEN/2;
vecLines[y][l].position.y = y/2;
vecLines[y][l].color = vecQuads[i][0].color;
if (x<WIDTHSCREEN/2)
vecLines[y][l].position.x = x - (y*xDistance/scale);
if (x>WIDTHSCREEN/2)
vecLines[y][l].position.x = x + (y*xDistance/scale);
l++;
}
if (x==vecQuads[i][1].position.x && y>=vecQuads[i][0].position.y && y<= vecQuads[i][2].position.y)
{
vecLines[y][l].color = vecQuads[i][1].color;
vecLines[y][l].position.y = y/2;
vecLines[y][l].position.x = WIDTHSCREEN/2;
if (x<WIDTHSCREEN/2)
vecLines[y][l].position.x = x - (y*xDistance/scale);
if (x>WIDTHSCREEN/2)
vecLines[y][l].position.x = x + (y*xDistance/scale);
l++;
}
}
}
}
app.clear();
for (auto& vvec : vecQuads)
app.draw(vvec);
for (auto& vvec : vecLines)
render.draw(vvec);
app.display();
render.display();
}
} |