Browse Source

Add different addSurface method options to surfaceManager

master
Krisjanis Rijnieks 11 years ago
parent
commit
c52a5b1ab6
  1. 2
      README.md
  2. 15
      example/src/ofApp.cpp
  3. 2
      example/src/ofApp.h
  4. 56
      src/ofxSurfaceManager.cpp
  5. 3
      src/ofxSurfaceManager.h

2
README.md

@ -38,7 +38,7 @@ Version history
### Version 0.1.2:
TODO:
-/+ Possibility to add multiple surfaces with a kind of layer management utility.
- Add GUI for surface manager instead per surface
+ Add GUI for surface manager instead per surface
+ Ability to select and drag whole surfaces
+ Select / deselect surfaces
- Example with video source. Maybe one example with different surfaces and sources.

15
example/src/ofApp.cpp

@ -63,6 +63,7 @@ void ofApp::keyPressed(int key)
case '2': gui.setMode(ofxGuiMode::TEXTURE_MAPPING); break;
case '3': gui.setMode(ofxGuiMode::PROJECTION_MAPPING); break;
case 'i': bShowInfo = !bShowInfo; break;
case 'r': addRandomSurface(); break;
default: break;
}
}
@ -83,4 +84,18 @@ void ofApp::mouseDragged(int x, int y, int button)
{
//
//surfaceManager.mouseDragged(x, y, button);
}
void ofApp::addRandomSurface()
{
int surfaceType = ofxSurfaceType::TRIANGLE_SURFACE;
vector<ofVec2f> vertices;
vertices.push_back( ofVec2f( ofRandomWidth(), ofRandomHeight() ) );
vertices.push_back( ofVec2f( ofRandomWidth(), ofRandomHeight() ) );
vertices.push_back( ofVec2f( ofRandomWidth(), ofRandomHeight() ) );
vector<ofVec2f> texCoords;
texCoords.push_back( ofVec2f( ofRandomuf(), ofRandomuf() ) );
texCoords.push_back( ofVec2f( ofRandomuf(), ofRandomuf() ) );
texCoords.push_back( ofVec2f( ofRandomuf(), ofRandomuf() ) );
surfaceManager.addSurface(surfaceType, vertices, texCoords);
}

2
example/src/ofApp.h

@ -16,6 +16,8 @@ public:
void mouseReleased(int x, int y, int button);
void mouseDragged(int x, int y, int button);
void addRandomSurface();
ofImage image;
ofxSurfaceManager surfaceManager;
ofxSurfaceManagerGui gui;

56
src/ofxSurfaceManager.cpp

@ -30,6 +30,62 @@ void ofxSurfaceManager::addSurface(int surfaceType)
}
}
void ofxSurfaceManager::addSurface(int surfaceType, ofTexture* texturePtr)
{
if ( surfaceType == ofxSurfaceType::TRIANGLE_SURFACE ) {
surfaces.push_back( new ofxTriangleSurface() );
surfaces.back()->setTexture(texturePtr);
} else {
throw std::runtime_error("Attempt to add non-existing surface type.");
}
}
void ofxSurfaceManager::addSurface(int surfaceType, vector<ofVec2f> vertices, vector<ofVec2f> texCoords)
{
if ( surfaceType == ofxSurfaceType::TRIANGLE_SURFACE ) {
if ( vertices.size() < 3 ) {
throw std::runtime_error("There must be 3 vertices for a triangle surface.");
} else if (texCoords.size() < 3) {
throw std::runtime_error("Thre must be 3 texture coordinates for a triangle surface.");
}
surfaces.push_back( new ofxTriangleSurface() );
for ( int i=0; i<3; i++ ) {
surfaces.back()->setVertex(i, vertices[i]);
surfaces.back()->setTexCoord(i, texCoords[i]);
}
} else {
throw std::runtime_error("Attempt to add non-existing surface type.");
}
}
void ofxSurfaceManager::addSurface(int surfaceType, ofTexture* texturePtr, vector<ofVec2f> vertices, vector<ofVec2f> texCoords)
{
if ( surfaceType == ofxSurfaceType::TRIANGLE_SURFACE ) {
if ( vertices.size() < 3 ) {
throw std::runtime_error("There must be 3 vertices for a triangle surface.");
} else if (texCoords.size() < 3) {
throw std::runtime_error("Thre must be 3 texture coordinates for a triangle surface.");
}
surfaces.push_back( new ofxTriangleSurface() );
surfaces.back()->setTexture(texturePtr);
for ( int i=0; i<3; i++ ) {
surfaces.back()->setVertex(i, vertices[i]);
surfaces.back()->setTexCoord(i, texCoords[i]);
}
} else {
throw std::runtime_error("Attempt to add non-existing surface type.");
}
}
ofxBaseSurface* ofxSurfaceManager::selectSurface(int index)
{
if ( index >= surfaces.size() ) {

3
src/ofxSurfaceManager.h

@ -15,6 +15,9 @@ public:
void draw();
void addSurface(int surfaceType);
void addSurface(int surfaceType, ofTexture* texturePtr);
void addSurface(int surfaceType, vector<ofVec2f> vertices, vector<ofVec2f> texCoords);
void addSurface(int surfaceType, ofTexture* texturePtr, vector<ofVec2f> vertices, vector<ofVec2f> texCoords);
ofxBaseSurface* getSurface(int index);
int size();
ofxBaseSurface* selectSurface(int index);

Loading…
Cancel
Save