diff options
Diffstat (limited to 'Room.h')
-rw-r--r-- | Room.h | 80 |
1 files changed, 45 insertions, 35 deletions
@@ -2,21 +2,34 @@ #define ROOM_H_ #include "Polygon.h" +#include "SharedPtr.h" #include "LevelObject.h" #include "VertexProvider.h" -#include "LevelVertex.h" +#include "EdgeProvider.h" #include <string> -class Room : public Polygon, public LevelObject, public VertexProvider { +class Room : public LevelObject, private VertexProvider, private EdgeProvider { private: + Polygon polygon; std::string name; float height; + std::vector<Edge> edges; + + void rotateAround(Vertex z, float a); + public: Room() {height = 10;} Room(std::string name) {this->name = name; height = 10;} + Room(const Room &room) : name(room.name), height(room.height) { + for(Polygon::const_iterator v = room.polygon.begin(); v != room.polygon.end(); v++) + addVertex(*v); + } + + const Room& operator=(const Room &room); + std::string &getName() {return name;} const std::string &getName() const {return name;} void setName(const std::string &name) {this->name = name;} @@ -24,17 +37,14 @@ class Room : public Polygon, public LevelObject, public VertexProvider { float getHeight() const {return height;} void setHeight(float height) {this->height = height;} - virtual bool hit(const Vertex &v, float scale) const {return contains(v);} + void addVertex(Vertex v); + + const Polygon& getPolygon() const {return polygon;} + + virtual bool hit(const Vertex &v, float scale) const {return polygon.contains(v);} virtual int getPriority() const {return 0;} - virtual std::vector<SharedPtr<LevelObject> > getChildren() { - std::vector<SharedPtr<LevelObject> > children; - - for(size_t i = 0; i < size(); i++) - children.push_back(SharedPtr<LevelObject>(new LevelVertex(this, i))); - - return children; - } + virtual std::vector<SharedPtr<LevelObject> > getChildren(); virtual const char* getType() const { return "Room"; @@ -43,55 +53,55 @@ class Room : public Polygon, public LevelObject, public VertexProvider { virtual void move(float x, float y) { Vertex m(x, y); - for(iterator v = begin(); v != end(); v++) + for(Polygon::iterator v = polygon.begin(); v != polygon.end(); v++) *v += m; } virtual void rotate(float a) { - Vertex z = getCenter(); - float s = sinf(a); - float c = cosf(a); - - for(iterator v = begin(); v != end(); v++) { - *v -= z; - v->setLocation(c*v->getX() - s*v->getY(), c*v->getY() + s*v->getX()); - *v += z; - } + rotateAround(getCenter(), a); } virtual Vertex getCenter() const { Vertex ret; - for(const_iterator v = begin(); v != end(); v++) + for(Polygon::const_iterator v = polygon.begin(); v != polygon.end(); v++) ret += *v; - return ret / size(); + return ret / polygon.size(); } virtual const Vertex* getVertex(size_t id) const { - return &at(id); + return &polygon[id]; } virtual size_t getVertexCount() const { - return size(); + return polygon.size(); } virtual void moveVertex(size_t id, float x, float y) { - at(id) += Vertex(x, y); + polygon[id] += Vertex(x, y); } virtual void rotateVertex(size_t id, float a) { - Vertex z = at(id); - float s = sinf(a); - float c = cosf(a); - - for(iterator v = begin(); v != end(); v++) { - *v -= z; - v->setLocation(c*v->getX() - s*v->getY(), c*v->getY() + s*v->getX()); - *v += z; - } + rotateAround(polygon[id], a); } + virtual const Edge* getEdge(size_t id) const { + return &edges[id]; + } + + virtual size_t getEdgeCount() const { + return edges.size(); + } + + virtual void moveEdge(size_t id, float x, float y) { + moveVertex(id, x, y); + moveVertex((id+1)%polygon.size(), x, y); + } + + virtual void rotateEdge(size_t id, float a) { + rotateAround((polygon[id]+polygon[(id+1)%polygon.size()])/2, a); + } }; #endif /*ROOM_H_*/ |