Commit a3c807f0 authored by Миколаенко Вадим Витальевич's avatar Миколаенко Вадим Витальевич
Browse files

Fixed working with SFML

No related merge requests found
Showing with 37 additions and 59 deletions
+37 -59
#include <iostream>
#include <Mesh2d.h>
#include <SFML/Graphics.hpp>
#include<SFML/Window.hpp>
#include "vector"
#include "Mesh2d.h"
#include "cmath"
#include "windows.h"
#include <SFML/Audio.hpp>
#include <vector>
#include <iostream>
#include <array>
#include <numeric>
#include "algorithm"
#include "array"
using namespace std;
bool Triang(std::vector<double>& FrX, std::vector<double>& FrY, std::vector<double>& W, std::vector<ELEMENT>& Elements, std::vector<double>& MeshX, std::vector<double>& MeshY, double mesh_edge_length_param);
int main()
{
int main(){
sf::Clock clock;
auto t1 = clock.getElapsedTime().asSeconds(), t2 = t1;
sf::RenderWindow window(sf::VideoMode(800, 600), "My window");
vector<array<sf::Vertex,2>> lines;
int scale = 4, delta = 70;
std::vector<double> FrX = {20,60,60,20};
std::vector<double> FrY = {20,20,60,60};
std::vector<std::array<sf::Vertex,2>> lines;
for(int el = 0; el < FrX.size(); el++){
FrX[el] = FrX[el] * scale;
}
for(int el = 0; el < FrY.size(); el++){
FrY[el] = FrY[el] * scale;
}
std::vector<double> W;
int frame_node_count = FrX.size();
W.resize(frame_node_count, -1);
std::vector<double> MeshX;
std::vector<double> MeshY;
std::vector<double> FrX = {0,40,40,0}, FrY = { 0,0,40,40 }, W(FrX.size(), -1);
std::vector<double> MeshX, MeshY;
std::vector<ELEMENT> Elements;
sf::Vertex line[2];
t1= clock.getElapsedTime().asSeconds();
Triang(FrX,FrY,W, Elements,MeshX,MeshY,5*scale);
Triang(FrX, FrY, W, Elements, MeshX, MeshY, 5);
t2 = clock.getElapsedTime().asSeconds();
std::cout << "Time elapsed: " << t2 - t1 << std::endl;
// run the program as long as the window is open
while (window.isOpen())
{
for (auto el:Elements) {
line[0] = sf::Vertex(sf::Vector2f(MeshX[el.i], MeshY[el.i]));
line[1] = sf::Vertex(sf::Vector2f(MeshX[el.j], MeshY[el.j]));
window.draw(line, 2, sf::Lines);
line[0] = sf::Vertex(sf::Vector2f(MeshX[el.i], MeshY[el.i]));
line[1] = sf::Vertex(sf::Vector2f(MeshX[el.k], MeshY[el.k]));
window.draw(line, 2, sf::Lines);
line[0] = sf::Vertex(sf::Vector2f(MeshX[el.j], MeshY[el.j]));
line[1] = sf::Vertex(sf::Vector2f(MeshX[el.k], MeshY[el.k]));
window.draw(line, 2, sf::Lines);
// Sleep(20);
window.display();
}
// check all the window's events that were triggered since the last iteration of the loop
const float x_max = *std::max_element(FrX.begin(), FrX.end());
const float y_max = *std::max_element(FrY.begin(), FrY.end());
sf::View view(sf::FloatRect({ 0.0f, 0.0f }, { x_max , y_max }));
view.zoom(1.1);
window.setView(view);
size_t count = 0;
clock.restart();
sf::ConvexShape triagnle{ 3 };
triagnle.setFillColor(sf::Color{ 55,55,55 });
triagnle.setOutlineThickness(-0.1);
triagnle.setOutlineColor(sf::Color::White);
while (window.isOpen()){
sf::Event event;
while (window.pollEvent(event))
{
// "close requested" event: we close the window
if (event.type == sf::Event::Closed)
window.close();
if (clock.getElapsedTime().asSeconds() > 0.1) {
count = std::min(count + 1, Elements.size());
clock.restart();
}
window.display();
window.clear();
for (size_t i = 0; i < count; ++i) {
triagnle.setPoint(0, sf::Vector2f{ (float)MeshX[Elements[i].i], (float)MeshY[Elements[i].i]});
triagnle.setPoint(1, sf::Vector2f{ (float)MeshX[Elements[i].j], (float)MeshY[Elements[i].j] });
triagnle.setPoint(2, sf::Vector2f{ (float)MeshX[Elements[i].k], (float)MeshY[Elements[i].k] });
window.draw(triagnle);
}
window.display();
}
return 0;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment