From ee49f3b80f53d6ae0e433684a3dab407baaade89 Mon Sep 17 00:00:00 2001 From: Krisjanis Rijnieks Date: Fri, 2 May 2014 18:50:43 +0200 Subject: [PATCH] Add setTexCoord method to triangle surface to be able to control texture coordinates of each triangle vertex --- example/src/ofApp.cpp | 7 ++++++- src/ofxBaseSurface.h | 1 + src/ofxTriangleSurface.cpp | 10 ++++++++++ src/ofxTriangleSurface.h | 1 + 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/example/src/ofApp.cpp b/example/src/ofApp.cpp index 49e2ddc..b59ac41 100644 --- a/example/src/ofApp.cpp +++ b/example/src/ofApp.cpp @@ -16,7 +16,12 @@ void ofApp::update() ofVec2f p; p.x = ofRandomWidth(); p.y = ofRandomHeight(); - triangleSurface.setVertex(0, p); + //triangleSurface.setVertex(0, p); + + ofVec2f t; + t.x = ofRandomuf(); + t.y = ofRandomuf(); + triangleSurface.setTexCoord(0, t); } void ofApp::draw() diff --git a/src/ofxBaseSurface.h b/src/ofxBaseSurface.h index f25551f..646ff6d 100644 --- a/src/ofxBaseSurface.h +++ b/src/ofxBaseSurface.h @@ -10,6 +10,7 @@ public: virtual void setup(){}; virtual void draw(){}; virtual void setVertex(int index, ofVec2f p){}; + virtual void setTexCoord(int index, ofVec2f t){}; protected: ofMesh mesh; diff --git a/src/ofxTriangleSurface.cpp b/src/ofxTriangleSurface.cpp index a5e3c65..3694767 100644 --- a/src/ofxTriangleSurface.cpp +++ b/src/ofxTriangleSurface.cpp @@ -60,4 +60,14 @@ void ofxTriangleSurface::setVertex(int index, ofVec2f p) } mesh.setVertex(index, p); +} + +void ofxTriangleSurface::setTexCoord(int index, ofVec2f t) +{ + if ( index > 2 ) { + ofLog() << "Texture coordinate with this index does not exist: " << index << endl; + return; + } + + mesh.setTexCoord(index, t); } \ No newline at end of file diff --git a/src/ofxTriangleSurface.h b/src/ofxTriangleSurface.h index 88c49ad..9efa431 100644 --- a/src/ofxTriangleSurface.h +++ b/src/ofxTriangleSurface.h @@ -14,6 +14,7 @@ public: void setup( ofVec2f p1, ofVec2f p2, ofVec2f p3, ofVec2f t1, ofVec2f t2, ofVec2f t3, ofTexture* texturePtr ); void draw(); void setVertex( int index, ofVec2f p ); + void setTexCoord( int index, ofVec2f t ); }; #endif \ No newline at end of file