zoomedit: Improved vertex handling and edge rendering.

This commit is contained in:
neoraider 2008-02-20 13:51:04 +00:00
parent f457ec5027
commit 258eb984ba
5 changed files with 34 additions and 13 deletions

View file

@ -51,8 +51,8 @@ void Renderer::fillPolygon(const Polygon &polygon) {
glEnd(); glEnd();
} }
void Renderer::drawPolygon(const Polygon &polygon, bool close) { void Renderer::drawPolygon(const Polygon &polygon) {
glBegin(close ? GL_LINE_LOOP : GL_LINE_STRIP); glBegin(GL_LINE_LOOP);
for(Polygon::const_iterator vertex = polygon.begin(); vertex != polygon.end(); vertex++) for(Polygon::const_iterator vertex = polygon.begin(); vertex != polygon.end(); vertex++)
glVertex2f(vertex->getX(), vertex->getY()); glVertex2f(vertex->getX(), vertex->getY());
@ -172,7 +172,15 @@ void Renderer::renderRoom(const Room &room, bool selected, bool hovered, float s
glLineWidth(1.0f); glLineWidth(1.0f);
} }
drawPolygon(room.getPolygon()); glBegin(GL_LINES);
for(size_t i = 0; i < room.getEdgeCount(); i++) {
const Edge *edge = room.getEdge(i);
glVertex2f(edge->getVertex1()->getX(), edge->getVertex1()->getY());
glVertex2f(edge->getVertex2()->getX(), edge->getVertex2()->getY());
}
glEnd();
} }
void Renderer::renderPlayerStart(const PlayerStart &start, bool selected, bool hovered, float scale) { void Renderer::renderPlayerStart(const PlayerStart &start, bool selected, bool hovered, float scale) {

View file

@ -19,7 +19,7 @@ class Renderer {
protected: protected:
void fillPolygon(const Polygon &polygon); void fillPolygon(const Polygon &polygon);
void drawPolygon(const Polygon &polygon, bool close = true); void drawPolygon(const Polygon &polygon);
void fillCircle(const Vertex &m, float r, int n = 64); void fillCircle(const Vertex &m, float r, int n = 64);
void drawCircle(const Vertex &m, float r, int n = 64); void drawCircle(const Vertex &m, float r, int n = 64);
void drawCircleDotted(const Vertex &m, float r, int n = 64, int d = 8, float rot = 0); void drawCircleDotted(const Vertex &m, float r, int n = 64, int d = 8, float rot = 0);

View file

@ -23,8 +23,10 @@ const Room& Room::operator=(const Room &room) {
std::vector<SharedPtr<LevelObject> > Room::getChildren() { std::vector<SharedPtr<LevelObject> > Room::getChildren() {
std::vector<SharedPtr<LevelObject> > children; std::vector<SharedPtr<LevelObject> > children;
for(size_t i = 0; i < vertices.size(); i++) for(size_t i = 0; i < vertices.size(); i++) {
if(vertices[i]->isDirect())
children.push_back(SharedPtr<LevelObject>(new LevelVertex(this, i, this))); children.push_back(SharedPtr<LevelObject>(new LevelVertex(this, i, this)));
}
for(size_t i = 0; i < edges.size(); i++) for(size_t i = 0; i < edges.size(); i++)
children.push_back(SharedPtr<LevelObject>(new LevelEdge(this, i, this))); children.push_back(SharedPtr<LevelObject>(new LevelEdge(this, i, this)));

10
Room.h
View file

@ -22,6 +22,8 @@ class Room : public LevelObject, private VertexProvider, private EdgeProvider {
virtual const Vertex& operator-=(const Vertex &v) {return **this;} virtual const Vertex& operator-=(const Vertex &v) {return **this;}
virtual void setLocation(float x, float y) {} virtual void setLocation(float x, float y) {}
virtual bool isDirect() const = 0;
}; };
class RoomVertexDirect : public RoomVertex { class RoomVertexDirect : public RoomVertex {
@ -48,6 +50,8 @@ class Room : public LevelObject, private VertexProvider, private EdgeProvider {
virtual void setLocation(float x, float y) { virtual void setLocation(float x, float y) {
vertex.setLocation(x, y); vertex.setLocation(x, y);
} }
virtual bool isDirect() const {return true;}
}; };
class RoomVertexIndirect : public RoomVertex { class RoomVertexIndirect : public RoomVertex {
@ -60,6 +64,8 @@ class Room : public LevelObject, private VertexProvider, private EdgeProvider {
virtual const Vertex& operator*() const { virtual const Vertex& operator*() const {
return *vertex; return *vertex;
} }
virtual bool isDirect() const {return false;}
}; };
@ -132,8 +138,8 @@ class Room : public LevelObject, private VertexProvider, private EdgeProvider {
} }
void close() { void close() {
if(!edges.empty()) if(vertices.size() >= 2)
edges.push_back(Edge(edges.back().getVertex2(), edges.front().getVertex1())); edges.push_back(Edge(LevelVertex(this, vertices.size()-1, this), LevelVertex(this, 0, this)));
} }
Polygon getPolygon() const { Polygon getPolygon() const {

View file

@ -34,19 +34,24 @@ void ToolAddPolygon::render(const Level &level, const Rectangle &rect, float sca
glLineWidth(2.0f); glLineWidth(2.0f);
glColor4f(0.0f, 0.7f, 1.0f, 0.7f); glColor4f(0.0f, 0.7f, 1.0f, 0.7f);
drawPolygon(newRoom.getPolygon(), false);
glBegin(GL_LINES);
for(size_t i = 0; i < newRoom.getEdgeCount(); i++) {
const Edge *edge = newRoom.getEdge(i);
glVertex2f(edge->getVertex1()->getX(), edge->getVertex1()->getY());
glVertex2f(edge->getVertex2()->getX(), edge->getVertex2()->getY());
}
if(!newRoom.getPolygon().empty() && editManager->getHoveredVertex()) { if(!newRoom.getPolygon().empty() && editManager->getHoveredVertex()) {
if(!editManager->vertexOk(*editManager->getHoveredVertex(), &newRoom)) if(!editManager->vertexOk(*editManager->getHoveredVertex(), &newRoom))
glColor4f(1.0f, 0.3f, 0.3f, 0.7f); glColor4f(1.0f, 0.3f, 0.3f, 0.7f);
glBegin(GL_LINES);
glVertex2f(newRoom.getPolygon().back().getX(), newRoom.getPolygon().back().getY()); glVertex2f(newRoom.getPolygon().back().getX(), newRoom.getPolygon().back().getY());
glVertex2f(editManager->getHoveredVertex()->getX(), editManager->getHoveredVertex()->getY()); glVertex2f(editManager->getHoveredVertex()->getX(), editManager->getHoveredVertex()->getY());
}
glEnd(); glEnd();
}
} }
bool ToolAddPolygon::buttonPress(unsigned int button, const Vertex *v) { bool ToolAddPolygon::buttonPress(unsigned int button, const Vertex *v) {