summaryrefslogtreecommitdiffstats
path: root/Portal.h
diff options
context:
space:
mode:
authorneoraider <devnull@localhost>2008-02-13 22:06:01 +0100
committerneoraider <devnull@localhost>2008-02-13 22:06:01 +0100
commitc4aadd98230f3b9ab50398b715164ff874ea8a61 (patch)
tree8b6fcaf48fb0a7eb9af6fd1483659ab4d6e5c000 /Portal.h
parent16397f4474fbbe5f140a5e68b3bb6934170bf2e3 (diff)
downloadzoomedit-c4aadd98230f3b9ab50398b715164ff874ea8a61.tar
zoomedit-c4aadd98230f3b9ab50398b715164ff874ea8a61.zip
zoomedit: Vertices are selectable now.
Diffstat (limited to 'Portal.h')
-rw-r--r--Portal.h75
1 files changed, 62 insertions, 13 deletions
diff --git a/Portal.h b/Portal.h
index 3df4247..5f53f7b 100644
--- a/Portal.h
+++ b/Portal.h
@@ -3,29 +3,45 @@
#include "LevelObject.h"
#include "Polygon.h"
+#include "VertexProvider.h"
+#include "LevelVertex.h"
#include <math.h>
-class Portal : public LevelObject {
+class Portal : public LevelObject, public VertexProvider {
private:
float width, height, thickness;
Vertex pos;
float orient;
- Polygon createPolygon() const {
- Polygon p;
-
- float s = sinf(orient);
- float c = cosf(orient);
+ Vertex vertices[4];
+ float s, c;
+
+
+ void updateVertices() {
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));
+ vertices[0].setLocation(pos.getX()-x-ts, pos.getY()-y+tc);
+ vertices[1].setLocation(pos.getX()-x+ts, pos.getY()-y-tc);
+ vertices[2].setLocation(pos.getX()+x+ts, pos.getY()+y-tc);
+ vertices[3].setLocation(pos.getX()+x-ts, pos.getY()+y+tc);
+ }
+
+ void updateOrient() {
+ s = sinf(orient);
+ c = cosf(orient);
+
+ updateVertices();
+ }
+
+ Polygon createPolygon() const {
+ Polygon p;
+
+ for(int i = 0; i < 4; i++)
+ p.push_back(vertices[i]);
return p;
}
@@ -37,6 +53,8 @@ class Portal : public LevelObject {
this->thickness = thickness;
orient = 0;
+
+ updateOrient();
}
float getWidth() const {return width;}
@@ -44,12 +62,21 @@ class Portal : public LevelObject {
float getThickness() const {return thickness;}
const Vertex& getPosition() const {return pos;}
- void setPosition(Vertex v) {pos = v;}
+ void setPosition(Vertex v) {pos = v; updateVertices();}
float getOrientation() const {return orient;}
- void setOrientation(float orient) {this->orient = orient;}
+ void setOrientation(float orient) {this->orient = orient; updateOrient();}
- virtual bool hit(const Vertex &v) const {return createPolygon().contains(v);}
+ virtual std::vector<SharedPtr<LevelObject> > getChildren() {
+ std::vector<SharedPtr<LevelObject> > children;
+
+ for(size_t i = 0; i < 4; i++)
+ children.push_back(SharedPtr<LevelObject>(new LevelVertex(this, i)));
+
+ return children;
+ }
+
+ virtual bool hit(const Vertex &v, float scale) const {return createPolygon().contains(v);}
virtual int getPriority() const {return 1;}
virtual const char* getType() const {
@@ -58,15 +85,37 @@ class Portal : public LevelObject {
virtual void move(float x, float y) {
pos += Vertex(x, y);
+ updateVertices();
}
virtual void rotate(float a) {
orient = fmodf(orient+a, 2*M_PI);
+ updateOrient();
}
virtual Vertex getCenter() const {
return pos;
}
+
+ virtual const Vertex* getVertex(size_t id) const {
+ return &vertices[id];
+ }
+
+ virtual size_t getVertexCount() const {
+ return 1;
+ }
+
+ virtual void moveVertex(size_t id, float x, float y) {
+ move(x, y);
+ }
+
+ virtual void rotateVertex(size_t id, float a) {
+ pos = vertices[id];
+ rotate(a);
+ pos = vertices[(id+2)%4];
+
+ updateVertices();
+ }
};
#endif /*PORTAL_H_*/