113 lines
2.6 KiB
C++
113 lines
2.6 KiB
C++
|
/**
|
||
|
* @author Tyler Beckman (tyler_beckman@mines.edu)
|
||
|
* @brief A program template for CSCI200
|
||
|
* @version 1
|
||
|
* @date 2024-09-21
|
||
|
*/
|
||
|
|
||
|
#include "Coordinate.h"
|
||
|
#include "EquilateralTriangle.h"
|
||
|
#include "IsoscelesTriangle.h"
|
||
|
#include "Polygon.h"
|
||
|
#include "Rhombus.h"
|
||
|
#include "ScaleneTriangle.h"
|
||
|
|
||
|
#include <fstream>
|
||
|
#include <iostream>
|
||
|
|
||
|
#include <cstdio>
|
||
|
|
||
|
#include <SFML/Graphics/Color.hpp>
|
||
|
|
||
|
int main(void) {
|
||
|
// Start file parsing logic
|
||
|
std::cout << "Please enter file path to read polygons from: ";
|
||
|
std::string filePath;
|
||
|
std::cin >> filePath;
|
||
|
|
||
|
std::ifstream file(filePath);
|
||
|
if (file.fail()) {
|
||
|
std::cout << "Failed to open specified file path " << filePath
|
||
|
<< ", does it exist?" << std::endl;
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
|
std::vector<APolygon *> polygonList;
|
||
|
APolygon *currentPolygon;
|
||
|
char type;
|
||
|
double x1, y1, x2, y2, x3, y3, x4, y4;
|
||
|
int r, g, b;
|
||
|
|
||
|
while (true) {
|
||
|
file >> type >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
|
||
|
if (type == 'R') {
|
||
|
file >> x4 >> y4;
|
||
|
}
|
||
|
file >> r >> g >> b;
|
||
|
|
||
|
if (file.fail()) {
|
||
|
break;
|
||
|
}
|
||
|
|
||
|
switch (type) {
|
||
|
case 'S':
|
||
|
currentPolygon = new ScaleneTriangle;
|
||
|
break;
|
||
|
case 'I':
|
||
|
currentPolygon = new IsoscelesTriangle;
|
||
|
break;
|
||
|
case 'E':
|
||
|
currentPolygon = new EquilateralTriangle;
|
||
|
break;
|
||
|
case 'R':
|
||
|
currentPolygon = new Rhombus;
|
||
|
break;
|
||
|
default:
|
||
|
std::cout << "polygon is invalid - \"" << type << " " << x1
|
||
|
<< " " << y1 << " " << x2 << " " << y2 << " " << x3
|
||
|
<< " " << y3 << " " << x4 << " " << y4 << " " << r
|
||
|
<< " " << g << " " << b << "\"" << std::endl;
|
||
|
continue;
|
||
|
}
|
||
|
|
||
|
currentPolygon->setCoordinate(0, Coordinate(x1, y1));
|
||
|
currentPolygon->setCoordinate(1, Coordinate(x2, y2));
|
||
|
currentPolygon->setCoordinate(2, Coordinate(x3, y3));
|
||
|
if (type == 'R') {
|
||
|
currentPolygon->setCoordinate(3, Coordinate(x4, y4));
|
||
|
}
|
||
|
currentPolygon->setColor(sf::Color(r, g, b));
|
||
|
|
||
|
if (!currentPolygon->validate()) {
|
||
|
std::cout << "polygon is invalid - \"" << type << " " << x1 << " "
|
||
|
<< y1 << " " << x2 << " " << y2 << " " << x3 << " " << y3
|
||
|
<< " " << x4 << " " << y4 << " " << r << " " << g << " "
|
||
|
<< b << "\"" << std::endl;
|
||
|
} else {
|
||
|
polygonList.push_back(currentPolygon);
|
||
|
}
|
||
|
};
|
||
|
|
||
|
// Start SFML Rendering logic
|
||
|
sf::RenderWindow window( sf::VideoMode(640, 640), ":3" );
|
||
|
window.setVerticalSyncEnabled(true);
|
||
|
|
||
|
sf::Event event;
|
||
|
|
||
|
while (window.isOpen()) {
|
||
|
window.clear();
|
||
|
|
||
|
for (size_t i = 0; i < polygonList.size(); i++) {
|
||
|
polygonList.at(i)->draw(window);
|
||
|
}
|
||
|
|
||
|
window.display();
|
||
|
|
||
|
while (window.pollEvent(event)) {
|
||
|
if (event.type == sf::Event::Closed) {
|
||
|
window.close();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|