diff options
Diffstat (limited to 'Room.cpp')
-rw-r--r-- | Room.cpp | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/Room.cpp b/Room.cpp new file mode 100644 index 0000000..1980026 --- /dev/null +++ b/Room.cpp @@ -0,0 +1,63 @@ +#include "Room.h" +#include "LevelEdge.h" + + +void Room::rotateAround(Vertex z, float a) { + float s = sinf(a); + float c = cosf(a); + + for(Polygon::iterator v = polygon.begin(); v != polygon.end(); v++) { + *v -= z; + v->setLocation(c*v->getX() - s*v->getY(), c*v->getY() + s*v->getX()); + *v += z; + } +} + +const Room& Room::operator=(const Room &room) { + polygon.clear(); + edges.clear(); + + name = room.name; + height = room.height; + + for(Polygon::const_iterator v = room.polygon.begin(); v != room.polygon.end(); v++) + addVertex(*v); + + return room; +} + +void Room::addVertex(Vertex v) { + polygon.push_back(v); + + if(polygon.size() < 2) + return; + + if(polygon.size() == 2) { + LevelVertex v1(this, 0, this), v2(this, 1, this); + + edges.push_back(Edge(v1, v2)); + edges.push_back(Edge(v2, v1)); + + return; + } + + edges.pop_back(); + LevelVertex v1(edges.back().getVertex2()); + LevelVertex v2(this, polygon.size()-1, this); + LevelVertex v3(edges.front().getVertex1()); + + edges.push_back(Edge(v1, v2)); + edges.push_back(Edge(v2, v3)); +} + +std::vector<SharedPtr<LevelObject> > Room::getChildren() { + std::vector<SharedPtr<LevelObject> > children; + + for(size_t i = 0; i < polygon.size(); i++) + children.push_back(SharedPtr<LevelObject>(new LevelVertex(this, i, this))); + + for(size_t i = 0; i < edges.size(); i++) + children.push_back(SharedPtr<LevelObject>(new LevelEdge(this, i, this))); + + return children; +} |