diff --git a/example/src/ofApp.cpp b/example/src/ofApp.cpp index cb4dce0..bf142e1 100644 --- a/example/src/ofApp.cpp +++ b/example/src/ofApp.cpp @@ -8,6 +8,8 @@ void ofApp::setup() // Create a triangle surface //triangleSurface.setup( ofVec2f(30,40), ofVec2f(500,500), ofVec2f(0,600), ofVec2f(0,0), ofVec2f(1,1), ofVec2f(0,1), &image.getTextureReference() ); + + gui.setup(triangleSurface); } void ofApp::update() diff --git a/example/src/ofApp.h b/example/src/ofApp.h index 5789e6a..f8707fe 100644 --- a/example/src/ofApp.h +++ b/example/src/ofApp.h @@ -4,7 +4,7 @@ #include "ofMain.h" #include "ofxPiMapper.h" -#include "ofxCircleJoint.h" +#include "ofxSurfaceGui.h" class ofApp : public ofBaseApp { @@ -21,7 +21,7 @@ public: ofxTriangleSurface triangleSurface; ofImage image; - ofxCircleJoint joint; + ofxSurfaceGui gui; }; #endif \ No newline at end of file diff --git a/src/ofxSurfaceGui.cpp b/src/ofxSurfaceGui.cpp new file mode 100644 index 0000000..032181a --- /dev/null +++ b/src/ofxSurfaceGui.cpp @@ -0,0 +1,30 @@ +#include "ofxSurfaceGui.h" + +ofxSurfaceGui::ofxSurfaceGui() +{ + jointCounter = 0; +} + +ofxSurfaceGui::~ofxSurfaceGui() +{ + +} + +void ofxSurfaceGui::setup(ofxTriangleSurface& surfaceForGui) +{ + surface = &surfaceForGui; + addNumJoints(3); +} + +void ofxSurfaceGui::addJoint() +{ + jointCounter++; +} + +void ofxSurfaceGui::addNumJoints(int num) +{ + for ( int i=0; igetVertex(i); + } +} \ No newline at end of file diff --git a/src/ofxSurfaceGui.h b/src/ofxSurfaceGui.h new file mode 100644 index 0000000..33c6f97 --- /dev/null +++ b/src/ofxSurfaceGui.h @@ -0,0 +1,25 @@ +#ifndef H_OFX_SURFACE_GUI +#define H_OFX_SURFACE_GUI + +#include "ofMain.h" +#include "ofxTriangleSurface.h" +#include "ofxCircleJoint.h" + +class ofxSurfaceGui +{ +public: + ofxSurfaceGui(); + ~ofxSurfaceGui(); + + void setup(ofxTriangleSurface& surfaceForGui); + +private: + ofxTriangleSurface* surface; + ofxCircleJoint joints[100]; + int jointCounter; + + void addJoint(); + void addNumJoints(int num); +}; + +#endif \ No newline at end of file diff --git a/src/ofxTriangleSurface.cpp b/src/ofxTriangleSurface.cpp index 3694767..62a8853 100644 --- a/src/ofxTriangleSurface.cpp +++ b/src/ofxTriangleSurface.cpp @@ -70,4 +70,15 @@ void ofxTriangleSurface::setTexCoord(int index, ofVec2f t) } mesh.setTexCoord(index, t); +} + +ofVec2f ofxTriangleSurface::getVertex(int index) +{ + if ( index > 2 ) { + ofLog() << "Vertex with this index does not exist: " << index << endl; + throw std::runtime_error("Index out of bounds."); + } + + ofVec3f vert = mesh.getVertex(index); + return ofVec2f(vert.x, vert.y); } \ No newline at end of file diff --git a/src/ofxTriangleSurface.h b/src/ofxTriangleSurface.h index 9efa431..e956a68 100644 --- a/src/ofxTriangleSurface.h +++ b/src/ofxTriangleSurface.h @@ -15,6 +15,7 @@ public: void draw(); void setVertex( int index, ofVec2f p ); void setTexCoord( int index, ofVec2f t ); + ofVec2f getVertex(int index); }; #endif \ No newline at end of file