30 lines
701 B
C++
30 lines
701 B
C++
#include "Polygon.h"
|
|
|
|
#include "Coordinate.h"
|
|
|
|
#include <SFML/Graphics/ConvexShape.hpp>
|
|
#include <SFML/Graphics/RenderTarget.hpp>
|
|
|
|
APolygon::APolygon() {
|
|
_color = sf::Color::White;
|
|
mNumVertices = 0;
|
|
mVertices = nullptr;
|
|
}
|
|
|
|
APolygon::~APolygon() { delete[] mVertices; }
|
|
|
|
void APolygon::setColor(const sf::Color COLOR) { _color = COLOR; }
|
|
|
|
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);
|
|
|
|
window.draw(shape);
|
|
}
|
|
|
|
void APolygon::setCoordinate(const int IDX, const Coordinate COORD) {
|
|
mVertices[IDX] = COORD;
|
|
}
|