diff options
Diffstat (limited to 'gaunt01/src')
| -rw-r--r-- | gaunt01/src/outsidePolygon.cpp | 35 | ||||
| -rw-r--r-- | gaunt01/src/outsidePolygon.h | 5 | ||||
| -rw-r--r-- | gaunt01/src/testApp.cpp | 32 | ||||
| -rw-r--r-- | gaunt01/src/testApp.h | 1 |
4 files changed, 41 insertions, 32 deletions
diff --git a/gaunt01/src/outsidePolygon.cpp b/gaunt01/src/outsidePolygon.cpp new file mode 100644 index 0000000..8f9b61e --- /dev/null +++ b/gaunt01/src/outsidePolygon.cpp @@ -0,0 +1,35 @@ +#include "outsidePolygon.h" + + +bool OutsidePolygon(vector<ofPoint>& polygon,ofPoint p) +//thanks to Paul Bourke +//http://local.wasp.uwa.edu.au/~pbourke/geometry/insidepoly/ +{ + int counter = 0; + int i; + double xinters; + ofPoint p1,p2; + + p1 = polygon[0]; + for (i=1;i<=polygon.size();i++) { + p2 = polygon[i % polygon.size()]; + if (p.y > min(p1.y,p2.y)) { + if (p.y <= max(p1.y,p2.y)) { + if (p.x <= max(p1.x,p2.x)) { + if (p1.y != p2.y) { + xinters = (p.y-p1.y)*(p2.x-p1.x)/(p2.y-p1.y)+p1.x; + if (p1.x == p2.x || p.x <= xinters) + counter++; + } + } + } + } + p1 = p2; + } + + if (counter % 2 == 0) + return true; + else + return false; +} + diff --git a/gaunt01/src/outsidePolygon.h b/gaunt01/src/outsidePolygon.h new file mode 100644 index 0000000..7616241 --- /dev/null +++ b/gaunt01/src/outsidePolygon.h @@ -0,0 +1,5 @@ +#pragma once + +#include "ofMain.h" + +bool OutsidePolygon(vector<ofPoint>& polygon,ofPoint p)
\ No newline at end of file diff --git a/gaunt01/src/testApp.cpp b/gaunt01/src/testApp.cpp index 785eb5a..a78a690 100644 --- a/gaunt01/src/testApp.cpp +++ b/gaunt01/src/testApp.cpp @@ -14,38 +14,6 @@ Is this too much work for every frame? Should it be put in a seperate thread? */ -bool OutsidePolygon(vector<ofPoint>& polygon,ofPoint p) -//thanks to Paul Bourke -//http://local.wasp.uwa.edu.au/~pbourke/geometry/insidepoly/ -{ - int counter = 0; - int i; - double xinters; - ofPoint p1,p2; - - p1 = polygon[0]; - for (i=1;i<=polygon.size();i++) { - p2 = polygon[i % polygon.size()]; - if (p.y > min(p1.y,p2.y)) { - if (p.y <= max(p1.y,p2.y)) { - if (p.x <= max(p1.x,p2.x)) { - if (p1.y != p2.y) { - xinters = (p.y-p1.y)*(p2.x-p1.x)/(p2.y-p1.y)+p1.x; - if (p1.x == p2.x || p.x <= xinters) - counter++; - } - } - } - } - p1 = p2; - } - - if (counter % 2 == 0) - return true; - else - return false; -} - void testApp::setup(){ bLearnBakground = true; diff --git a/gaunt01/src/testApp.h b/gaunt01/src/testApp.h index c25defe..2ba60c4 100644 --- a/gaunt01/src/testApp.h +++ b/gaunt01/src/testApp.h @@ -13,6 +13,7 @@ #include "trapdoor.h" #include "bird.h" #include "player.h" +#include "outsidePolygon.h" //#define _USE_LIVE_VIDEO // uncomment this to use a live camera // otherwise, we'll use a movie file |
