summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gaunt01/src/testApp.cpp78
-rw-r--r--gaunt01/src/testApp.h3
2 files changed, 73 insertions, 8 deletions
diff --git a/gaunt01/src/testApp.cpp b/gaunt01/src/testApp.cpp
index 4047f69..785eb5a 100644
--- a/gaunt01/src/testApp.cpp
+++ b/gaunt01/src/testApp.cpp
@@ -13,6 +13,39 @@ 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;
@@ -96,6 +129,8 @@ void testApp::setup(){
light.setPosition(ofGetWidth(),0,ofGetHeight());
light.enable();
+
+ drawingborder=false;
}
@@ -294,7 +329,10 @@ void testApp::update(){
players[blobsManager.blobs.at(i).id].update(blob); //create model
}
map<int,player>::iterator it;
- for (it=players.begin();it!=players.end();it++) if(ids.find(it->first)==ids.end()) it->second.active=false;
+ for (it=players.begin();it!=players.end();it++) {
+ if (ids.find(it->first)==ids.end()||(border.size()>3&&OutsidePolygon(border,ofPoint(it->second.getWorldPosition().x,it->second.getWorldPosition().y)))) it->second.active=false;
+ else it->second.active=true;
+ }
}
if (trapDoor.checkUpdate(players)) updatePlane();
Bird.update(players,cam_angle);
@@ -339,8 +377,9 @@ void testApp::draw(){
glDisable(GL_DEPTH_TEST);
ofSetHexColor(0xffffff);
colorImg.getTextureReference().bind();
+ map<int,player>::iterator it;
for(int i=0;i<blobsManager.blobs.size();i++){
- players[blobsManager.blobs.at(i).id].draw();
+ if(players[blobsManager.blobs.at(i).id].active) players[blobsManager.blobs.at(i).id].draw();
}
colorImg.getTextureReference().unbind();
@@ -432,6 +471,15 @@ void testApp::draw(){
//
}
+ if (border.size()>1) {
+ ofSetHexColor(0x00ff00);
+ ofPushMatrix();
+ ofRotate(cam_angle,1,0,0);
+ for (int i=0;i<border.size();i++) {
+ ofLine(border[i],border[(i+1)%border.size()]);
+ }
+ ofPopMatrix();
+ }
@@ -475,7 +523,7 @@ void testApp::keyPressed(int key){
cam_angle-=1;
updatePlane();
break;
- case 'q':
+ case 'q':
drawStats=!drawStats;
break;
case 's':
@@ -527,7 +575,7 @@ void testApp::keyPressed(int key){
Bird.currentseq="attack";
}
break;
-
+ /*
case 'y':
light.setPosition(light.getX(),light.getY()-100,light.getZ());
printf("light at %f,%f,%f\n",light.getX(),light.getY(),light.getZ());
@@ -552,6 +600,14 @@ void testApp::keyPressed(int key){
light.setPosition(light.getX(),light.getY(),light.getZ()-100);
printf("light at %f,%f,%f\n",light.getX(),light.getY(),light.getZ());
break;
+ */
+ case 'b':
+ if (!drawingborder) {
+ border.clear();
+ drawingborder=true;
+ }
+ else drawingborder=false;
+ break;
}
}
@@ -578,10 +634,16 @@ void testApp::mousePressed(int x, int y, int button){
//--------------------------------------------------------------
void testApp::mouseReleased(int x, int y, int button){
pos=ofVec2f(x,y);
- //if (hit) printf("ray:%i,%i hit plane:%f,%f,%f\n",x,y,pos.x,pos.y,pos.z);
- //else printf("ray:%i,%i missed plane\n",x,y);
- trapDoor.startPos(screen2plane(pos));
- updatePlane();
+ if (drawingborder) {
+ border.push_back(screen2plane(pos));
+ }
+ else {
+
+ //if (hit) printf("ray:%i,%i hit plane:%f,%f,%f\n",x,y,pos.x,pos.y,pos.z);
+ //else printf("ray:%i,%i missed plane\n",x,y);
+ trapDoor.startPos(screen2plane(pos));
+ updatePlane();
+ }
}
//--------------------------------------------------------------
diff --git a/gaunt01/src/testApp.h b/gaunt01/src/testApp.h
index ff53510..c25defe 100644
--- a/gaunt01/src/testApp.h
+++ b/gaunt01/src/testApp.h
@@ -97,6 +97,9 @@ class testApp : public ofBaseApp{
ofLight light;
ofPlane* bounds;
+
+ vector<ofPoint> border;
+ bool drawingborder;
};