*/
#include "Polygon.h"
+#include "debug.h"
#include "Vector2.h"
+#include "graphics/graphics.h"
+
/// ***** Constructors/Destructors *****
-Polygon::Polygon(const Vector2& pos, vector<Vector2> points)
- : PhysicsEntity(pos), points(points)
+Polygon::Polygon(const vector<Vector2>& points)
+ : PhysicsEntity(Vector2(0,0)), points(points)
{
+ DASSERT(0 < points.size());
+
createBindingBox();
+ centerPosition();
}
Polygon::~Polygon()
{
void Polygon::draw() const
{
- // TODO
+ graphics::drawPolygon(points);
}
/// ***** Private Class Methods *****
void Polygon::createBindingBox()
{
+ DASSERT(0 < points.size());
+
+ maxP = points.at(0);
+ minP = points.at(0);
+
+ for(unsigned int i=1; i<points.size(); i++)
+ {
+ if(points[i].x < minP.x) minP.x = points[i].x;
+ else if(points[i].x > maxP.x) maxP.x = points[i].x;
+
+ if(points[i].y < minP.y) minP.y = points[i].y;
+ else if(points[i].y > maxP.y) maxP.y = points[i].y;
+ }
+}
+
+void Polygon::centerPosition()
+{
// TODO
}