From b674303dc4680461877e5cd9dfd124a83535ad5c Mon Sep 17 00:00:00 2001 From: sebl Date: Mon, 7 Jul 2014 10:16:55 +0000 Subject: [PATCH 1/2] modified: example-fboTexture/bin/data/defaultSurfaces.xml modified: example-fboTexture/src/ofApp.cpp modified: example-fboTexture/src/ofApp.h modified: src/ofxProjectionEditor.h modified: src/ofxSurfaceManager.cpp modified: src/ofxSurfaceManager.h modified: src/ofxSurfaceType.h modified: src/ofxTextureEditor.cpp src/ofxQuadSurface.cpp src/ofxQuadSurface.h --- .../bin/data/defaultSurfaces.xml | 0 example-fboTexture/src/ofApp.cpp | 25 ++ example-fboTexture/src/ofApp.h | 1 + src/ofxProjectionEditor.h | 0 src/ofxSurfaceManager.cpp | 234 ++++++++++++++---- src/ofxSurfaceManager.h | 1 + src/ofxSurfaceType.h | 3 +- src/ofxTextureEditor.cpp | 0 8 files changed, 210 insertions(+), 54 deletions(-) mode change 100644 => 100755 example-fboTexture/bin/data/defaultSurfaces.xml mode change 100644 => 100755 example-fboTexture/src/ofApp.cpp mode change 100644 => 100755 example-fboTexture/src/ofApp.h mode change 100644 => 100755 src/ofxProjectionEditor.h mode change 100644 => 100755 src/ofxSurfaceManager.cpp mode change 100644 => 100755 src/ofxSurfaceManager.h mode change 100644 => 100755 src/ofxSurfaceType.h mode change 100644 => 100755 src/ofxTextureEditor.cpp diff --git a/example-fboTexture/bin/data/defaultSurfaces.xml b/example-fboTexture/bin/data/defaultSurfaces.xml old mode 100644 new mode 100755 diff --git a/example-fboTexture/src/ofApp.cpp b/example-fboTexture/src/ofApp.cpp old mode 100644 new mode 100755 index 0a66d68..7012632 --- a/example-fboTexture/src/ofApp.cpp +++ b/example-fboTexture/src/ofApp.cpp @@ -64,6 +64,7 @@ void ofApp::draw() ss << " 4. Source selection mode\n\n"; ss << "You can switch between the modes by using <1>, <2>, <3> and <4> keys on the keyboard.\n\n"; ss << "Press or to add random or normal surface.\n"; + ss << "Press to add a new quad surface.\n"; ss << "Press to save the composition.\n"; ss << "Press to toggle fullscreen.\n"; ss << "Press to reassign the fbo texture to the first surface\n"; @@ -90,6 +91,7 @@ void ofApp::keyPressed(int key) case '4': gui.setMode(ofxGuiMode::SOURCE_SELECTION); break; case 'i': bShowInfo = !bShowInfo; break; case 'r': addRandomSurface(); break; + case 'q': addQuadSurface(); break; case 'n': addSurface(); break; case 'f': ofToggleFullscreen(); break; case 's': surfaceManager.saveXmlSettings("surfaces.xml"); break; @@ -116,6 +118,29 @@ void ofApp::addRandomSurface() surfaceManager.selectSurface(surfaceManager.size()-1); } +void ofApp::addQuadSurface() +{ + int surfaceType = ofxSurfaceType::QUAD_SURFACE; + vector vertices; + + int border = 50; + vertices.push_back( ofVec2f(border, border) ); + vertices.push_back( ofVec2f(border, ofGetHeight() - border) ); + vertices.push_back( ofVec2f(ofGetWidth() - border, ofGetHeight() - border) ); + vertices.push_back( ofVec2f(ofGetWidth() - border, border) ); + + 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)) ); + + surfaceManager.addSurface(surfaceType, vertices, texCoords); + + // select this surface right away + surfaceManager.selectSurface(surfaceManager.size()-1); +} + void ofApp::addSurface() { int surfaceType = ofxSurfaceType::TRIANGLE_SURFACE; diff --git a/example-fboTexture/src/ofApp.h b/example-fboTexture/src/ofApp.h old mode 100644 new mode 100755 index 39b01f8..05d7a8f --- a/example-fboTexture/src/ofApp.h +++ b/example-fboTexture/src/ofApp.h @@ -15,6 +15,7 @@ public: void keyPressed(int key); void addRandomSurface(); + void addQuadSurface(); void addSurface(); void setFboAsTexture(); diff --git a/src/ofxProjectionEditor.h b/src/ofxProjectionEditor.h old mode 100644 new mode 100755 diff --git a/src/ofxSurfaceManager.cpp b/src/ofxSurfaceManager.cpp old mode 100644 new mode 100755 index fe9faa1..e3e261b --- a/src/ofxSurfaceManager.cpp +++ b/src/ofxSurfaceManager.cpp @@ -21,7 +21,11 @@ void ofxSurfaceManager::addSurface(int surfaceType) { if ( surfaceType == ofxSurfaceType::TRIANGLE_SURFACE ) { surfaces.push_back( new ofxTriangleSurface() ); - } else { + } + else if (surfaceType == ofxSurfaceType::QUAD_SURFACE ) { + surfaces.push_back( new ofxQuadSurface() ); + } + else { throw std::runtime_error("Attempt to add non-existing surface type."); } } @@ -31,7 +35,12 @@ void ofxSurfaceManager::addSurface(int surfaceType, ofTexture* texturePtr) if ( surfaceType == ofxSurfaceType::TRIANGLE_SURFACE ) { surfaces.push_back( new ofxTriangleSurface() ); surfaces.back()->setTexture(texturePtr); - } else { + } + else if (surfaceType == ofxSurfaceType::QUAD_SURFACE ) { + surfaces.push_back( new ofxQuadSurface() ); + surfaces.back()->setTexture(texturePtr); + } + else { throw std::runtime_error("Attempt to add non-existing surface type."); } } @@ -43,7 +52,7 @@ void ofxSurfaceManager::addSurface(int surfaceType, vector vertices, ve 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."); + throw std::runtime_error("There must be 3 texture coordinates for a triangle surface."); } surfaces.push_back( new ofxTriangleSurface() ); @@ -53,7 +62,22 @@ void ofxSurfaceManager::addSurface(int surfaceType, vector vertices, ve surfaces.back()->setTexCoord(i, texCoords[i]); } - } else { + } + else if (surfaceType == ofxSurfaceType::QUAD_SURFACE ) { + if ( vertices.size() < 4 ) { + throw std::runtime_error("There must be 4 vertices for a quad surface."); + } else if (texCoords.size() < 4) { + throw std::runtime_error("There must be 4 texture coordinates for a quad surface."); + } + + surfaces.push_back( new ofxQuadSurface() ); + + for ( int i=0; i<4; 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."); } @@ -77,7 +101,23 @@ void ofxSurfaceManager::addSurface(int surfaceType, ofTexture* texturePtr, vecto surfaces.back()->setTexCoord(i, texCoords[i]); } - } else { + } + else if (surfaceType == ofxSurfaceType::QUAD_SURFACE ) { + if ( vertices.size() < 4 ) { + throw std::runtime_error("There must be 4 vertices for a quad surface."); + } else if (texCoords.size() < 4) { + throw std::runtime_error("Thre must be 4 texture coordinates for a quad surface."); + } + + surfaces.push_back( new ofxQuadSurface() ); + surfaces.back()->setTexture(texturePtr); + + for ( int i=0; i<4; 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."); } } @@ -138,6 +178,16 @@ void ofxSurfaceManager::clear() } } +// String getTypeString(ofxSurfaceType e) +// { +// switch e +// { +// case TRINAGLE_SURFACE: return "TRINAGLE_SURFACE"; +// case QUAD_SURFACE: return "QUAD_SURFACE"; +// default: throw Exception("Bad MyEnum"); +// } +// } + void ofxSurfaceManager::saveXmlSettings(string fileName) { xmlSettings.clear(); @@ -147,10 +197,9 @@ void ofxSurfaceManager::saveXmlSettings(string fileName) xmlSettings.pushTag("surfaces"); for ( int i=0; i* vertices = &surface->getVertices(); @@ -186,9 +235,16 @@ void ofxSurfaceManager::saveXmlSettings(string fileName) xmlSettings.addValue("source-type", "image"); xmlSettings.addValue("source-name", getSurfaceSourceName(surface)); //xmlSettings.addValue("source-path", "/root/etc/image.jpg"); - xmlSettings.popTag(); // source - + + + // xmlSettings.addTag("type"); + // xmlSettings.pushTag("type"); + // // surfaceType == ofxSurfaceType::TRIANGLE_SURFACE + // ofxSurfaceType surfaceType = &surface->getType(); + // xmlSettings.addValue("surface-type", surfaceType); + // xmlSettings.popTag(); // type + xmlSettings.popTag(); // surface } xmlSettings.popTag(); // surfaces @@ -198,6 +254,8 @@ void ofxSurfaceManager::saveXmlSettings(string fileName) void ofxSurfaceManager::loadXmlSettings(string fileName) { + ofLog(OF_LOG_WARNING, "A load XML settings..."); + if (!xmlSettings.loadFile(fileName)){ ofLog(OF_LOG_WARNING, "Could not load XML settings."); return; @@ -225,55 +283,125 @@ void ofxSurfaceManager::loadXmlSettings(string fileName) sourceTexture = loadImageSource(sourceName, ss.str()); } xmlSettings.popTag(); // source - + + // // attempt to load surface type + // ofLog(OF_LOG_WARNING, "Attempt to load surface type."); + // xmlSettings.pushTag("type"); + // string surfaceType = xmlSettings.getValue("surface-type", "TRIANGLE_SURFACE"); + // xmlSettings.popTag(); // type + // get vertices (only for triangle surface for now) xmlSettings.pushTag("vertices"); vector vertices; - - xmlSettings.pushTag("vertex", 0); - vertices.push_back( ofVec2f( xmlSettings.getValue("x", 0.0f), xmlSettings.getValue("y", 0.0f) ) ); - xmlSettings.popTag(); - - xmlSettings.pushTag("vertex", 1); - vertices.push_back( ofVec2f( xmlSettings.getValue("x", 100.0f), xmlSettings.getValue("y", 0.0f) ) ); - xmlSettings.popTag(); - - xmlSettings.pushTag("vertex", 2); - vertices.push_back( ofVec2f( xmlSettings.getValue("x", 0.0f), xmlSettings.getValue("y", 100.0f) ) ); - xmlSettings.popTag(); - - xmlSettings.popTag(); // vertices - - // get texture coordinates (only for triangle surfaces for now) - xmlSettings.pushTag("texCoords"); - - vector texCoords; - - xmlSettings.pushTag("texCoord", 0); - texCoords.push_back( ofVec2f( xmlSettings.getValue("x", 0.0f), xmlSettings.getValue("y", 0.0f) ) ); - xmlSettings.popTag(); - - xmlSettings.pushTag("texCoord", 1); - texCoords.push_back( ofVec2f( xmlSettings.getValue("x", 1.0f), xmlSettings.getValue("y", 0.0f) ) ); - xmlSettings.popTag(); - - xmlSettings.pushTag("texCoord", 2); - texCoords.push_back( ofVec2f( xmlSettings.getValue("x", 0.0f), xmlSettings.getValue("y", 1.0f) ) ); - xmlSettings.popTag(); - - xmlSettings.popTag(); // texCoords - - - // now we have variables sourceName and sourceTexture - // by checking those we can use one or another addSurface method - if ( sourceName != "none" && sourceTexture != NULL ) { - addSurface(ofxSurfaceType::TRIANGLE_SURFACE, sourceTexture, vertices, texCoords); - } else { - addSurface(ofxSurfaceType::TRIANGLE_SURFACE, vertices, texCoords); + + int vertexCount = vertices.size(); + // int vertexCount = vertices->size() + + //it's a triangle ? + if (vertexCount == 3) + // if (surfaceType == TRIANGLE_SURFACE) + { + xmlSettings.pushTag("vertex", 0); + vertices.push_back( ofVec2f( xmlSettings.getValue("x", 0.0f), xmlSettings.getValue("y", 0.0f) ) ); + xmlSettings.popTag(); + + xmlSettings.pushTag("vertex", 1); + vertices.push_back( ofVec2f( xmlSettings.getValue("x", 100.0f), xmlSettings.getValue("y", 0.0f) ) ); + xmlSettings.popTag(); + + xmlSettings.pushTag("vertex", 2); + vertices.push_back( ofVec2f( xmlSettings.getValue("x", 0.0f), xmlSettings.getValue("y", 100.0f) ) ); + xmlSettings.popTag(); + + xmlSettings.popTag(); // vertices + + xmlSettings.pushTag("texCoords"); + + vector texCoords; + + xmlSettings.pushTag("texCoord", 0); + texCoords.push_back( ofVec2f( xmlSettings.getValue("x", 0.0f), xmlSettings.getValue("y", 0.0f) ) ); + xmlSettings.popTag(); + + xmlSettings.pushTag("texCoord", 1); + texCoords.push_back( ofVec2f( xmlSettings.getValue("x", 1.0f), xmlSettings.getValue("y", 0.0f) ) ); + xmlSettings.popTag(); + + xmlSettings.pushTag("texCoord", 2); + texCoords.push_back( ofVec2f( xmlSettings.getValue("x", 0.0f), xmlSettings.getValue("y", 1.0f) ) ); + xmlSettings.popTag(); + + xmlSettings.popTag(); // texCoords + + + // now we have variables sourceName and sourceTexture + // by checking those we can use one or another addSurface method + if ( sourceName != "none" && sourceTexture != NULL ) { + addSurface(ofxSurfaceType::TRIANGLE_SURFACE, sourceTexture, vertices, texCoords); + } else { + addSurface(ofxSurfaceType::TRIANGLE_SURFACE, vertices, texCoords); + } + + xmlSettings.popTag(); // surface + } + // it's a quad ? + else if (vertexCount == 4) + // if (surface-type == QUAD_SURFACE) + { + ofSendMessage("create Quad"); + + xmlSettings.pushTag("vertex", 0); + vertices.push_back( ofVec2f( xmlSettings.getValue("x", 0.0f), xmlSettings.getValue("y", 0.0f) ) ); + xmlSettings.popTag(); + + xmlSettings.pushTag("vertex", 1); + vertices.push_back( ofVec2f( xmlSettings.getValue("x", 100.0f), xmlSettings.getValue("y", 0.0f) ) ); + xmlSettings.popTag(); + + xmlSettings.pushTag("vertex", 2); + vertices.push_back( ofVec2f( xmlSettings.getValue("x", 100.0f), xmlSettings.getValue("y", 100.0f) ) ); + xmlSettings.popTag(); + + xmlSettings.pushTag("vertex", 3); + vertices.push_back( ofVec2f( xmlSettings.getValue("x", 0.0f), xmlSettings.getValue("y", 100.0f) ) ); + xmlSettings.popTag(); + + xmlSettings.popTag(); // vertices + + xmlSettings.pushTag("texCoords"); + + vector texCoords; + + xmlSettings.pushTag("texCoord", 0); + texCoords.push_back( ofVec2f( xmlSettings.getValue("x", 0.0f), xmlSettings.getValue("y", 0.0f) ) ); + xmlSettings.popTag(); + + xmlSettings.pushTag("texCoord", 1); + texCoords.push_back( ofVec2f( xmlSettings.getValue("x", 1.0f), xmlSettings.getValue("y", 0.0f) ) ); + xmlSettings.popTag(); + + xmlSettings.pushTag("texCoord", 2); + texCoords.push_back( ofVec2f( xmlSettings.getValue("x", 1.0f), xmlSettings.getValue("y", 1.0f) ) ); + xmlSettings.popTag(); + + xmlSettings.pushTag("texCoord", 3); + texCoords.push_back( ofVec2f( xmlSettings.getValue("x", 0.0f), xmlSettings.getValue("y", 1.0f) ) ); + xmlSettings.popTag(); + + xmlSettings.popTag(); // texCoords + + + // now we have variables sourceName and sourceTexture + // by checking those we can use one or another addSurface method + if ( sourceName != "none" && sourceTexture != NULL ) { + addSurface(ofxSurfaceType::QUAD_SURFACE, sourceTexture, vertices, texCoords); + } else { + addSurface(ofxSurfaceType::QUAD_SURFACE, vertices, texCoords); + } + + xmlSettings.popTag(); // surface } - - xmlSettings.popTag(); // surface } xmlSettings.popTag(); // surfaces diff --git a/src/ofxSurfaceManager.h b/src/ofxSurfaceManager.h old mode 100644 new mode 100755 index 2dae777..90e8bb1 --- a/src/ofxSurfaceManager.h +++ b/src/ofxSurfaceManager.h @@ -3,6 +3,7 @@ #include "ofxBaseSurface.h" #include "ofxTriangleSurface.h" +#include "ofxQuadSurface.h" #include "ofxSurfaceType.h" #include "ofEvents.h" #include "ofxXmlSettings.h" diff --git a/src/ofxSurfaceType.h b/src/ofxSurfaceType.h old mode 100644 new mode 100755 index 5914130..cbda131 --- a/src/ofxSurfaceType.h +++ b/src/ofxSurfaceType.h @@ -4,7 +4,8 @@ struct ofxSurfaceType { enum { - TRIANGLE_SURFACE + TRIANGLE_SURFACE, + QUAD_SURFACE }; }; diff --git a/src/ofxTextureEditor.cpp b/src/ofxTextureEditor.cpp old mode 100644 new mode 100755 From 6099c436bf5b9c52171618003923513cac16b1b8 Mon Sep 17 00:00:00 2001 From: sebl Date: Mon, 7 Jul 2014 10:18:07 +0000 Subject: [PATCH 2/2] edit ofxSurfaceManager.cpp new file: src/ofxQuadSurface.cpp new file: src/ofxQuadSurface.h src/ofxQuadSurface.cpp --- src/ofxQuadSurface.cpp | 156 ++++++++++++++++++++++++++++++++++++++ src/ofxQuadSurface.h | 34 +++++++++ src/ofxSurfaceManager.cpp | 23 +++--- 3 files changed, 200 insertions(+), 13 deletions(-) create mode 100644 src/ofxQuadSurface.cpp create mode 100755 src/ofxQuadSurface.h mode change 100755 => 100644 src/ofxSurfaceManager.cpp diff --git a/src/ofxQuadSurface.cpp b/src/ofxQuadSurface.cpp new file mode 100644 index 0000000..68f8c7e --- /dev/null +++ b/src/ofxQuadSurface.cpp @@ -0,0 +1,156 @@ +#include "ofxQuadSurface.h" + +ofxQuadSurface::ofxQuadSurface() +{ + cout << "ofxQuadSurface constructor." << endl; + setup(); +} + +ofxQuadSurface::~ofxQuadSurface() +{ + cout << "ofxQuadSurface destructor." << endl; +} + +void ofxQuadSurface::setup() +{ + // Create 4 points for the 2 triangles + ofVec2f p1 = ofVec2f(0, 0); + ofVec2f p2 = ofVec2f(0, ofGetHeight()); + ofVec2f p3 = ofVec2f(ofGetWidth(), ofGetHeight()); + ofVec2f p4 = ofVec2f(ofGetWidth(), 0); + + // Create 4 point for the texture coordinates + ofVec2f t1 = ofVec2f(ofVec2f(0.0f, 0.0f)); + ofVec2f t2 = ofVec2f(ofVec2f(1.0f, 0.0f)); + ofVec2f t3 = ofVec2f(ofVec2f(1.0f, 1.0f)); + ofVec2f t4 = ofVec2f(ofVec2f(0.0f, 1.0f)); + + setup( p1, p2, p3, p4, t1, t2, t3, t4, texture ); +} + +void ofxQuadSurface::setup( ofVec2f p1, ofVec2f p2, ofVec2f p3, ofVec2f p4, + ofVec2f t1, ofVec2f t2, ofVec2f t3, ofVec2f t4, ofTexture* texturePtr ) +{ + // Assign texture + texture = texturePtr; + + // Clear mesh + mesh.clear(); + + // Create a surface with the points + mesh.addVertex( p1 ); + mesh.addVertex( p2 ); + mesh.addVertex( p3 ); + mesh.addVertex( p4 ); + + // Add 2 triangles + mesh.addTriangle(0, 2, 3); + mesh.addTriangle(0, 1, 2); + + // Add texture coordinates + mesh.addTexCoord(t1); + mesh.addTexCoord(t2); + mesh.addTexCoord(t3); + mesh.addTexCoord(t4); +} + +void ofxQuadSurface::draw() +{ + texture->bind(); + mesh.draw(); + texture->unbind(); +} + +void ofxQuadSurface::setVertex(int index, ofVec2f p) +{ + if ( index > 3 ) { + ofLog() << "Vertex with this index does not exist: " << index << endl; + return; + } + + mesh.setVertex(index, p); +} + +void ofxQuadSurface::setTexCoord(int index, ofVec2f t) +{ + if ( index > 3 ) { + ofLog() << "Texture coordinate with this index does not exist: " << index << endl; + return; + } + + mesh.setTexCoord(index, t); +} + +int ofxQuadSurface::getType() +{ + return ofxSurfaceType::QUAD_SURFACE; +} + +bool ofxQuadSurface::hitTest(ofVec2f p) +{ + // Construct ofPolyline from vertices + ofPolyline line = getHitArea(); + + if ( line.inside(p.x, p.y) ) { + return true; + } else { + return false; + } +} + +ofVec2f ofxQuadSurface::getVertex(int index) +{ + if ( index > 3 ) { + ofLog() << "Vertex with this index does not exist: " << index << endl; + throw std::runtime_error("Vertex index out of bounds."); + } + + ofVec3f vert = mesh.getVertex(index); + return ofVec2f(vert.x, vert.y); +} + +ofVec2f ofxQuadSurface::getTexCoord(int index) +{ + if (index > 3) { + throw std::runtime_error("Texture coordinate index out of bounds."); + } + + return mesh.getTexCoord(index); +} + +ofPolyline ofxQuadSurface::getHitArea() +{ + ofPolyline line; + line.addVertex( ofPoint( mesh.getVertex(0).x, mesh.getVertex(0).y ) ); + line.addVertex( ofPoint( mesh.getVertex(1).x, mesh.getVertex(1).y ) ); + line.addVertex( ofPoint( mesh.getVertex(2).x, mesh.getVertex(2).y ) ); + line.addVertex( ofPoint( mesh.getVertex(3).x, mesh.getVertex(3).y ) ); + line.close(); + + return line; +} + +ofPolyline ofxQuadSurface::getTextureHitArea() +{ + ofPolyline line; + vector& texCoords = mesh.getTexCoords(); + ofVec2f textureSize = ofVec2f(texture->getWidth(), texture->getHeight()); + for ( int i=0; i& ofxQuadSurface::getVertices() +{ + // return only joint vertices + return mesh.getVertices(); +} + +vector& ofxQuadSurface::getTexCoords() +{ + + return mesh.getTexCoords(); +} \ No newline at end of file diff --git a/src/ofxQuadSurface.h b/src/ofxQuadSurface.h new file mode 100755 index 0000000..f2b8164 --- /dev/null +++ b/src/ofxQuadSurface.h @@ -0,0 +1,34 @@ +#ifndef H_OFX_QUAD_SURFACE +#define H_OFX_QUAD_SURFACE + +#include "ofMain.h" +#include "ofxBaseSurface.h" +#include "ofxSurfaceType.h" + +class ofxQuadSurface : public ofxBaseSurface +{ +public: + ofxQuadSurface(); + ~ofxQuadSurface(); + + void setup(); + + void setup( ofVec2f p1, ofVec2f p2, ofVec2f p3, ofVec2f p4, + ofVec2f t1, ofVec2f t2, ofVec2f t3, ofVec2f t4, + ofTexture* texturePtr ); + + void draw(); + void setVertex( int index, ofVec2f p ); + void setTexCoord( int index, ofVec2f t ); + + int getType(); + bool hitTest(ofVec2f p); + ofVec2f getVertex(int index); + ofVec2f getTexCoord(int index); + ofPolyline getHitArea(); + ofPolyline getTextureHitArea(); + vector& getVertices(); + vector& getTexCoords(); +}; + +#endif \ No newline at end of file diff --git a/src/ofxSurfaceManager.cpp b/src/ofxSurfaceManager.cpp old mode 100755 new mode 100644 index e3e261b..e7df328 --- a/src/ofxSurfaceManager.cpp +++ b/src/ofxSurfaceManager.cpp @@ -197,9 +197,10 @@ void ofxSurfaceManager::saveXmlSettings(string fileName) xmlSettings.pushTag("surfaces"); for ( int i=0; i* vertices = &surface->getVertices(); @@ -254,7 +255,7 @@ void ofxSurfaceManager::saveXmlSettings(string fileName) void ofxSurfaceManager::loadXmlSettings(string fileName) { - ofLog(OF_LOG_WARNING, "A load XML settings..."); + if (!xmlSettings.loadFile(fileName)){ ofLog(OF_LOG_WARNING, "Could not load XML settings."); @@ -271,7 +272,6 @@ void ofxSurfaceManager::loadXmlSettings(string fileName) int numSurfaces = xmlSettings.getNumTags("surface"); for ( int i=0; i vertices; - int vertexCount = vertices.size(); - // int vertexCount = vertices->size() + int vertexCount = xmlSettings.getNumTags("vertex"); + //it's a triangle ? if (vertexCount == 3) - // if (surfaceType == TRIANGLE_SURFACE) { + ofLog(OF_LOG_NOTICE, "create Triangle"); xmlSettings.pushTag("vertex", 0); vertices.push_back( ofVec2f( xmlSettings.getValue("x", 0.0f), xmlSettings.getValue("y", 0.0f) ) ); xmlSettings.popTag(); @@ -342,15 +341,11 @@ void ofxSurfaceManager::loadXmlSettings(string fileName) } else { addSurface(ofxSurfaceType::TRIANGLE_SURFACE, vertices, texCoords); } - - xmlSettings.popTag(); // surface } // it's a quad ? else if (vertexCount == 4) // if (surface-type == QUAD_SURFACE) { - ofSendMessage("create Quad"); - xmlSettings.pushTag("vertex", 0); vertices.push_back( ofVec2f( xmlSettings.getValue("x", 0.0f), xmlSettings.getValue("y", 0.0f) ) ); xmlSettings.popTag(); @@ -400,8 +395,10 @@ void ofxSurfaceManager::loadXmlSettings(string fileName) addSurface(ofxSurfaceType::QUAD_SURFACE, vertices, texCoords); } - xmlSettings.popTag(); // surface + } + + xmlSettings.popTag(); // surface } xmlSettings.popTag(); // surfaces