Browse Source

Create separate methods for creating triangle and quad surfaces

master
Krisjanis Rijnieks 9 years ago
parent
commit
15a9940e57
  1. 92
      src/Surfaces/SurfaceFactory.cpp
  2. 3
      src/Surfaces/SurfaceFactory.h

92
src/Surfaces/SurfaceFactory.cpp

@ -14,55 +14,59 @@ SurfaceFactory * SurfaceFactory::instance(){
BaseSurface * SurfaceFactory::createSurface(int type){
if(type == SurfaceType::TRIANGLE_SURFACE){
vector <ofVec2f> vertices;
float margin = 50.0f;
vertices.push_back(ofVec2f((float)ofGetWidth() / 2.0f, margin));
vertices.push_back(ofVec2f((float)ofGetWidth() - margin, (float)ofGetHeight() - margin));
vertices.push_back(ofVec2f(margin, (float)ofGetHeight() - margin));
vector <ofVec2f> texCoords;
texCoords.push_back(ofVec2f(0.5f, 0.0f));
texCoords.push_back(ofVec2f(1.0f, 1.0f));
texCoords.push_back(ofVec2f(0.0f, 1.0f));
TriangleSurface * triangleSurface = new TriangleSurface();
for(int i = 0; i < 3; i++){
triangleSurface->setVertex(i, vertices[i]);
triangleSurface->setTexCoord(i, texCoords[i]);
}
return triangleSurface;
return createTriangleSurface();
}else if(type == SurfaceType::QUAD_SURFACE){
vector <ofVec2f> vertices;
float margin = 50.0f;
vertices.push_back(ofVec2f(margin, margin));
vertices.push_back(ofVec2f((float)ofGetWidth() - margin, margin));
vertices.push_back(ofVec2f((float)ofGetWidth() - margin, (float)ofGetHeight() - margin));
vertices.push_back(ofVec2f(margin, (float)ofGetHeight() - margin));
vector <ofVec2f> texCoords;
texCoords.push_back(ofVec2f(ofVec2f(0.0f, 0.0f)));
texCoords.push_back(ofVec2f(ofVec2f(1.0f, 0.0f)));
texCoords.push_back(ofVec2f(ofVec2f(1.0f, 1.0f)));
texCoords.push_back(ofVec2f(ofVec2f(0.0f, 1.0f)));
QuadSurface * quadSurface = new QuadSurface();
for(int i = 0; i < 4; i++){
quadSurface->setVertex(i, vertices[i]);
quadSurface->setTexCoord(i, texCoords[i]);
}
return quadSurface;
return createQuadSurface();
}else{
throw runtime_error("Undefined surface type");
}
}
TriangleSurface * SurfaceFactory::createTriangleSurface(){
vector <ofVec2f> vertices;
float margin = 50.0f;
vertices.push_back(ofVec2f((float)ofGetWidth() / 2.0f, margin));
vertices.push_back(ofVec2f((float)ofGetWidth() - margin, (float)ofGetHeight() - margin));
vertices.push_back(ofVec2f(margin, (float)ofGetHeight() - margin));
vector <ofVec2f> texCoords;
texCoords.push_back(ofVec2f(0.5f, 0.0f));
texCoords.push_back(ofVec2f(1.0f, 1.0f));
texCoords.push_back(ofVec2f(0.0f, 1.0f));
TriangleSurface * triangleSurface = new TriangleSurface();
for(int i = 0; i < 3; i++){
triangleSurface->setVertex(i, vertices[i]);
triangleSurface->setTexCoord(i, texCoords[i]);
}
return triangleSurface;
}
QuadSurface * SurfaceFactory::createQuadSurface(){
vector <ofVec2f> vertices;
float margin = 50.0f;
vertices.push_back(ofVec2f(margin, margin));
vertices.push_back(ofVec2f((float)ofGetWidth() - margin, margin));
vertices.push_back(ofVec2f((float)ofGetWidth() - margin, (float)ofGetHeight() - margin));
vertices.push_back(ofVec2f(margin, (float)ofGetHeight() - margin));
vector <ofVec2f> texCoords;
texCoords.push_back(ofVec2f(ofVec2f(0.0f, 0.0f)));
texCoords.push_back(ofVec2f(ofVec2f(1.0f, 0.0f)));
texCoords.push_back(ofVec2f(ofVec2f(1.0f, 1.0f)));
texCoords.push_back(ofVec2f(ofVec2f(0.0f, 1.0f)));
QuadSurface * quadSurface = new QuadSurface();
for(int i = 0; i < 4; i++){
quadSurface->setVertex(i, vertices[i]);
quadSurface->setTexCoord(i, texCoords[i]);
}
return quadSurface;
}
} // namespace piMapper
} // namespace ofx

3
src/Surfaces/SurfaceFactory.h

@ -19,6 +19,9 @@ class SurfaceFactory {
private:
static SurfaceFactory * _instance;
TriangleSurface * createTriangleSurface();
QuadSurface * createQuadSurface();
};
} // namespace piMapper

Loading…
Cancel
Save