Browse Source

Implement `SurfaceFactory`

Code that creates triangle or quad surface with default vertex and texCoord values
master
Krisjanis Rijnieks 10 years ago
parent
commit
c4db1d000e
  1. 46
      src/Surfaces/SurfaceFactory.cpp
  2. 2
      src/Surfaces/SurfaceFactory.h

46
src/Surfaces/SurfaceFactory.cpp

@ -14,9 +14,51 @@ SurfaceFactory * SurfaceFactory::instance(){
BaseSurface * SurfaceFactory::createSurface(int type){
if(type == SurfaceType::TRIANGLE_SURFACE){
// TODO: Create 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;
}else if(type == SurfaceType::QUAD_SURFACE){
// TODO: Create 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;
}else{
throw runtime_error("Undefined surface type");
}

2
src/Surfaces/SurfaceFactory.h

@ -3,6 +3,8 @@
#include "ofMain.h"
#include "BaseSurface.h"
#include "SurfaceType.h"
#include "TriangleSurface.h"
#include "QuadSurface.h"
namespace ofx {
namespace piMapper {

Loading…
Cancel
Save