summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorneoraider <devnull@localhost>2008-04-15 16:15:02 +0200
committerneoraider <devnull@localhost>2008-04-15 16:15:02 +0200
commitbb09e9e703caceab0c5c5774509fb7167ead8d49 (patch)
tree059f0e06b885ae393c844db0cdc15669b68f8524 /src
parent7c929e6e1ce1f43d16d0d279af1e1261b5c566b7 (diff)
downloadzoomedit-bb09e9e703caceab0c5c5774509fb7167ead8d49.tar
zoomedit-bb09e9e703caceab0c5c5774509fb7167ead8d49.zip
zoomedit:
* Draw room edges
Diffstat (limited to 'src')
-rw-r--r--src/View/TopView.cpp59
-rw-r--r--src/View/TopView.h12
2 files changed, 71 insertions, 0 deletions
diff --git a/src/View/TopView.cpp b/src/View/TopView.cpp
index 684f4ef..8ca047f 100644
--- a/src/View/TopView.cpp
+++ b/src/View/TopView.cpp
@@ -24,10 +24,40 @@
#include <Gui/RenderArea.h>
#include <GL/gl.h>
#include <cmath>
+#include <set>
namespace ZoomEdit {
namespace View {
+bool TopView::Edge::operator<(const Edge &e) const {
+ if(v1->getX() < e.v1->getX())
+ return true;
+ if(v1->getX() > e.v1->getX())
+ return false;
+ if(v1->getY() < e.v1->getY())
+ return true;
+ if(v1->getY() > e.v1->getY())
+ return false;
+ if(v1->getZ() < e.v1->getZ())
+ return true;
+ if(v1->getZ() > e.v1->getZ())
+ return false;
+ if(v2->getX() < e.v2->getX())
+ return true;
+ if(v2->getX() > e.v2->getX())
+ return false;
+ if(v2->getY() < e.v2->getY())
+ return true;
+ if(v2->getY() > e.v2->getY())
+ return false;
+ if(v2->getZ() < e.v2->getZ())
+ return true;
+ if(v2->getZ() > e.v2->getZ())
+ return false;
+
+ return false;
+}
+
void TopView::drawGrid(Gui::RenderArea *renderArea) {
float depth = std::log10(renderArea->getScale())-0.75f;
float depth2 = std::floor(depth);
@@ -68,6 +98,7 @@ void TopView::drawGrid(Gui::RenderArea *renderArea) {
void TopView::renderRoom(Data::Room *room) {
const std::list<Data::Triangle*> &floor = room->getFloorTriangles();
+ std::multiset<Edge> edges;
glColor4f(0.0f, 0.7f, 1.0f, 0.3f);
@@ -76,11 +107,39 @@ void TopView::renderRoom(Data::Room *room) {
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);
+ const Data::Vertex &v2 = (*t)->getVertex((i+1)%3);
+
glVertex2f(v.getX(), v.getZ());
+
+ edges.insert(Edge(&v, &v2));
}
}
glEnd();
+
+ for(std::multiset<Edge>::iterator next = edges.begin(); next != edges.end();) {
+ std::multiset<Edge>::iterator edge = next++;
+ std::multiset<Edge>::iterator edge2 = edges.find(Edge(edge->v2, edge->v1));
+
+ if(edge2 != edges.end()) {
+ edges.erase(edge2);
+ next = edge;
+ ++next;
+ edges.erase(edge);
+ }
+ }
+
+ glColor4f(0.0f, 0.7f, 1.0f, 0.7f);
+ glLineWidth(1.0f);
+
+ glBegin(GL_LINES);
+
+ for(std::multiset<Edge>::iterator edge = edges.begin(); edge != edges.end(); ++edge) {
+ glVertex2f(edge->v1->getX(), edge->v1->getZ());
+ glVertex2f(edge->v2->getX(), edge->v2->getZ());
+ }
+
+ glEnd();
}
void TopView::render(Gui::RenderArea *renderArea) {
diff --git a/src/View/TopView.h b/src/View/TopView.h
index 844faa5..bbb9394 100644
--- a/src/View/TopView.h
+++ b/src/View/TopView.h
@@ -27,14 +27,26 @@ namespace ZoomEdit {
namespace Data {
class Level;
class Room;
+class Vertex;
}
namespace View {
class TopView : public View {
private:
+ class Edge {
+ public:
+ const Data::Vertex *v1, *v2;
+
+ Edge(const Data::Vertex *v10, const Data::Vertex *v20)
+ : v1(v10), v2(v20) {};
+ bool operator<(const Edge &e) const;
+ };
+
Data::Level *level;
+ bool edgeLess(const Edge &e1, const Edge &e2);
+
void drawGrid(Gui::RenderArea *renderArea);
void renderRoom(Data::Room *room);