summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/Data/Room.cpp62
-rw-r--r--src/Data/Room.h12
-rw-r--r--src/Data/Triangle.cpp2
-rw-r--r--src/Gui/RenderArea.cpp8
-rw-r--r--src/Gui/RenderArea.h13
-rw-r--r--src/Gui/Window.h2
-rw-r--r--src/Instance.cpp27
-rw-r--r--src/Instance.h6
-rw-r--r--src/View/TopView.cpp31
-rw-r--r--src/View/TopView.h10
-rw-r--r--src/View/View.h12
11 files changed, 131 insertions, 54 deletions
diff --git a/src/Data/Room.cpp b/src/Data/Room.cpp
index acc79be..b1d7473 100644
--- a/src/Data/Room.cpp
+++ b/src/Data/Room.cpp
@@ -23,8 +23,36 @@
namespace ZoomEdit {
namespace Data {
+void Room::populateTriangle(xmlpp::Element *tNode) {
+ xmlpp::Element *node = tNode->add_child("vertex");
+ node->set_attribute("x", "0.0");
+ node->set_attribute("y", "0.0");
+ node->set_attribute("z", "0.0");
+
+ node = tNode->add_child("vertex");
+ node->set_attribute("x", "0.0");
+ node->set_attribute("y", "0.0");
+ node->set_attribute("z", "0.0");
+
+ node = tNode->add_child("vertex");
+ node->set_attribute("x", "0.0");
+ node->set_attribute("y", "0.0");
+ node->set_attribute("z", "0.0");
+}
+
Room::Room(xmlpp::Element *node) : roomNode(node) {
- xmlpp::Node::NodeList triangleList = node->get_children("triangle");
+ floorNode = dynamic_cast<xmlpp::Element*>(node->get_children("floor").front());
+
+ xmlpp::Node::NodeList triangleList = floorNode->get_children("triangle");
+
+ for(xmlpp::Node::NodeList::iterator t = triangleList.begin(); t != triangleList.end(); ++t) {
+ xmlpp::Element *tNode = dynamic_cast<xmlpp::Element*>(*t);
+
+ if(tNode)
+ floor.push_back(new Triangle(tNode));
+ }
+
+ triangleList = node->get_children("triangle");
for(xmlpp::Node::NodeList::iterator t = triangleList.begin(); t != triangleList.end(); ++t) {
xmlpp::Element *tNode = dynamic_cast<xmlpp::Element*>(*t);
@@ -44,20 +72,7 @@ Room::~Room() {
Triangle* Room::addTriangle() {
xmlpp::Element *tNode = roomNode->add_child("triangle");
- xmlpp::Element *node = tNode->add_child("vertex");
- node->set_attribute("x", "0.0");
- node->set_attribute("y", "0.0");
- node->set_attribute("z", "0.0");
-
- node = tNode->add_child("vertex");
- node->set_attribute("x", "0.0");
- node->set_attribute("y", "0.0");
- node->set_attribute("z", "0.0");
-
- node = tNode->add_child("vertex");
- node->set_attribute("x", "0.0");
- node->set_attribute("y", "0.0");
- node->set_attribute("z", "0.0");
+ populateTriangle(tNode);
Triangle *t = new Triangle(tNode);
triangles.push_back(t);
@@ -71,5 +86,22 @@ void Room::removeTriangle(Triangle *t) {
delete t;
}
+Triangle* Room::addFloorTriangle() {
+ xmlpp::Element *tNode = floorNode->add_child("triangle");
+
+ populateTriangle(tNode);
+
+ Triangle *t = new Triangle(tNode);
+ floor.push_back(t);
+
+ return t;
+}
+
+void Room::removeFloorTriangle(Triangle *t) {
+ floorNode->remove_child(t->getNode());
+ floor.remove(t);
+ delete t;
+}
+
}
}
diff --git a/src/Data/Room.h b/src/Data/Room.h
index e290e36..b23923b 100644
--- a/src/Data/Room.h
+++ b/src/Data/Room.h
@@ -33,8 +33,13 @@ class Room {
std::list<Triangle*> triangles;
xmlpp::Element *roomNode;
+ std::list<Triangle*> floor;
+ xmlpp::Element *floorNode;
+
Glib::ustring id;
+ void populateTriangle(xmlpp::Element *tNode);
+
// Prevent shallow copy
Room(const Room &o);
Room& operator=(const Room &o);
@@ -50,6 +55,13 @@ class Room {
Triangle* addTriangle();
void removeTriangle(Triangle *t);
+ const std::list<Triangle*>& getFloorTriangles() const {
+ return floor;
+ }
+
+ Triangle* addFloorTriangle();
+ void removeFloorTriangle(Triangle *t);
+
const Glib::ustring& getId() const {
return id;
}
diff --git a/src/Data/Triangle.cpp b/src/Data/Triangle.cpp
index 096081b..b3f76a7 100644
--- a/src/Data/Triangle.cpp
+++ b/src/Data/Triangle.cpp
@@ -18,7 +18,7 @@
*/
#include "Triangle.h"
-#include "../Util/Xml.h"
+#include <Util/Xml.h>
#include <cstdlib>
namespace ZoomEdit {
diff --git a/src/Gui/RenderArea.cpp b/src/Gui/RenderArea.cpp
index 39e1e45..7aa2745 100644
--- a/src/Gui/RenderArea.cpp
+++ b/src/Gui/RenderArea.cpp
@@ -18,6 +18,7 @@
*/
#include "RenderArea.h"
+#include <View/View.h>
#include <iostream>
#include <cstdlib>
#include <cmath>
@@ -31,7 +32,7 @@ namespace Gui {
GdkGLConfig *RenderArea::glconfig = 0;
RenderArea::RenderArea(BaseObjectType *cobject, const Glib::RefPtr<Gnome::Glade::Xml> &xml)
-: Gtk::DrawingArea(cobject), xCenter(0), yCenter(0), zoomLevel(0), scale(100) {
+: Gtk::DrawingArea(cobject), view(0), xCenter(0), yCenter(0), zoomLevel(0), scale(100) {
if(!glconfig) {
glconfig = gdk_gl_config_new_by_mode((GdkGLConfigMode)(GDK_GL_MODE_RGB | GDK_GL_MODE_DOUBLE));
if(!glconfig) glconfig = gdk_gl_config_new_by_mode(GDK_GL_MODE_RGB); // Hmm, can't find double buffered config
@@ -101,12 +102,13 @@ bool RenderArea::onExposeEvent(GdkEventExpose*) {
glScalef(scale, scale, 1);
glTranslatef(-xCenter, -yCenter, 0);
-
drawGrid();
+ if(view)
+ view->render();
+
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
-
gdkSwapBuffers();
gdkGLEnd();
diff --git a/src/Gui/RenderArea.h b/src/Gui/RenderArea.h
index 66a8924..123c50f 100644
--- a/src/Gui/RenderArea.h
+++ b/src/Gui/RenderArea.h
@@ -26,18 +26,31 @@
#include <gtk/gtkgl.h>
namespace ZoomEdit {
+
+namespace View {
+class View;
+}
+
namespace Gui {
class RenderArea : public Gtk::DrawingArea {
public:
RenderArea(BaseObjectType *cobject, const Glib::RefPtr<Gnome::Glade::Xml> &xml);
+ View::View* getView() const {return view;}
+ void setView(View::View *view0) {
+ view = view0;
+ queue_draw();
+ }
+
private:
static GdkGLConfig *glconfig;
Gtk::HScrollbar *hScrollbar;
Gtk::VScrollbar *vScrollbar;
+ View::View *view;
+
float xCenter, yCenter;
int zoomLevel;
diff --git a/src/Gui/Window.h b/src/Gui/Window.h
index 92369ce..ae22d42 100644
--- a/src/Gui/Window.h
+++ b/src/Gui/Window.h
@@ -35,6 +35,8 @@ class Window : public Gtk::Window {
public:
Window(BaseObjectType *cobject, const Glib::RefPtr<Gnome::Glade::Xml> &xml);
virtual ~Window();
+
+ RenderArea* getRenderArea() const {return renderArea;}
};
}
diff --git a/src/Instance.cpp b/src/Instance.cpp
index 6d01d99..b54fb32 100644
--- a/src/Instance.cpp
+++ b/src/Instance.cpp
@@ -17,18 +17,20 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include "Instance.h"
#include <iostream>
#include <libxml++/validators/dtdvalidator.h>
#include <libxml/tree.h>
-#include "Instance.h"
-#include "Gui/Window.h"
-#include "Data/Level.h"
+#include <Gui/Window.h>
+#include <Gui/RenderArea.h>
+#include <Data/Level.h>
+#include <View/TopView.h>
namespace ZoomEdit {
guint Instance::instances = 0;
-Instance::Instance(const Glib::ustring &file) : window(0), levelXml(0), level(0) {
+Instance::Instance(const Glib::ustring &file) : window(0), levelXml(0), level(0), view(0) {
instances++;
#ifdef GLIBMM_EXCEPTIONS_ENABLED
@@ -59,6 +61,9 @@ Instance::Instance(const Glib::ustring &file) : window(0), levelXml(0), level(0)
window->signal_hide().connect(sigc::mem_fun(this, &Instance::destroy));
+ view = new View::TopView();
+ window->getRenderArea()->setView(view);
+
if(file.empty())
createLevel();
else
@@ -71,6 +76,9 @@ Instance::~Instance() {
if(window)
delete window;
+ if(view)
+ delete view;
+
if(level)
delete level;
@@ -83,8 +91,10 @@ Instance::~Instance() {
}
void Instance::createLevel() {
- if(level)
+ if(level) {
+ view->setLevel(0);
delete level;
+ }
if(levelXml)
delete levelXml;
@@ -109,10 +119,13 @@ void Instance::createLevel() {
root->add_child("textures");
level = new Data::Level(root);
+
+ view->setLevel(level);
}
bool Instance::loadLevel(const Glib::ustring &file) {
if(level) {
+ view->setLevel(0);
delete level;
level = 0;
}
@@ -131,7 +144,9 @@ bool Instance::loadLevel(const Glib::ustring &file) {
level = new Data::Level(doc->get_root_node());
- return (level != 0);
+ view->setLevel(level);
+
+ return true;
}
bool Instance::saveLevel(const Glib::ustring &file) {
diff --git a/src/Instance.h b/src/Instance.h
index 8c22eb4..a85999a 100644
--- a/src/Instance.h
+++ b/src/Instance.h
@@ -34,6 +34,10 @@ namespace Data {
class Level;
}
+namespace View {
+class TopView;
+}
+
class Instance {
public:
virtual ~Instance();
@@ -53,6 +57,8 @@ class Instance {
xmlpp::DomParser *levelXml;
Data::Level *level;
+ View::TopView *view;
+
Instance(const Glib::ustring &file);
void destroy();
diff --git a/src/View/TopView.cpp b/src/View/TopView.cpp
index 43f0bc1..38d4824 100644
--- a/src/View/TopView.cpp
+++ b/src/View/TopView.cpp
@@ -18,28 +18,29 @@
*/
#include "TopView.h"
-#include "../Data/Level.h"
-#include "../Data/Room.h"
-#include "../Data/Triangle.h"
-#include <cmath>
+#include <Data/Level.h>
+#include <Data/Room.h>
+#include <Data/Triangle.h>
+#include <GL/gl.h>
namespace ZoomEdit {
namespace View {
void TopView::renderRoom(Data::Room *room) {
- const std::list<Data::Triangle*> &triangles = room->getTriangles();
- std::list<Data::Triangle*> floor;
+ const std::list<Data::Triangle*> &floor = room->getFloorTriangles();
- for(std::list<Data::Triangle*>::const_iterator t = triangles.begin(); t != triangles.end(); ++t) {
- Data::Vector v1 = (*t)->getVertex(1) - (*t)->getVertex(0);
- Data::Vector v2 = (*t)->getVertex(2) - (*t)->getVertex(0);
-
- Data::Vector n = (v1 % v2);
- n.normalize();
-
- if(n*Data::Vector(0, 1, 0) > std::cos(45))
- floor.push_back(*t);
+ glColor4f(0.0f, 0.7f, 1.0f, 0.3f);
+
+ glBegin(GL_TRIANGLES);
+
+ for(std::list<Data::Triangle*>::const_iterator t = floor.begin(); t != floor.end(); ++t) {
+ for(int i = 0; i < 3; ++i) {
+ const Data::Vertex &v = (*t)->getVertex(i);
+ glVertex2f(v.getX(), v.getZ());
+ }
}
+
+ glEnd();
}
void TopView::render() {
diff --git a/src/View/TopView.h b/src/View/TopView.h
index c5af1de..5141e51 100644
--- a/src/View/TopView.h
+++ b/src/View/TopView.h
@@ -25,6 +25,7 @@
namespace ZoomEdit {
namespace Data {
+class Level;
class Room;
}
@@ -32,12 +33,17 @@ namespace View {
class TopView : public View {
private:
+ Data::Level *level;
+
void renderRoom(Data::Room *room);
public:
- TopView(Data::Level *level0 = 0) : View(level0) {}
+ TopView(Data::Level *level0 = 0) : level(level0) {}
+
+ Data::Level* getLevel() {return level;}
+ void setLevel(Data::Level *level0) {level = level0;}
- void render();
+ virtual void render();
};
}
diff --git a/src/View/View.h b/src/View/View.h
index c7755f2..32c201e 100644
--- a/src/View/View.h
+++ b/src/View/View.h
@@ -21,24 +21,12 @@
#define ZOOMEDIT_VIEW_H_
namespace ZoomEdit {
-
-namespace Data {
-class Level;
-}
-
namespace View {
class View {
- protected:
- Data::Level *level;
-
public:
- View(Data::Level *level0) : level(level0) {}
virtual ~View() {}
- virtual Data::Level* getLevel() {return level;}
- virtual void setLevel(Data::Level *level0) {level = level0;}
-
virtual void render() = 0;
};