Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2008-03-06 22:07:10 +0000
committerStijn Buys <ingar@osirion.org>2008-03-06 22:07:10 +0000
commit6ade6c1c346743b8432600485e28682e276cfbd0 (patch)
treec0735c3c7d853a42927f97d277960568562d0163 /src/core
parent0af232b6f1b17271338a278783b4270a83e8897f (diff)
moved render::Face to core::Face
Diffstat (limited to 'src/core')
-rw-r--r--src/core/face.cc53
-rw-r--r--src/core/face.h43
2 files changed, 96 insertions, 0 deletions
diff --git a/src/core/face.cc b/src/core/face.cc
new file mode 100644
index 0000000..31b7fcc
--- /dev/null
+++ b/src/core/face.cc
@@ -0,0 +1,53 @@
+/*
+ render/face.cc
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
+*/
+
+#include "render/face.h"
+#include "render/gl.h"
+
+namespace render {
+
+Face::Face(math::Vector3f const & normal, math::Color const *color) :
+ face_normal(normal)
+{
+ face_normal.normalize();
+
+ if (color)
+ face_color = new math::Color(*color);
+ else
+ face_color = 0;
+}
+
+Face::~Face()
+{
+ for (std::vector<math::Vector3f *>::iterator it = face_vertex.begin(); it != face_vertex.end(); it++) {
+ delete (*it);
+ }
+
+ face_vertex.clear();
+
+ if (face_color)
+ delete face_color;
+}
+
+void Face::add_vertex(math::Vector3f const & vertex)
+{
+ math::Vector3f *v = new math::Vector3f(vertex);
+
+ face_vertex.push_back(v);
+}
+
+void Face::draw()
+{
+ //gl::begin(gl::LineLoop);
+ gl::begin(gl::Polygon);
+ gl::normal(face_normal); // face_normal already has unit lenght
+ for (std::vector<math::Vector3f *>::iterator it = face_vertex.begin(); it != face_vertex.end(); it++) {
+ gl::vertex(*(*it));
+ }
+ gl::end();
+}
+
+}
diff --git a/src/core/face.h b/src/core/face.h
new file mode 100644
index 0000000..a0a4d5a
--- /dev/null
+++ b/src/core/face.h
@@ -0,0 +1,43 @@
+/*
+ render/face.h
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
+*/
+
+#ifndef __INCLUDED_RENDER_FACE_H__
+#define __INCLUDED_RENDER_FACE_H__
+
+#include <vector>
+
+#include "math/mathlib.h"
+
+namespace render {
+
+/// one face (polygon) of a model
+class Face {
+public:
+ Face(math::Vector3f const & normal, math::Color const *color=0);
+ ~Face();
+
+ /// the normal of this face
+ inline math::Vector3f const & normal() const { return face_normal; };
+
+ /// the color of this face
+ inline math::Color const *color() const { return face_color; };
+
+ /// add a vertex to the face
+ void add_vertex(math::Vector3f const &vertex);
+
+ /// draw the polygon
+ void draw();
+
+private:
+ math::Vector3f face_normal;
+ math::Color *face_color;
+ std::vector<math::Vector3f *> face_vertex;
+};
+
+}
+
+#endif // __INCLUDED_RENDER_FACE_H__
+