hacks that make a polygon draw
authorPatrik Gornicz <Gornicz.P@gmail.com>
Tue, 20 Jan 2009 03:57:36 +0000 (22:57 -0500)
committerPatrik Gornicz <Gornicz.P@gmail.com>
Tue, 20 Jan 2009 03:57:36 +0000 (22:57 -0500)
src/Entities/Polygon.cpp
src/Entities/Polygon.h
src/entityCreator.cpp
src/graphics/graphics.cpp
src/graphics/graphics.h

index 42cfbdb..bf2fb00 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)
+    : PhysicsEntity(Vector2(0,0)), points(points)
 {
+    DASSERT(0 < points.size());
+
     createBindingBox();
 }
 Polygon::~Polygon()
@@ -36,7 +41,7 @@ Polygon::~Polygon()
 
 void Polygon::draw() const
 {
-    // TODO
+    graphics::drawPolygon(points);
 }
 
 /// ***** Private Class Methods *****
index 5d8d10d..b8c8493 100644 (file)
@@ -30,7 +30,7 @@ using std::vector;
 class Polygon: public PhysicsEntity
 {
     public:
-        Polygon(const Vector2&, vector<Vector2>);
+        Polygon(const vector<Vector2>&);
         virtual ~Polygon();
 
         virtual void draw() const;
index 2df4457..1b4b6f7 100644 (file)
@@ -23,6 +23,7 @@
 #include "input/inputManager.h"
 
 #include "Entities/Ball.h"
+#include "Entities/Polygon.h"
 #include "graphics/colors.h"
 
 
@@ -78,6 +79,14 @@ void creator::init()
     {
         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()
 {
index 537cdc8..d89db8a 100644 (file)
@@ -34,6 +34,7 @@ using std::endl;
 /// ***** Private Method Headers *****
 
 void glDrawCircle(int);
+void glDrawPolygon( const std::vector<Vector2>& points );
 void sdlInit();
 void glInit();
 
@@ -65,6 +66,21 @@ void graphics::drawCircle(float radius, const Vector2& pos, const float* color)
     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)
@@ -81,6 +97,18 @@ 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)
index 1f23760..aa87e1b 100644 (file)
@@ -19,6 +19,7 @@
 #define GRAPHICS_H
 
 #include "Vector2.h"
+#include <vector>
 
 
 /// ***** Header Methods *****
@@ -29,6 +30,7 @@ namespace graphics
     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