Browse Source

Add surface gui for the only surface we have here

master
Krisjanis Rijnieks 11 years ago
parent
commit
18f9055d2b
  1. 2
      example/src/ofApp.cpp
  2. 4
      example/src/ofApp.h
  3. 30
      src/ofxSurfaceGui.cpp
  4. 25
      src/ofxSurfaceGui.h
  5. 11
      src/ofxTriangleSurface.cpp
  6. 1
      src/ofxTriangleSurface.h

2
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()

4
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

30
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; i<num; i++ ) {
addJoint();
joints[i].position = surface->getVertex(i);
}
}

25
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

11
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);
}

1
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
Loading…
Cancel
Save