2008-02-08 21:21:01 +00:00
|
|
|
#ifndef PORTAL_H_
|
|
|
|
#define PORTAL_H_
|
|
|
|
|
|
|
|
#include "LevelObject.h"
|
|
|
|
#include "Polygon.h"
|
2008-02-13 21:06:01 +00:00
|
|
|
#include "VertexProvider.h"
|
|
|
|
#include "LevelVertex.h"
|
2008-02-08 21:21:01 +00:00
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
|
2008-02-13 21:06:01 +00:00
|
|
|
class Portal : public LevelObject, public VertexProvider {
|
2008-02-08 21:21:01 +00:00
|
|
|
private:
|
|
|
|
float width, height, thickness;
|
|
|
|
Vertex pos;
|
|
|
|
float orient;
|
|
|
|
|
2008-02-13 21:06:01 +00:00
|
|
|
Vertex vertices[4];
|
|
|
|
float s, c;
|
|
|
|
|
|
|
|
|
|
|
|
void updateVertices() {
|
2008-02-08 21:21:01 +00:00
|
|
|
float x = width/2*c;
|
|
|
|
float y = width/2*s;
|
|
|
|
float ts = thickness/2*s;
|
|
|
|
float tc = thickness/2*c;
|
|
|
|
|
2008-02-13 21:06:01 +00:00
|
|
|
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]);
|
2008-02-08 21:21:01 +00:00
|
|
|
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
Portal(float width, float height, float thickness) {
|
|
|
|
this->width = width;
|
|
|
|
this->height = height;
|
|
|
|
this->thickness = thickness;
|
|
|
|
|
|
|
|
orient = 0;
|
2008-02-13 21:06:01 +00:00
|
|
|
|
|
|
|
updateOrient();
|
2008-02-08 21:21:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
float getWidth() const {return width;}
|
|
|
|
float getHeight() const {return height;}
|
|
|
|
float getThickness() const {return thickness;}
|
|
|
|
|
|
|
|
const Vertex& getPosition() const {return pos;}
|
2008-02-13 21:06:01 +00:00
|
|
|
void setPosition(Vertex v) {pos = v; updateVertices();}
|
2008-02-08 21:21:01 +00:00
|
|
|
|
|
|
|
float getOrientation() const {return orient;}
|
2008-02-13 21:06:01 +00:00
|
|
|
void setOrientation(float orient) {this->orient = orient; updateOrient();}
|
2008-02-08 21:21:01 +00:00
|
|
|
|
2008-02-13 21:06:01 +00:00
|
|
|
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);}
|
2008-02-08 21:21:01 +00:00
|
|
|
virtual int getPriority() const {return 1;}
|
|
|
|
|
|
|
|
virtual const char* getType() const {
|
|
|
|
return "Portal";
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void move(float x, float y) {
|
2008-02-09 12:21:00 +00:00
|
|
|
pos += Vertex(x, y);
|
2008-02-13 21:06:01 +00:00
|
|
|
updateVertices();
|
2008-02-08 21:21:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void rotate(float a) {
|
|
|
|
orient = fmodf(orient+a, 2*M_PI);
|
2008-02-13 21:06:01 +00:00
|
|
|
updateOrient();
|
2008-02-08 21:21:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual Vertex getCenter() const {
|
|
|
|
return pos;
|
|
|
|
}
|
2008-02-13 21:06:01 +00:00
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
2008-02-08 21:21:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /*PORTAL_H_*/
|