*/
#include "Polygon.h"
-#include "debug.h"
-#include "Vector2.h"
+#include <pg/debug.h>
+#include <pg/Vector2.h>
#include "graphics/graphics.h"
/// ***** Constructors/Destructors *****
-Polygon::Polygon(const vector<Vector2>& points)
- : PhysicsEntity(Vector2(0,0)), 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()
{
void Polygon::draw() const
{
- graphics::drawPolygon(points);
+ 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
}