From 0427680c29e5b0dfcaacf9c3f43f0473c15a1756 Mon Sep 17 00:00:00 2001 From: Krisjanis Rijnieks Date: Fri, 2 May 2014 18:44:33 +0200 Subject: [PATCH] Add setVertex method to striangle surface to be able to move its corners --- example/src/ofApp.cpp | 5 +++++ src/ofxBaseSurface.h | 1 + src/ofxTriangleSurface.cpp | 10 ++++++++++ src/ofxTriangleSurface.h | 1 + 4 files changed, 17 insertions(+) diff --git a/example/src/ofApp.cpp b/example/src/ofApp.cpp index db054b4..49e2ddc 100644 --- a/example/src/ofApp.cpp +++ b/example/src/ofApp.cpp @@ -12,6 +12,11 @@ void ofApp::setup() void ofApp::update() { ofBackground(0); + + ofVec2f p; + p.x = ofRandomWidth(); + p.y = ofRandomHeight(); + triangleSurface.setVertex(0, p); } void ofApp::draw() diff --git a/src/ofxBaseSurface.h b/src/ofxBaseSurface.h index c57816e..f25551f 100644 --- a/src/ofxBaseSurface.h +++ b/src/ofxBaseSurface.h @@ -9,6 +9,7 @@ public: ofxBaseSurface(); virtual void setup(){}; virtual void draw(){}; + virtual void setVertex(int index, ofVec2f p){}; protected: ofMesh mesh; diff --git a/src/ofxTriangleSurface.cpp b/src/ofxTriangleSurface.cpp index e2907c3..a5e3c65 100644 --- a/src/ofxTriangleSurface.cpp +++ b/src/ofxTriangleSurface.cpp @@ -50,4 +50,14 @@ void ofxTriangleSurface::draw() texture->bind(); mesh.draw(); texture->unbind(); +} + +void ofxTriangleSurface::setVertex(int index, ofVec2f p) +{ + if ( index > 2 ) { + ofLog() << "Vertex with this index does not exist: " << index << endl; + return; + } + + mesh.setVertex(index, p); } \ No newline at end of file diff --git a/src/ofxTriangleSurface.h b/src/ofxTriangleSurface.h index 7c19f64..88c49ad 100644 --- a/src/ofxTriangleSurface.h +++ b/src/ofxTriangleSurface.h @@ -13,6 +13,7 @@ public: void setup(); void setup( ofVec2f p1, ofVec2f p2, ofVec2f p3, ofVec2f t1, ofVec2f t2, ofVec2f t3, ofTexture* texturePtr ); void draw(); + void setVertex( int index, ofVec2f p ); }; #endif \ No newline at end of file