diff --git a/src/Surfaces/SurfaceFactory.cpp b/src/Surfaces/SurfaceFactory.cpp index 2841a0b..0783110 100644 --- a/src/Surfaces/SurfaceFactory.cpp +++ b/src/Surfaces/SurfaceFactory.cpp @@ -14,55 +14,59 @@ SurfaceFactory * SurfaceFactory::instance(){ BaseSurface * SurfaceFactory::createSurface(int type){ if(type == SurfaceType::TRIANGLE_SURFACE){ - - vector 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 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 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 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 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 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 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 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 diff --git a/src/Surfaces/SurfaceFactory.h b/src/Surfaces/SurfaceFactory.h index 228a925..5d2548f 100644 --- a/src/Surfaces/SurfaceFactory.h +++ b/src/Surfaces/SurfaceFactory.h @@ -19,6 +19,9 @@ class SurfaceFactory { private: static SurfaceFactory * _instance; + + TriangleSurface * createTriangleSurface(); + QuadSurface * createQuadSurface(); }; } // namespace piMapper