diff options
Diffstat (limited to 'polyTest/src/ofApp.cpp')
| -rw-r--r-- | polyTest/src/ofApp.cpp | 52 |
1 files changed, 36 insertions, 16 deletions
diff --git a/polyTest/src/ofApp.cpp b/polyTest/src/ofApp.cpp index 7b87c9d..ae85d7a 100644 --- a/polyTest/src/ofApp.cpp +++ b/polyTest/src/ofApp.cpp @@ -4,18 +4,33 @@ //-------------------------------------------------------------- void ofApp::setup(){ + warpframe[0]=glm::vec2(0,0); + warpframe[1]=glm::vec2(ofGetWidth(),0); + warpframe[2]=glm::vec2(ofGetWidth(),ofGetHeight()); + warpframe[3]=glm::vec2(0,ofGetHeight()); + select_warpframe=-1; + bDrawFrame=false; +} +void ofApp::drawframe(){ + ofSetColor(255,255,255); + ofNoFill(); + for (int i=0;i<4;i++){ + ofDrawCircle(warpframe[i],25); + ofDrawLine(warpframe[i],warpframe[(i+1)%4]); + } } + //-------------------------------------------------------------- void ofApp::update(){ } -void gaussianElimination(float * input, int n) +void ofApp::gaussianElimination(float * input, int n) { auto i = 0; auto j = 0; @@ -73,7 +88,7 @@ void gaussianElimination(float * input, int n) } } -glm::mat4 getPerspectiveTransformMatrix(const glm::vec2 src[4], const glm::vec2 dst[4]) +glm::mat4 ofApp::getPerspectiveTransformMatrix(const glm::vec2 src[4], const glm::vec2 dst[4]) { float p[8][9] = { @@ -103,7 +118,7 @@ ofPolyline ofApp::polyLineTransform(const ofPolyline& poly, ofMatrix4x4 xform){ return tempPoly; } -ofPolyline makePolygon(int num,float diam){ +ofPolyline ofApp::makePolygon(int num,float diam){ ofPolyline poly; float step=PI*2/num; for (int i=0;i<=num;i++){ @@ -112,7 +127,7 @@ ofPolyline makePolygon(int num,float diam){ return poly; } -void drawPoly(ofPolyline poly,float x,float y){ +void ofApp::drawPoly(ofPolyline poly,float x,float y){ glPushMatrix(); ofTranslate(x,y); poly.draw(); @@ -139,14 +154,7 @@ void ofApp::draw(){ glm::vec2(0,ofGetHeight()) }; - glm::vec2 dst[]={ - glm::vec2(0,0), - glm::vec2(ofGetWidth(),0), - glm::vec2(ofGetWidth()-100,ofGetHeight()), - glm::vec2(100,ofGetHeight()) - }; - - ofMatrix4x4 warp =getPerspectiveTransformMatrix(src,dst); + ofMatrix4x4 warp =getPerspectiveTransformMatrix(src,warpframe); //drawPoly(polyLineTransform(makePolygon(4,200),m),200,200); //drawPoly(polyLineTransform(makePolygon(5,200),m),-200,200); @@ -154,6 +162,7 @@ void ofApp::draw(){ drawPoly(polyLineTransform(polyLineTransform(makePolygon(6,200),m),warp),0,0); + if (bDrawFrame) drawframe(); } @@ -167,7 +176,12 @@ void ofApp::exit() { //-------------------------------------------------------------- void ofApp::keyPressed(ofKeyEventArgs &args){ - + switch(args.key){ + case 'w':{ + bDrawFrame=!bDrawFrame; + break; + } + } } @@ -186,17 +200,23 @@ void ofApp::mouseMoved(int x, int y ){ //-------------------------------------------------------------- void ofApp::mouseDragged(int x, int y, int button){ - + if (select_warpframe>-1){ + warpframe[select_warpframe]=glm::vec2(x,y); + } } //-------------------------------------------------------------- void ofApp::mousePressed(int x, int y, int button){ - + for (int i=0;i<4;i++){ + if (ofPoint(x,y).distance(warpframe[i])<25){ + select_warpframe=i; + } + } } //-------------------------------------------------------------- void ofApp::mouseReleased(int x, int y, int button){ - + select_warpframe=-1; } //-------------------------------------------------------------- |
