Skip to content

Instantly share code, notes, and snippets.

@tgfrerer
Created September 29, 2016 20:24
Show Gist options
  • Save tgfrerer/ae38a263a881526415d38fe3723b3463 to your computer and use it in GitHub Desktop.
Save tgfrerer/ae38a263a881526415d38fe3723b3463 to your computer and use it in GitHub Desktop.
#include "ofMain.h"
ofPolyline polyline;
uint64_t pointFlags = -1;
class ofApp : public ofBaseApp
{
public:
void reset(){
polyline.addVertex( 100, 200, 0 );
polyline.addVertex( 100, 200, 0 );
polyline.addVertex( 50, 377, 0 );
polyline.addVertex( 762, 300, 0 );
polyline.addVertex( 400, 100, 0 );
polyline.addVertex( 762, 300, 0 );
for ( std::size_t i = 0; i < polyline.size(); ++i ){
ofLog() << "Pos " << i << " : " << polyline[i];
ofVec3f tangentPoint = polyline.getTangentAtIndex( i );
ofLog() << "Tangent " << i << " : " << tangentPoint << " / " << tangentPoint.getNormalized();
ofVec3f normalPoint = polyline.getNormalAtIndex( i );
ofLog() << "Normal " << i << " : " << normalPoint << " / " << normalPoint.getNormalized();
ofLog() << "Angle " << i << " : " << polyline.getAngleAtIndex( i );
ofLog() << std::endl;
}
uint64_t pointFlags = -1;
}
void setup(){
reset();
};
void draw(){
ofSetBackgroundColor( ofColor::black );
ofSetColor( ofColor::blue );
polyline.draw();
for ( std::size_t i = 0; i < polyline.size(); ++i ){
if ( ( 1 << (i % 10) ) & pointFlags ){
auto & p = polyline[i];
ofSetColor( ofColor::white );
ofDrawBitmapString( ofToString( i ), p );
ofSetColor( ofColor::green );
ofVec3f t = polyline.getTangentAtIndex( i );
ofDrawLine( p, p + t * 30 );
ofSetColor( ofColor::red );
ofVec3f n = polyline.getNormalAtIndex( i );
ofDrawLine( p, p + n * 30 );
}
}
ostringstream text;
text << "test #5228 / shortcuts: " << endl;
text << "0-9: toggle point info drawing for vertex" << endl;
text << "a,n: toggle point info for all/none" << endl;
text << "+,-: resample by count (add/remove 4 vertices)" << endl;
text << "r/R: reset to start screen / create random elements" << endl;
ofDrawBitmapStringHighlight( text.str(), 20, ofGetHeight() - 16 * 5 );
};
void keyReleased( int key ){
if ( key >= '0' && key <= '9' ){
uint64_t keyInt = key - '0';
ofLog() << "Toggle point: " << ( '0' + keyInt );
pointFlags ^= ( 1ULL << keyInt );
} else if ( key == 'a' ){
pointFlags = -1;
} else if ( key == 'n' ){
pointFlags = 0;
} else if ( key == '+' ){
polyline = polyline.getResampledByCount( polyline.size() + 4 );
} else if ( key == '-' ){
polyline = polyline.getResampledByCount( std::max<int>( 0, int( polyline.size() ) - 4 ) );
} else if ( key == 'r' ){
reset();
} else if ( key == 'R' ){
for ( auto&p : polyline ){
p = ofVec3f( ofRandomWidth(), ofRandomHeight(),0 );
}
}
};
};
//========================================================================
int main( ){
ofSetupOpenGL(1024,768,OF_WINDOW); // <-------- setup the GL context
// this kicks off the running of my app
// can be OF_WINDOW or OF_FULLSCREEN
// pass in width and height too:
ofRunApp(new ofApp());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment