changed src so the libpg headers are now used
[physics.git] / src / Entities / Polygon.cpp
index 42cfbdb..9f2eff6 100644 (file)
 
 #include "Polygon.h"
 
-#include "Vector2.h"
+#include <pg/debug.h>
+#include <pg/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].m_fX < minP.m_fX) minP.m_fX = points[i].m_fX;
+        else if(points[i].m_fX > 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
 }