#include "ofApp.h" #include "glew.h" //-------------------------------------------------------------- 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 ofApp::gaussianElimination(float * input, int n) { auto i = 0; auto j = 0; auto m = n - 1; while (i < m && j < n) { auto iMax = i; for (auto k = i + 1; k < m; ++k) { if (fabs(input[k * n + j]) > fabs(input[iMax * n + j])) { iMax = k; } } if (input[iMax * n + j] != 0) { if (i != iMax) { for (auto k = 0; k < n; ++k) { auto ikIn = input[i * n + k]; input[i * n + k] = input[iMax * n + k]; input[iMax * n + k] = ikIn; } } float ijIn = input[i * n + j]; for (auto k = 0; k < n; ++k) { input[i * n + k] /= ijIn; } for (auto u = i + 1; u < m; ++u) { auto ujIn = input[u * n + j]; for (auto k = 0; k < n; ++k) { input[u * n + k] -= ujIn * input[i * n + k]; } } ++i; } ++j; } for (auto i = m - 2; i >= 0; --i) { for (auto j = i + 1; j < n - 1; ++j) { input[i * n + m] -= input[i * n + j] * input[j * n + m]; } } } glm::mat4 ofApp::getPerspectiveTransformMatrix(const glm::vec2 src[4], const glm::vec2 dst[4]) { float p[8][9] = { { -src[0][0], -src[0][1], -1, 0, 0, 0, src[0][0] * dst[0][0], src[0][1] * dst[0][0], -dst[0][0] }, // h11 { 0, 0, 0, -src[0][0], -src[0][1], -1, src[0][0] * dst[0][1], src[0][1] * dst[0][1], -dst[0][1] }, // h12 { -src[1][0], -src[1][1], -1, 0, 0, 0, src[1][0] * dst[1][0], src[1][1] * dst[1][0], -dst[1][0] }, // h13 { 0, 0, 0, -src[1][0], -src[1][1], -1, src[1][0] * dst[1][1], src[1][1] * dst[1][1], -dst[1][1] }, // h21 { -src[2][0], -src[2][1], -1, 0, 0, 0, src[2][0] * dst[2][0], src[2][1] * dst[2][0], -dst[2][0] }, // h22 { 0, 0, 0, -src[2][0], -src[2][1], -1, src[2][0] * dst[2][1], src[2][1] * dst[2][1], -dst[2][1] }, // h23 { -src[3][0], -src[3][1], -1, 0, 0, 0, src[3][0] * dst[3][0], src[3][1] * dst[3][0], -dst[3][0] }, // h31 { 0, 0, 0, -src[3][0], -src[3][1], -1, src[3][0] * dst[3][1], src[3][1] * dst[3][1], -dst[3][1] }, // h32 }; gaussianElimination(&p[0][0], 9); return glm::mat4(p[0][8], p[3][8], 0, p[6][8], p[1][8], p[4][8], 0, p[7][8], 0, 0, 1, 0, p[2][8], p[5][8], 0, 1); } ofPolyline ofApp::polyLineTransform(const ofPolyline& poly, ofMatrix4x4 xform){ ofPolyline tempPoly; for (auto& p:poly){ tempPoly.addVertex(ofVec3f(p)*xform); } return tempPoly; } ofPolyline ofApp::makePolygon(int num,float diam){ ofPolyline poly; float step=PI*2/num; for (int i=0;i<=num;i++){ poly.addVertex(cos(step*i)*diam,sin(step*i)*diam); } return poly; } void ofApp::drawPoly(ofPolyline poly,float x,float y){ glPushMatrix(); ofTranslate(x,y); poly.draw(); for (int i=0;i-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; } //-------------------------------------------------------------- void ofApp::mouseEntered(int x, int y){ } //-------------------------------------------------------------- void ofApp::mouseExited(int x, int y){ } //-------------------------------------------------------------- void ofApp::windowResized(int w, int h){ } void ofApp::outputWindowResized(ofResizeEventArgs &resizeargs){ } //-------------------------------------------------------------- void ofApp::gotMessage(ofMessage msg){ } //-------------------------------------------------------------- void ofApp::dragEvent(ofDragInfo dragInfo){ }