*/
#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();
}
Polygon::~Polygon()
void Polygon::draw() const
{
- // TODO
+ graphics::drawPolygon(points);
}
/// ***** Private Class Methods *****
class Polygon: public PhysicsEntity
{
public:
- Polygon(const Vector2&, vector<Vector2>);
+ Polygon(const vector<Vector2>&);
virtual ~Polygon();
virtual void draw() const;
#include "input/inputManager.h"
#include "Entities/Ball.h"
+#include "Entities/Polygon.h"
#include "graphics/colors.h"
{
addBall(Vector2(200+i*2, 200+i*2), 10, cCyan);
}
+
+ // add a polygon into the mix (currently not cleaned up)
+ vector<Vector2> points;
+ points.push_back(Vector2(50,50));
+ points.push_back(Vector2(50,100));
+ points.push_back(Vector2(100,50));
+
+ manager::add(new Polygon(points));
}
void creator::clean()
{
/// ***** Private Method Headers *****
void glDrawCircle(int);
+void glDrawPolygon( const std::vector<Vector2>& points );
void sdlInit();
void glInit();
glDrawCircle(32);
}
+void graphics::drawPolygon
+(
+ const std::vector<Vector2>& points,
+ const float* color
+)
+{
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+
+ if(color != NULL)
+ glColor3fv(color);
+
+ glDrawPolygon(points);
+}
+
/// ***** Private Methods *****
void glDrawCircle(int pieces)
glEnd();
}
+void glDrawPolygon( const std::vector<Vector2>& points )
+{
+ glBegin(GL_POLYGON);
+ for(unsigned int n = 0; n < points.size(); n++)
+ {
+ const Vector2& vec = points.at(n);
+
+ glVertex3f(vec.x, vec.y, 0);
+ }
+ glEnd();
+}
+
void sdlInit()
{
if(SDL_Init(SDL_INIT_VIDEO) < 0)
#define GRAPHICS_H
#include "Vector2.h"
+#include <vector>
/// ***** Header Methods *****
void clean();
void drawCircle(float radius, const Vector2&, const float* color = 0);
+ void drawPolygon(const std::vector<Vector2>& points, const float* color = 0);
}
#endif // GRAPHICS_H