added color to polygons
[physics.git] / src / Entities / Polygon.cpp
index 42cfbdb..ecaf2c4 100644 (file)
  */
 
 #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, const float* color)
+    : PhysicsEntity(Vector2(0,0)), points(points), color(color)
 {
+    DASSERT(0 < points.size());
+
     createBindingBox();
+    centerPosition();
 }
 Polygon::~Polygon()
 {
@@ -36,11 +42,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<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
 }