From acb1721e94a49a4941bb11dfc2f832c3848aa204 Mon Sep 17 00:00:00 2001 From: neoraider Date: Fri, 8 Feb 2008 21:21:01 +0000 Subject: zoomedit: Implemented Rotate tool; added simple gates. --- Portal.h | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 Portal.h (limited to 'Portal.h') diff --git a/Portal.h b/Portal.h new file mode 100644 index 0000000..a4cb349 --- /dev/null +++ b/Portal.h @@ -0,0 +1,73 @@ +#ifndef PORTAL_H_ +#define PORTAL_H_ + +#include "LevelObject.h" +#include "Polygon.h" +#include + + +class Portal : public LevelObject { + private: + float width, height, thickness; + Vertex pos; + float orient; + + Polygon createPolygon() const { + Polygon p; + + float s = sinf(orient); + float c = cosf(orient); + float x = width/2*c; + float y = width/2*s; + float ts = thickness/2*s; + float tc = thickness/2*c; + + p.push_back(Vertex(pos.getX()-x-ts, pos.getY()-y+tc)); + p.push_back(Vertex(pos.getX()-x+ts, pos.getY()-y-tc)); + p.push_back(Vertex(pos.getX()+x+ts, pos.getY()+y-tc)); + p.push_back(Vertex(pos.getX()+x-ts, pos.getY()+y+tc)); + + return p; + } + + public: + Portal(float width, float height, float thickness) { + this->width = width; + this->height = height; + this->thickness = thickness; + + orient = 0; + } + + float getWidth() const {return width;} + float getHeight() const {return height;} + float getThickness() const {return thickness;} + + const Vertex& getPosition() const {return pos;} + void setPosition(Vertex v) {pos = v;} + + float getOrientation() const {return orient;} + void setOrientation(float orient) {this->orient = orient;} + + virtual bool hit(const Vertex &v) const {return createPolygon().contains(v);} + virtual int getPriority() const {return 1;} + + virtual const char* getType() const { + return "Portal"; + } + + virtual void move(float x, float y) { + pos.setX(pos.getX()+x); + pos.setY(pos.getY()+y); + } + + virtual void rotate(float a) { + orient = fmodf(orient+a, 2*M_PI); + } + + virtual Vertex getCenter() const { + return pos; + } +}; + +#endif /*PORTAL_H_*/ -- cgit v1.2.3