projects
/
physics.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
002fd13
)
hacks that make a polygon draw
author
Patrik Gornicz
<Gornicz.P@gmail.com>
Tue, 20 Jan 2009 03:57:36 +0000
(22:57 -0500)
committer
Patrik Gornicz
<Gornicz.P@gmail.com>
Tue, 20 Jan 2009 03:57:36 +0000
(22:57 -0500)
src/Entities/Polygon.cpp
patch
|
blob
|
blame
|
history
src/Entities/Polygon.h
patch
|
blob
|
blame
|
history
src/entityCreator.cpp
patch
|
blob
|
blame
|
history
src/graphics/graphics.cpp
patch
|
blob
|
blame
|
history
src/graphics/graphics.h
patch
|
blob
|
blame
|
history
diff --git
a/src/Entities/Polygon.cpp
b/src/Entities/Polygon.cpp
index
42cfbdb
..
bf2fb00
100644
(file)
--- a/
src/Entities/Polygon.cpp
+++ b/
src/Entities/Polygon.cpp
@@
-16,15
+16,20
@@
*/
#include "Polygon.h"
*/
#include "Polygon.h"
+#include "debug.h"
#include "Vector2.h"
#include "Vector2.h"
+#include "graphics/graphics.h"
+
/// ***** Constructors/Destructors *****
/// ***** 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()
createBindingBox();
}
Polygon::~Polygon()
@@
-36,7
+41,7
@@
Polygon::~Polygon()
void Polygon::draw() const
{
void Polygon::draw() const
{
- // TODO
+ graphics::drawPolygon(points);
}
/// ***** Private Class Methods *****
}
/// ***** Private Class Methods *****
diff --git
a/src/Entities/Polygon.h
b/src/Entities/Polygon.h
index
5d8d10d
..
b8c8493
100644
(file)
--- a/
src/Entities/Polygon.h
+++ b/
src/Entities/Polygon.h
@@
-30,7
+30,7
@@
using std::vector;
class Polygon: public PhysicsEntity
{
public:
class Polygon: public PhysicsEntity
{
public:
- Polygon(const
Vector2&, vector<Vector2>
);
+ Polygon(const
vector<Vector2>&
);
virtual ~Polygon();
virtual void draw() const;
virtual ~Polygon();
virtual void draw() const;
diff --git
a/src/entityCreator.cpp
b/src/entityCreator.cpp
index
2df4457
..
1b4b6f7
100644
(file)
--- a/
src/entityCreator.cpp
+++ b/
src/entityCreator.cpp
@@
-23,6
+23,7
@@
#include "input/inputManager.h"
#include "Entities/Ball.h"
#include "input/inputManager.h"
#include "Entities/Ball.h"
+#include "Entities/Polygon.h"
#include "graphics/colors.h"
#include "graphics/colors.h"
@@
-78,6
+79,14
@@
void creator::init()
{
addBall(Vector2(200+i*2, 200+i*2), 10, cCyan);
}
{
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()
{
}
void creator::clean()
{
diff --git
a/src/graphics/graphics.cpp
b/src/graphics/graphics.cpp
index
537cdc8
..
d89db8a
100644
(file)
--- a/
src/graphics/graphics.cpp
+++ b/
src/graphics/graphics.cpp
@@
-34,6
+34,7
@@
using std::endl;
/// ***** Private Method Headers *****
void glDrawCircle(int);
/// ***** Private Method Headers *****
void glDrawCircle(int);
+void glDrawPolygon( const std::vector<Vector2>& points );
void sdlInit();
void glInit();
void sdlInit();
void glInit();
@@
-65,6
+66,21
@@
void graphics::drawCircle(float radius, const Vector2& pos, const float* color)
glDrawCircle(32);
}
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)
/// ***** Private Methods *****
void glDrawCircle(int pieces)
@@
-81,6
+97,18
@@
void glDrawCircle(int pieces)
glEnd();
}
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)
void sdlInit()
{
if(SDL_Init(SDL_INIT_VIDEO) < 0)
diff --git
a/src/graphics/graphics.h
b/src/graphics/graphics.h
index
1f23760
..
aa87e1b
100644
(file)
--- a/
src/graphics/graphics.h
+++ b/
src/graphics/graphics.h
@@
-19,6
+19,7
@@
#define GRAPHICS_H
#include "Vector2.h"
#define GRAPHICS_H
#include "Vector2.h"
+#include <vector>
/// ***** Header Methods *****
/// ***** Header Methods *****
@@
-29,6
+30,7
@@
namespace graphics
void clean();
void drawCircle(float radius, const Vector2&, const float* color = 0);
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
}
#endif // GRAPHICS_H