2024-11-18 00:16:40 -07:00
|
|
|
#include "Polygon.h"
|
2024-11-06 17:02:59 -07:00
|
|
|
|
|
|
|
#include "Coordinate.h"
|
2024-11-18 00:16:40 -07:00
|
|
|
|
|
|
|
#include <SFML/Graphics/ConvexShape.hpp>
|
|
|
|
#include <SFML/Graphics/RenderTarget.hpp>
|
2024-11-06 17:02:59 -07:00
|
|
|
|
|
|
|
APolygon::APolygon() {
|
2024-11-18 00:18:28 -07:00
|
|
|
_color = sf::Color::White;
|
|
|
|
mNumVertices = 0;
|
|
|
|
mVertices = nullptr;
|
2024-11-06 17:02:59 -07:00
|
|
|
}
|
|
|
|
|
2024-11-18 00:16:40 -07:00
|
|
|
APolygon::~APolygon() { delete[] mVertices; }
|
2024-11-06 17:02:59 -07:00
|
|
|
|
2024-11-18 00:16:40 -07:00
|
|
|
void APolygon::setColor(const sf::Color COLOR) { _color = COLOR; }
|
2024-11-06 17:02:59 -07:00
|
|
|
|
2024-11-18 00:18:28 -07:00
|
|
|
void APolygon::draw(sf::RenderTarget& window) {
|
|
|
|
sf::ConvexShape shape(mNumVertices);
|
|
|
|
for (int i = 0; i < mNumVertices; i++) {
|
|
|
|
shape.setPoint(i, sf::Vector2f(mVertices[i].x, mVertices[i].y));
|
|
|
|
}
|
|
|
|
shape.setFillColor(_color);
|
2024-11-06 17:02:59 -07:00
|
|
|
|
2024-11-18 00:18:28 -07:00
|
|
|
window.draw(shape);
|
2024-11-06 17:02:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void APolygon::setCoordinate(const int IDX, const Coordinate COORD) {
|
2024-11-18 00:18:28 -07:00
|
|
|
mVertices[IDX] = COORD;
|
2024-11-06 17:02:59 -07:00
|
|
|
}
|