named members m_* to quite -Wshadow
[physics.git] / src / Entities / Polygon.cpp
index 085c6e2..9f1aa43 100644 (file)
@@ -1,14 +1,38 @@
+/*
+ *  Copyright (C) 2008 Patrik Gornicz, Gornicz_P (at) hotmail (dot) com.
+ *
+ *  This program is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
 #include "Polygon.h"
 
-#include "../Vector2.h"
+#include <bear/debug.h>
+#include <bear/Vector2.h>
+using namespace bear;
+
+#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)), m_points(points), m_color(color)
 {
+    DASSERT(0 < points.size());
+
     createBindingBox();
+    centerPosition();
 }
 Polygon::~Polygon()
 {
@@ -19,11 +43,28 @@ Polygon::~Polygon()
 
 void Polygon::draw() const
 {
-    // TODO
+    graphics::drawPolygon(m_points, m_color);
 }
 
 /// ***** Private Class Methods *****
 void Polygon::createBindingBox()
 {
+    DASSERT(0 < m_points.size());
+
+    m_maxP = m_points.at(0);
+    m_minP = m_points.at(0);
+
+    for(unsigned int i=1; i<m_points.size(); i++)
+    {
+             if(m_points[i].m_fX < m_minP.m_fX) m_minP.m_fX = m_points[i].m_fX;
+        else if(m_points[i].m_fX > m_maxP.m_fX) m_maxP.m_fX = m_points[i].m_fX;
+
+             if(m_points[i].m_fY < m_minP.m_fY) m_minP.m_fY = m_points[i].m_fY;
+        else if(m_points[i].m_fY > m_maxP.m_fY) m_maxP.m_fY = m_points[i].m_fY;
+    }
+}
+
+void Polygon::centerPosition()
+{
     // TODO
 }