X-Git-Url: http://gitweb.pgornicz.com/gitweb.cgi?a=blobdiff_plain;f=src%2FEntities%2FPolygon.cpp;h=4b3826e68f06b014feaf0c08bb6ff895e004ea5d;hb=5e0713e5967be038b1b0cc5f0ffbd0180e3f7099;hp=18615714f3254a885d75a79ebda5fc64ecb70fbf;hpb=e68f847b245153427266841ae724d602ca434c29;p=physics.git diff --git a/src/Entities/Polygon.cpp b/src/Entities/Polygon.cpp index 1861571..4b3826e 100644 --- a/src/Entities/Polygon.cpp +++ b/src/Entities/Polygon.cpp @@ -17,15 +17,22 @@ #include "Polygon.h" -#include "../Vector2.h" +#include +#include +using namespace bear; + +#include "graphics/graphics.h" /// ***** Constructors/Destructors ***** -Polygon::Polygon(const Vector2& pos, vector points) - : PhysicsEntity(pos), 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() { @@ -36,11 +43,28 @@ Polygon::~Polygon() void Polygon::draw() const { - // TODO + 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 }