Compare commits
No commits in common. "e16e3d588e1795c8ceb701cf3e6aabcfb2f22f0f" and "ff12edcdbe371f7364eedbf51025bfdbcfbc2923" have entirely different histories.
e16e3d588e
...
ff12edcdbe
29
Display.cpp
29
Display.cpp
@ -1,29 +0,0 @@
|
|||||||
|
|
||||||
// make sure sfml is installed:
|
|
||||||
// linux - sudo apt-get install libsfml-dev
|
|
||||||
// windows - manual dl from https://www.sfml-dev.org/download.php
|
|
||||||
#include <SFML/Graphics.hpp>
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
#include "Display.h"
|
|
||||||
|
|
||||||
void Display::show()
|
|
||||||
{
|
|
||||||
sf::RenderWindow window(sf::VideoMode(WIDTH, HEIGHT), "SFML works!");
|
|
||||||
sf::CircleShape shape(100.f);
|
|
||||||
shape.setFillColor(sf::Color::Green);
|
|
||||||
|
|
||||||
while (window.isOpen())
|
|
||||||
{
|
|
||||||
sf::Event event;
|
|
||||||
while (window.pollEvent(event))
|
|
||||||
{
|
|
||||||
if (event.type == sf::Event::Closed)
|
|
||||||
window.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
window.clear();
|
|
||||||
window.draw(shape);
|
|
||||||
window.display();
|
|
||||||
}
|
|
||||||
}
|
|
13
Display.h
13
Display.h
@ -1,13 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#define WIDTH 800
|
|
||||||
#define HEIGHT 600
|
|
||||||
|
|
||||||
class Display
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
void show();
|
|
||||||
|
|
||||||
// TODO:
|
|
||||||
// setData for used stuff... current triangle, all points, ladida...
|
|
||||||
};
|
|
20
Point.h
20
Point.h
@ -1,20 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
class Point
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
float m_x, m_y;
|
|
||||||
|
|
||||||
public:
|
|
||||||
Point(float x, float y) : m_x(x), m_y(y) {}
|
|
||||||
|
|
||||||
float x()
|
|
||||||
{
|
|
||||||
return m_x;
|
|
||||||
}
|
|
||||||
|
|
||||||
float y()
|
|
||||||
{
|
|
||||||
return m_y;
|
|
||||||
}
|
|
||||||
};
|
|
87
main.cpp
87
main.cpp
@ -1,82 +1,29 @@
|
|||||||
#include <iostream> // cin, cout
|
// make sure sfml is installed:
|
||||||
#include <fstream> // ifstream
|
// linux - sudo apt-get install libsfml-dev
|
||||||
#include <cstdlib> // srand, rand
|
// windows - manual dl from https://www.sfml-dev.org/download.php
|
||||||
#include <ctime> // time
|
#include <SFML/Graphics.hpp>
|
||||||
#include <cstring> // strcmp
|
|
||||||
#include <vector> // TODO: or use arrays for maximum performance?
|
|
||||||
|
|
||||||
#include "Display.h"
|
|
||||||
#include "Point.h" // TODO: check if there is a usable SFML or c++ class
|
|
||||||
#include "Timing.h"
|
#include "Timing.h"
|
||||||
|
|
||||||
int main (int argc, char **argv)
|
int main()
|
||||||
{
|
{
|
||||||
// read program arguments
|
sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
|
||||||
// -v mode with enabled visualization
|
sf::CircleShape shape(100.f);
|
||||||
// -f <filename> read random numbers from file
|
shape.setFillColor(sf::Color::Green);
|
||||||
// TODO: care a little more <3
|
|
||||||
std::string fileRnd = "";
|
|
||||||
bool vis = false;
|
|
||||||
for (int i = 0; i < argc; ++i)
|
|
||||||
{
|
|
||||||
if (strcmp(argv[i], "-v") == 0) vis = true;
|
|
||||||
else if (strcmp(argv[i], "-f") == 0) fileRnd = argv[i + 1];
|
|
||||||
}
|
|
||||||
|
|
||||||
int valCount = 10;
|
while (window.isOpen())
|
||||||
std::vector<Point> points;
|
|
||||||
if (fileRnd.empty()) // generate random numbers
|
|
||||||
{
|
{
|
||||||
std::cout << "generating random numbers..." << std::endl;
|
sf::Event event;
|
||||||
//srand(static_cast <unsigned> (time(0)));
|
while (window.pollEvent(event))
|
||||||
srand(static_cast <unsigned> (0)); // fixed seed for testing
|
|
||||||
for (int i = 0; i < valCount; ++i)
|
|
||||||
{
|
{
|
||||||
float x = static_cast <float> (rand()) / (static_cast <float> (RAND_MAX / WIDTH));
|
if (event.type == sf::Event::Closed)
|
||||||
float y = static_cast <float> (rand()) / (static_cast <float> (RAND_MAX / HEIGHT));
|
window.close();
|
||||||
points.push_back(Point(x, y));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else // read random numbers
|
|
||||||
{
|
|
||||||
std::cout << "reading random numbers from file: " << fileRnd << "..." << std::endl;
|
|
||||||
std::ifstream in(fileRnd.c_str());
|
|
||||||
if (in.is_open())
|
|
||||||
{
|
|
||||||
std::string line;
|
|
||||||
std::getline(in, line); // get first line for explizit valueCount
|
|
||||||
valCount = std::stoi(line);
|
|
||||||
for (int i = 0; i < valCount; ++i)
|
|
||||||
{
|
|
||||||
getline(in, line);
|
|
||||||
//getline(in, line, ','); // could also be used slightly different but includes newlines :/
|
|
||||||
size_t pos = line.find(',');
|
|
||||||
if (pos != std::string::npos)
|
|
||||||
{
|
|
||||||
float x = std::stof(line.substr(0, pos));
|
|
||||||
float y = std::stof(line.substr(pos + 1));
|
|
||||||
points.push_back(Point(x, y));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw "invalid format!";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
window.clear();
|
||||||
|
window.draw(shape);
|
||||||
|
window.display();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Point& pt : points)
|
|
||||||
{
|
|
||||||
std::cout << "pt: " << pt.x() << ", " << pt.y() << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (vis)
|
|
||||||
{
|
|
||||||
Display display;
|
|
||||||
display.show();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::cout << "any key to exit...";
|
|
||||||
std::cin.get();
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user