Browse Source

Add `clone()` and `deleteSurface()` methods to `BaseSurface`

master
Krisjanis Rijnieks 9 years ago
parent
commit
18ae7b7b42
  1. 2
      src/Surfaces/BaseSurface.h
  2. 20
      src/Surfaces/GridWarpSurface.cpp
  3. 3
      src/Surfaces/GridWarpSurface.h
  4. 20
      src/Surfaces/QuadSurface.cpp
  5. 3
      src/Surfaces/QuadSurface.h
  6. 20
      src/Surfaces/TriangleSurface.cpp
  7. 3
      src/Surfaces/TriangleSurface.h

2
src/Surfaces/BaseSurface.h

@ -30,6 +30,8 @@ class BaseSurface {
virtual ofPolyline getTextureHitArea(){}
virtual vector <ofVec3f> & getVertices(){}
virtual vector <ofVec2f> & getTexCoords(){}
virtual BaseSurface * clone(){}
void drawTexture(ofVec2f position);
void setSource(BaseSource * newSource);

20
src/Surfaces/GridWarpSurface.cpp

@ -160,6 +160,18 @@ void GridWarpSurface::setVertices(vector<ofVec2f> v){
ofNotifyEvent(verticesChangedEvent, mesh.getVertices(), this);
}
void GridWarpSurface::setVertices(vector<ofVec3f> v){
if(v.size() != mesh.getVertices().size()){
throw runtime_error("Wrong number of vertices");
}
for(int i = 0; i < v.size(); ++i){
mesh.setVertex(i, v[i]);
}
ofNotifyEvent(verticesChangedEvent, mesh.getVertices(), this);
}
void GridWarpSurface::setTexCoord(int index, ofVec2f t){
if(index >= mesh.getVertices().size()){
throw runtime_error("Texture coordinate with provided index does not exist");
@ -231,7 +243,13 @@ void GridWarpSurface::createGridMesh(){
ofNotifyEvent(verticesChangedEvent, mesh.getVertices(), this);
}
BaseSurface * GridWarpSurface::clone(){
GridWarpSurface * s = new GridWarpSurface();
s->setVertices(getVertices());
s->setTexCoords(getTexCoords());
s->setSource(getSource());
return s;
}
} // namespace piMapper
} // namespace ofx

3
src/Surfaces/GridWarpSurface.h

@ -28,12 +28,15 @@ class GridWarpSurface : public BaseSurface {
void setVertex(int index, ofVec2f p);
void setVertices(vector<ofVec2f> v);
void setVertices(vector<ofVec3f> v);
void setTexCoord(int index, ofVec2f t);
void setTexCoords(vector<ofVec2f> t);
vector <ofVec3f> & getVertices();
vector <ofVec2f> & getTexCoords();
void createGridMesh();
BaseSurface * clone();
private:
int _gridCols;

20
src/Surfaces/QuadSurface.cpp

@ -114,6 +114,18 @@ void QuadSurface::setVertices(vector<ofVec2f> v){
ofNotifyEvent(verticesChangedEvent, mesh.getVertices(), this);
}
void QuadSurface::setVertices(vector<ofVec3f> v){
if(v.size() != 4){
throw runtime_error("Wrong number of vertices");
}
for(int i = 0; i < 4; ++i){
mesh.setVertex(i, v[i]);
}
ofNotifyEvent(verticesChangedEvent, mesh.getVertices(), this);
}
void QuadSurface::setTexCoord(int index, ofVec2f t){
if(index > 3){
ofLog() << "Texture coordinate with this index does not exist: " << index
@ -277,5 +289,13 @@ ofRectangle QuadSurface::getMeshBoundingBox(){
return boundingBox;
}
BaseSurface * QuadSurface::clone(){
QuadSurface * s = new QuadSurface();
s->setVertices(getVertices());
s->setTexCoords(getTexCoords());
s->setSource(getSource());
return s;
}
} // namespace piMapper
} // namespace ofx

3
src/Surfaces/QuadSurface.h

@ -22,6 +22,7 @@ class QuadSurface : public BaseSurface {
void setVertex(int index, ofVec2f p);
void setVertices(vector<ofVec2f> v);
void setVertices(vector<ofVec3f> v);
void setTexCoord(int index, ofVec2f t);
void setTexCoords(vector<ofVec2f> t);
@ -41,6 +42,8 @@ class QuadSurface : public BaseSurface {
bool getPerspectiveWarping();
ofRectangle getMeshBoundingBox();
BaseSurface * clone();
private:
void calculateHomography();

20
src/Surfaces/TriangleSurface.cpp

@ -79,6 +79,18 @@ void TriangleSurface::setVertices(vector<ofVec2f> v){
ofNotifyEvent(verticesChangedEvent, mesh.getVertices(), this);
}
void TriangleSurface::setVertices(vector<ofVec3f> v){
if(v.size() != 3){
throw runtime_error("Wrong number of vertices");
}
for(int i = 0; i < 3; ++i){
mesh.setVertex(i, v[i]);
}
ofNotifyEvent(verticesChangedEvent, mesh.getVertices(), this);
}
void TriangleSurface::setTexCoord(int index, ofVec2f t){
if(index > 2){
ofLog() << "Texture coordinate with this index does not exist: " << index
@ -173,5 +185,13 @@ vector <ofVec2f> & TriangleSurface::getTexCoords(){
return mesh.getTexCoords();
}
BaseSurface * TriangleSurface::clone(){
TriangleSurface * s = new TriangleSurface();
s->setVertices(getVertices());
s->setTexCoords(getTexCoords());
s->setSource(getSource());
return s;
}
} // namespace piMapper
} // namespace ofx

3
src/Surfaces/TriangleSurface.h

@ -19,6 +19,7 @@ class TriangleSurface : public BaseSurface {
void setVertex(int index, ofVec2f p);
void setVertices(vector<ofVec2f> v);
void setVertices(vector<ofVec3f> v);
void setTexCoord(int index, ofVec2f t);
void setTexCoords(vector<ofVec2f> t);
@ -33,6 +34,8 @@ class TriangleSurface : public BaseSurface {
ofPolyline getTextureHitArea();
vector <ofVec3f> & getVertices();
vector <ofVec2f> & getTexCoords();
BaseSurface * clone();
};
} // namespace piMapper

Loading…
Cancel
Save