diff --git a/src/ofxBaseSurface.cpp b/src/ofxBaseSurface.cpp index e97938a..ffafbd3 100644 --- a/src/ofxBaseSurface.cpp +++ b/src/ofxBaseSurface.cpp @@ -36,4 +36,9 @@ void ofxBaseSurface::createDefaultTexture() // Assign default texture to texture pointer texture = &defaultTexture; +} + +ofTexture* ofxBaseSurface::getTexture() +{ + return texture; } \ No newline at end of file diff --git a/src/ofxBaseSurface.h b/src/ofxBaseSurface.h index 646ff6d..89bc9c6 100644 --- a/src/ofxBaseSurface.h +++ b/src/ofxBaseSurface.h @@ -12,6 +12,8 @@ public: virtual void setVertex(int index, ofVec2f p){}; virtual void setTexCoord(int index, ofVec2f t){}; + ofTexture* getTexture(); + protected: ofMesh mesh; ofTexture* texture; diff --git a/src/ofxSurfaceGui.cpp b/src/ofxSurfaceGui.cpp index 0aca9a3..2461736 100644 --- a/src/ofxSurfaceGui.cpp +++ b/src/ofxSurfaceGui.cpp @@ -3,7 +3,7 @@ ofxSurfaceGui::ofxSurfaceGui() { surface = NULL; - mode = PROJECTION_MAPPING; + mode = TEXTURE_MAPPING; } ofxSurfaceGui::~ofxSurfaceGui() @@ -23,8 +23,14 @@ void ofxSurfaceGui::update() if (surface == NULL) return; if (mode == NONE) return; - for ( int i=0; isetVertex(i, projectionMappingJoints[i].position); + if (mode == PROJECTION_MAPPING) { + for ( int i=0; isetVertex(i, projectionMappingJoints[i].position); + } + } + } else if (mode == TEXTURE_MAPPING) { + ofVec2f textureSize = ofVec2f( surface->getTexture()->getWidth(), surface->getTexture()->getHeight() ); + for ( int i=0; isetTexCoord(i, textureMappingJoints[i].position/textureSize); + } } } } @@ -100,8 +134,9 @@ void ofxSurfaceGui::addNumProjectionMappingJoints(int num) void ofxSurfaceGui::addTextureMappingJoint() { - textureMappingJoings.push_back(ofxCircleJoint()); - //textureMappingJoings.back().position = surface->getTex + textureMappingJoints.push_back(ofxCircleJoint()); + ofVec2f textureSize = ofVec2f(surface->getTexture()->getWidth(), surface->getTexture()->getHeight()); + textureMappingJoints.back().position = surface->getTexCoord(textureMappingJoints.size()-1) * textureSize; } void ofxSurfaceGui::addNumTextureMappingJoints(int num) diff --git a/src/ofxSurfaceGui.h b/src/ofxSurfaceGui.h index aaf1f12..c383f43 100644 --- a/src/ofxSurfaceGui.h +++ b/src/ofxSurfaceGui.h @@ -32,7 +32,7 @@ private: ofxTriangleSurface* surface; vector projectionMappingJoints; - vector textureMappingJoings; + vector textureMappingJoints; void addProjectionMappingJoint(); void addNumProjectionMappingJoints(int num);