summaryrefslogtreecommitdiff
path: root/polyTest/src
diff options
context:
space:
mode:
authorTim Redfern <tim@getdrop.com>2018-01-30 21:13:32 +0000
committerTim Redfern <tim@getdrop.com>2018-01-30 21:13:32 +0000
commitd5286b2a84704e6b1a9c845cda1bf44679158a5f (patch)
treecf69a54f64b89013c3f2542bd4a189da2aaa2929 /polyTest/src
parentb1744ad133b8543a3072897602ee33f6781655da (diff)
vector warp good
Diffstat (limited to 'polyTest/src')
-rw-r--r--polyTest/src/main.cpp1
-rw-r--r--polyTest/src/ofApp.cpp52
-rw-r--r--polyTest/src/ofApp.h9
3 files changed, 46 insertions, 16 deletions
diff --git a/polyTest/src/main.cpp b/polyTest/src/main.cpp
index 02b6b14..efc8ee4 100644
--- a/polyTest/src/main.cpp
+++ b/polyTest/src/main.cpp
@@ -20,5 +20,6 @@ int main(int argc, char *argv[]){
ofRunApp(mainWindow, mainApp);
ofRunMainLoop();
+
}
\ No newline at end of file
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;
}
//--------------------------------------------------------------
diff --git a/polyTest/src/ofApp.h b/polyTest/src/ofApp.h
index 4066c30..121d25f 100644
--- a/polyTest/src/ofApp.h
+++ b/polyTest/src/ofApp.h
@@ -28,6 +28,15 @@ class ofApp : public ofBaseApp{
void dragEvent(ofDragInfo dragInfo);
void gotMessage(ofMessage msg);
+ void drawframe();
+ void gaussianElimination(float * input, int n);
+ glm::mat4 getPerspectiveTransformMatrix(const glm::vec2 src[4], const glm::vec2 dst[4]);
ofPolyline polyLineTransform(const ofPolyline& poly, ofMatrix4x4 xform);
+ ofPolyline makePolygon(int num,float diam);
+ void drawPoly(ofPolyline poly,float x,float y);
+ glm::vec2 warpframe[4];
+ int select_warpframe;
+
+ bool bDrawFrame;
};