X-Git-Url: http://gitweb.pgornicz.com/gitweb.cgi?a=blobdiff_plain;f=src%2FEntities%2FPolygon.cpp;h=4b3826e68f06b014feaf0c08bb6ff895e004ea5d;hb=5e0713e5967be038b1b0cc5f0ffbd0180e3f7099;hp=bf2fb0021bd8f6c70bb54024a8f54a36fb99dc53;hpb=4a76d2e2cf7874e54a4e6688ebf1fa8ca59ce8c1;p=physics.git diff --git a/src/Entities/Polygon.cpp b/src/Entities/Polygon.cpp index bf2fb00..4b3826e 100644 --- a/src/Entities/Polygon.cpp +++ b/src/Entities/Polygon.cpp @@ -16,21 +16,23 @@ */ #include "Polygon.h" -#include "debug.h" -#include "Vector2.h" +#include +#include +using namespace bear; #include "graphics/graphics.h" /// ***** Constructors/Destructors ***** -Polygon::Polygon(const vector& points) - : PhysicsEntity(Vector2(0,0)), points(points) +Polygon::Polygon(const vector& points, const float* color) + : PhysicsEntity(Vector2(0,0)), points(points), color(color) { DASSERT(0 < points.size()); createBindingBox(); + centerPosition(); } Polygon::~Polygon() { @@ -41,11 +43,28 @@ Polygon::~Polygon() void Polygon::draw() const { - graphics::drawPolygon(points); + graphics::drawPolygon(points, color); } /// ***** Private Class Methods ***** void Polygon::createBindingBox() { + DASSERT(0 < points.size()); + + maxP = points.at(0); + minP = points.at(0); + + for(unsigned int i=1; i maxP.m_fX) maxP.m_fX = points[i].m_fX; + + if(points[i].m_fY < minP.m_fY) minP.m_fY = points[i].m_fY; + else if(points[i].m_fY > maxP.m_fY) maxP.m_fY = points[i].m_fY; + } +} + +void Polygon::centerPosition() +{ // TODO }