summaryrefslogtreecommitdiff
path: root/gaunt01
diff options
context:
space:
mode:
Diffstat (limited to 'gaunt01')
-rw-r--r--gaunt01/bin/data/TextureTrapdoor.jpgbin95259 -> 104698 bytes
-rw-r--r--gaunt01/bin/data/settings.xml2
-rw-r--r--gaunt01/gaunt01.layout22
-rw-r--r--gaunt01/src/testApp.cpp299
-rw-r--r--gaunt01/src/testApp.h22
-rw-r--r--gaunt01/src/trapdoor.cpp51
-rw-r--r--gaunt01/src/trapdoor.h8
7 files changed, 236 insertions, 168 deletions
diff --git a/gaunt01/bin/data/TextureTrapdoor.jpg b/gaunt01/bin/data/TextureTrapdoor.jpg
index 8815737..d3447ba 100644
--- a/gaunt01/bin/data/TextureTrapdoor.jpg
+++ b/gaunt01/bin/data/TextureTrapdoor.jpg
Binary files differ
diff --git a/gaunt01/bin/data/settings.xml b/gaunt01/bin/data/settings.xml
index 22f206b..5b23dd9 100644
--- a/gaunt01/bin/data/settings.xml
+++ b/gaunt01/bin/data/settings.xml
@@ -1,2 +1,2 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<gauntlet cam_angle="-59" threshold="20" />
+<gauntlet cam_angle="-55" threshold="20" />
diff --git a/gaunt01/gaunt01.layout b/gaunt01/gaunt01.layout
deleted file mode 100644
index c2ecf4b..0000000
--- a/gaunt01/gaunt01.layout
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
-<CodeBlocks_layout_file>
- <ActiveTarget name="Debug" />
- <File name="addons.make" open="1" top="0" tabpos="2">
- <Cursor position="31" topLine="0" />
- </File>
- <File name="config.make" open="0" top="0" tabpos="3">
- <Cursor position="192" topLine="0" />
- </File>
- <File name="src/testApp.cpp" open="0" top="0" tabpos="1">
- <Cursor position="4771" topLine="162" />
- </File>
- <File name="src/testApp.h" open="1" top="1" tabpos="1">
- <Cursor position="1151" topLine="28" />
- </File>
- <File name="src/trapdoor.cpp" open="0" top="0" tabpos="0">
- <Cursor position="1102" topLine="0" />
- </File>
- <File name="src/trapdoor.h" open="1" top="0" tabpos="3">
- <Cursor position="258" topLine="0" />
- </File>
-</CodeBlocks_layout_file>
diff --git a/gaunt01/src/testApp.cpp b/gaunt01/src/testApp.cpp
index 3b81cdd..87a51c4 100644
--- a/gaunt01/src/testApp.cpp
+++ b/gaunt01/src/testApp.cpp
@@ -11,15 +11,23 @@ void testApp::setup(){
loadSettings("settings.xml");
- #ifdef _USE_LIVE_VIDEO
+ vidPlayer.loadMovie("camoutput.mov"); //footage/ camera needs to be the same res as opencv planes and output
+ vidPlayer.setLoopState(OF_LOOP_NORMAL);
vidGrabber.setVerbose(true);
- vidGrabber.initGrabber(320,240);
- #else
- vidPlayer.loadMovie("camoutput.wmv"); //footage/ camera needs to be the same res as opencv planes and output
- vidPlayer.play();
- #endif
+ if (vidGrabber.initGrabber(640,480)) {
+ hasCamera=true;
+ useCamera=true;
+ }
+ else
+ {
+ hasCamera=false;
+ useCamera=false;
+ vidPlayer.play();
+ }
+
colorImg.allocate(640,480);
+ colorImg.setUseTexture(true);
grayImage.allocate(640,480);
grayBg.allocate(640,480);
grayDiff.allocate(640,480);
@@ -37,11 +45,53 @@ void testApp::setup(){
cam=ofCamera();
cam.setPosition(ofGetWidth()/2,ofGetHeight()/2,-ofGetWidth());
cam.lookAt(ofVec3f(ofGetWidth()/2,ofGetHeight()/2,0),ofVec3f(0, -1, 0));
- cam.setFov(42.0); //39.85); //53.13);
+ cam.setFov(41.0); //39.85); //53.13);
- trapDoor=trapdoor(ofRectangle(0,ofGetHeight()/4,ofGetHeight(),ofGetHeight()),ofVec2f(20,20));
+ updatePlane();
+ mode=PLAY;
+}
+
+ofVec2f testApp::screen2plane(ofVec2f screenpos){
+ ofVec3f p;
+ ray=projector.castPixel(screenpos.x,screenpos.y);
+ bool hit = plane.intersect(ray,p);
+ return ofVec2f(p.x,pow(pow(p.y,2)+pow(p.z,2),0.5f));
+}
+ofVec3f testApp::plane2world(ofVec2f planepos){
+ return ofVec3f(planepos.x,planepos.y,0);
+}
+
+void testApp::updatePlane(){
+ plane.setNormal(ofVec3f(0,sin(cam_angle*0.01745329),-cos(cam_angle*0.01745329)));
+ trapDoor=trapdoor(screen2plane(ofVec2f(ofGetWidth(),0)),screen2plane(ofVec2f(ofGetWidth(),ofGetHeight())),ofVec2f(20,20));
+ //create ground mesh with hole for trapdoor
+ ground=ofMesh();
+ ground.addVertex(plane2world(screen2plane(ofVec2f(0,0))));
+ ground.addTexCoord(ofVec2f(0,0));
+ ground.addVertex(plane2world(screen2plane(ofVec2f(ofGetWidth(),0))));
+ ground.addTexCoord(ofVec2f(1,0));
+ ground.addVertex(plane2world(screen2plane(ofVec2f(ofGetWidth(),ofGetHeight()))));
+ ground.addTexCoord(ofVec2f(1,1));
+ ground.addVertex(plane2world(screen2plane(ofVec2f(0,ofGetHeight()))));
+ ground.addTexCoord(ofVec2f(0,1));
+
+ ground.addTriangle(0,2,1);
+ ground.addTriangle(0,3,2);
+
+ /*
+ vector<ofVec2f> corners=trapDoor.getCorners();
+ for (int i=0;i<corners.size();i++) {
+ ground.addVertex(plane2world(corners[0]));
+ ground.addTexCoord(trapDoor.bounds2UV(corners[0]));
+ }
+ //join a quad for each side
+ for (int i=0;i<corners.size();i++) {
+ ground.addTriangle(i,i+4,i+1);
+ ground.addTriangle(i+4,(i+5)%ground.getNumVertices(),i+1);
+ }
+ */
}
@@ -51,21 +101,21 @@ void testApp::update(){
bool bNewFrame = false;
- #ifdef _USE_LIVE_VIDEO
- vidGrabber.grabFrame();
- bNewFrame = vidGrabber.isFrameNew();
- #else
- vidPlayer.idleMovie();
- bNewFrame = vidPlayer.isFrameNew();
- #endif
+ if (useCamera) {
+ vidGrabber.grabFrame();
+ bNewFrame = vidGrabber.isFrameNew();
+ }else {
+ vidPlayer.idleMovie();
+ bNewFrame = vidPlayer.isFrameNew();
+ }
if (bNewFrame){
- #ifdef _USE_LIVE_VIDEO
- colorImg.setFromPixels(vidGrabber.getPixels(), 320,240);
- #else
+ if (useCamera) {
+ colorImg.setFromPixels(vidGrabber.getPixels(), 640,480);
+ }else {
colorImg.setFromPixels(vidPlayer.getPixels(), 640,480);
- #endif
+ }
grayImage = colorImg;
if (bLearnBakground == true){
@@ -88,115 +138,103 @@ void testApp::update(){
//--------------------------------------------------------------
void testApp::draw(){
-
- /*
- // draw the incoming, the grayscale, the bg and the thresholded difference
- ofSetHexColor(0xffffff);
- colorImg.draw(20,20);
- grayImage.draw(360,20);
- grayBg.draw(20,280);
- grayDiff.draw(360,280);
-
- // then draw the contours:
- */
- ofFill();
- ofSetHexColor(0x333333);
- //ofRect(360,540,320,240);
- ofSetHexColor(0xa0a0a0);
-
- // we could draw the whole contour finder
- //contourFinder.draw(360,540);
-
- //keep running background average- how do you use a custom background
-
-
- colorImg.draw(0,0,ofGetWidth(),ofGetHeight());
-
cam.begin();
- ofPushMatrix();
-
- ofRotate(cam_angle,1,0,0);
- //cam.Rotate(cam_angle,1,0,0);
-
- for (float i=0;i<=ofGetWidth();i+=ofGetWidth()/10) {
- glBegin(GL_LINES);
- glVertex3f(i,0,0);
- glVertex3f(i,ofGetWidth(),0);
- glEnd();
- glBegin(GL_LINES);
- glVertex3f(0,i,0);
- glVertex3f(ofGetWidth(),i,0);
- glEnd();
- }
-
- ofPopMatrix();
-
- //ofSphere(pos.x,pos.y,pos.z,5);
-
- vector<ofVec3f> newPlayers;
- float movethresh=10;
-
- for (int i = 0; i < contourFinder.nBlobs; i++){
- //do some bounds checking, size threshold and overlap removal
- //in order to translate blobs into players
- //attempt to track players - maintain ID no
- //attempt to base blobs
- //TODO attempt to estimate bounds shape
- //project all of this into the 3D space
- ofRectangle r=contourFinder.blobs[i].boundingRect;
-
- ofVec2f blobBase=ofVec2f(r.x+(r.width/2),r.y+r.height-(r.width/2));
-
- contourFinder.blobs[i].draw(0,0);
- ofPoint p=contourFinder.blobs[i].centroid;
-
- ofSetHexColor(0xffff00);
-
- char numStr[16];
- sprintf(numStr, "%i", i);
- ofDrawBitmapString(numStr, r.x, r.y);
-
- ofVec3f pp;
- ray=projector.castPixel(blobBase.x,blobBase.y); //(ofGetHeight()-y));
- bool hit = plane.intersect(ray,pp);
-
+ switch(mode) {
+ case PLAY:
+ glDisable(GL_DEPTH_TEST);
+ //must be a better way than this
+ colorImg.draw(0,0,ofGetWidth(),ofGetHeight());
+ ofFill();
+ ofSetHexColor(0x000000);
+ ofRect(0,0,ofGetWidth(),ofGetHeight());
+ ofSetHexColor(0xffffff);
+ ofPushMatrix();
+ ofRotate(cam_angle,1,0,0);
+ bindTexture(colorImg);
+ ground.draw();
+ unbindTexture(colorImg);
+ trapDoor.checkUpdate(players);
+ trapDoor.draw();
+ ofPopMatrix();
+ break;
+ case CALIBRATE:
+ ofFill();
+ ofSetHexColor(0x333333);
+ ofSetHexColor(0xa0a0a0);
+ // we could draw the whole contour finder
+ //contourFinder.draw(360,540);
+ //keep running background average- how do you use a custom background
+ ofSetHexColor(0xffffff);
+ colorImg.draw(0,0,ofGetWidth(),ofGetHeight());
- for (int i=0;i<players.size();i++) {
- if (abs(players[i].x-pp.x)<10&&abs(players[i].z-pp.z)) {
- //identified a player
- //this is flawed: tracking boxes in a skewed axis
- //how to get UV coords on the plane
- //maybe rotate the camera instead of the plane
-
+ ofPushMatrix();
+ ofRotate(cam_angle,1,0,0);
+ for (float i=0;i<=ofGetWidth();i+=ofGetWidth()/10) {
+ glBegin(GL_LINES);
+ glVertex3f(i,0,0);
+ glVertex3f(i,ofGetWidth(),0);
+ glEnd();
+ glBegin(GL_LINES);
+ glVertex3f(0,i,0);
+ glVertex3f(ofGetWidth(),i,0);
+ glEnd();
+ }
+ ofPopMatrix();
+
+ vector<ofVec3f> newPlayers;
+ float movethresh=10;
+ for (int i = 0; i < contourFinder.nBlobs; i++){
+ //do some bounds checking, size threshold and overlap removal
+ //in order to translate blobs into players
+ //attempt to track players - maintain ID no
+ //attempt to base blobs
+ //TODO attempt to estimate bounds shape
+ //project all of this into the 3D space
+ ofRectangle r=contourFinder.blobs[i].boundingRect;
+ ofVec2f blobBase=ofVec2f(r.x+(r.width/2),r.y+r.height-(r.width/2));
+ contourFinder.blobs[i].draw(0,0);
+ ofPoint p=contourFinder.blobs[i].centroid;
+ ofSetHexColor(0xffff00);
+ char numStr[16];
+ sprintf(numStr, "%i", i);
+ ofDrawBitmapString(numStr, r.x, r.y);
+ ofVec3f pp;
+ ray=projector.castPixel(blobBase.x,blobBase.y); //(ofGetHeight()-y));
+ bool hit = plane.intersect(ray,pp);
+ for (int i=0;i<players.size();i++) {
+ if (abs(players[i].x-pp.x)<10&&abs(players[i].z-pp.z)) {
+ //identified a player
+ //this is flawed: tracking boxes in a skewed axis
+ //how to get UV coords on the plane
+ //maybe rotate the camera instead of the plane
+
+ }
+ }
+ ofPushMatrix();
+ ofTranslate(pp);
+ ofRotate(cam_angle,1,0,0);
+ ofBox(0,-10,0,20);
+ //for now, draw in this axis
+ ofPopMatrix();
}
- }
-
- ofPushMatrix();
- ofTranslate(pp);
- ofRotate(cam_angle,1,0,0);
- ofBox(0,-10,0,20);
- //for now, draw in this axis
- ofPopMatrix();
+
+ trapDoor.checkUpdate(players);
+ ofPushMatrix();
+ ofRotate(cam_angle,1,0,0);
+ trapDoor.draw();
+ ofPopMatrix();
+
+
+ // finally, a report:
+
+ ofSetHexColor(0xffffff);
+ char reportStr[1024];
+ sprintf(reportStr, "threshold %i\nnum blobs found %i, fps: %f", threshold, contourFinder.nBlobs, ofGetFrameRate());
+ ofDrawBitmapString(reportStr, 10, ofGetHeight()-40);
+ break;
}
-
- trapDoor.checkUpdate(players);
- ofPushMatrix();
- ofRotate(cam_angle,1,0,0);
- //for now, draw in this axis
- trapDoor.draw();
- ofPopMatrix();
-
cam.end();
-
-
-
- // finally, a report:
-
- ofSetHexColor(0xffffff);
- char reportStr[1024];
- sprintf(reportStr, "threshold %i\nnum blobs found %i, fps: %f", threshold, contourFinder.nBlobs, ofGetFrameRate());
- ofDrawBitmapString(reportStr, 10, ofGetHeight()-40);
}
//--------------------------------------------------------------
@@ -216,15 +254,22 @@ void testApp::keyPressed(int key){
break;
case 'a':
cam_angle+=1;
+ updatePlane();
break;
case 'z':
cam_angle-=1;
+ updatePlane();
break;
case 's':
saveSettings("settings.xml");
break;
+ case '1':
+ mode=PLAY;
+ break;
+ case '2':
+ mode=CALIBRATE;
+ break;
}
- plane.setNormal(ofVec3f(0,sin(cam_angle*0.01745329),-cos(cam_angle*0.01745329)));
}
//--------------------------------------------------------------
@@ -249,11 +294,9 @@ void testApp::mousePressed(int x, int y, int button){
//--------------------------------------------------------------
void testApp::mouseReleased(int x, int y, int button){
- ray=projector.castPixel(x,y); //+(ofGetHeight()/2)); //(ofGetHeight()-y));
- bool hit = plane.intersect(ray,pos);
- //pos=ofVec3f(pos.x*2,pos.y*2,pos.z*2);
- 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);
+ 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);
}
diff --git a/gaunt01/src/testApp.h b/gaunt01/src/testApp.h
index b08682c..2870008 100644
--- a/gaunt01/src/testApp.h
+++ b/gaunt01/src/testApp.h
@@ -12,6 +12,10 @@
//#define _USE_LIVE_VIDEO // uncomment this to use a live camera
// otherwise, we'll use a movie file
+#define PLAY 0
+#define CALIBRATE 1
+
+
class testApp : public ofBaseApp{
public:
@@ -29,15 +33,20 @@ class testApp : public ofBaseApp{
void dragEvent(ofDragInfo dragInfo);
void gotMessage(ofMessage msg);
+ int mode;
+
+ ofVec2f screen2plane(ofVec2f screenpos);
+ ofVec3f plane2world(ofVec2f planepos);
+ void updatePlane();
+
ofxXmlSettings XML;
void loadSettings(string filename);
void saveSettings(string filename);
- #ifdef _USE_LIVE_VIDEO
- ofVideoGrabber vidGrabber;
- #else
- ofVideoPlayer vidPlayer;
- #endif
+ bool useCamera;
+ bool hasCamera;
+ ofVideoGrabber vidGrabber;
+ ofVideoPlayer vidPlayer;
ofxCvColorImage colorImg;
@@ -58,10 +67,11 @@ class testApp : public ofBaseApp{
ofPlane plane;
ofProjector projector;
- ofVec3f pos;
+ ofVec2f pos;
vector<ofVec3f> players;
trapdoor trapDoor;
+ ofMesh ground;
};
diff --git a/gaunt01/src/trapdoor.cpp b/gaunt01/src/trapdoor.cpp
index b9ec952..ce06b4a 100644
--- a/gaunt01/src/trapdoor.cpp
+++ b/gaunt01/src/trapdoor.cpp
@@ -1,6 +1,6 @@
#include "trapdoor.h"
-trapdoor::trapdoor(ofRectangle _boundingRect,ofVec2f _doorSize)
+trapdoor::trapdoor(ofVec2f _boundTR,ofVec2f _boundBR,ofVec2f _doorSize)
{
surround=morphmesh("trapdoor-surround.xml");
lid=morphmesh("trapdoor-lid.xml");
@@ -8,8 +8,12 @@ trapdoor::trapdoor(ofRectangle _boundingRect,ofVec2f _doorSize)
texture.loadImage("TextureTrapdoor.jpg");
- boundingRect=_boundingRect;
- doorSize=_doorSize;
+ boundTR=_boundTR;
+ boundBR=_boundBR;
+
+ printf("trapdoor bounds: %f,%f - %f,%f\n",boundTR.x,boundTR.y,boundBR.x,boundBR.y);
+
+ size=_doorSize;
start();
}
@@ -17,40 +21,67 @@ trapdoor::trapdoor(ofRectangle _boundingRect,ofVec2f _doorSize)
trapdoor::~trapdoor() {}
void trapdoor::start(){
- position=ofVec2f(boundingRect.x+ofRandom(boundingRect.width),boundingRect.y+ofRandom(boundingRect.height));
+ //place trapdoor within bounds
+ float u=ofRandom(-0.9,0.9); //(-1 to 1)
+ float v=ofRandom(0.05,0.95);
+ float mx=ofGetWidth()/2;
+
+ float x=mx+((boundTR.x-mx)*u*(1-v))+((boundBR.x-mx)*u*v);
+ float y=boundTR.y+((boundBR.y-boundTR.y)*v);
+ printf("new trapdoor: %f,%f\n",x,y);
+
+ position=ofVec2f(x,y);
startTime=ofGetElapsedTimef();
doorAngle=0;
doorSpeed=0;
}
+
+vector<ofVec2f> trapdoor::getCorners(){
+ vector<ofVec2f> corners;
+ corners.push_back(ofVec2f(-size.x/2,-size.y/2));
+ corners.push_back(ofVec2f(size.x/2,-size.y/2));
+ corners.push_back(ofVec2f(size.x/2,size.y/2));
+ corners.push_back(ofVec2f(-size.x/2,size.y/2));
+ return corners;
+}
+
+ofVec2f trapdoor::bounds2UV(ofVec2f point){
+ //returns the 0-1 UV coords of a point on the ground plane relative to its bounds.
+ float v=(point.y-boundTR.y)/(boundBR.y-boundTR.y);
+ float mx=ofGetWidth()/2;
+ float u=((point.x-mx)/(((boundTR.x-mx)*(1-v))+((boundBR.x-mx)*v)))+0.5;
+ return ofVec2f(u,v);
+}
void trapdoor::checkUpdate(const vector<ofVec3f>& players) {
float segTime=(ofGetElapsedTimef()-startTime);
if (segTime>5) start();
if (segTime>3) {
- doorSpeed=(doorSpeed+((cos(doorAngle*0.0174532925)/ofGetFrameRate())*100))*0.95;
- doorAngle+=doorSpeed;
+ doorSpeed=(doorSpeed+((cos(doorAngle*0.0174532925)/ofGetFrameRate())*50))*0.95;
+ doorAngle-=doorSpeed;
}
}
void trapdoor::draw() {
glEnable(GL_DEPTH_TEST);
+ ofSetHexColor(0xffffff);
bindTexture(texture);
ofPushMatrix();
ofRotate(90,-1,0,0);
- ofTranslate(position.x,0,position.y);
- ofRotate(180,-1,0,0);
+ ofTranslate(ofVec3f(position.x,0,position.y));
+ //ofRotate(180,-1,0,0);
//for now size =40x40
ofScale(.1,.1,.1);
surround.draw();
ofPushMatrix();
ofTranslate(90,0,0);
- ofRotate(doorAngle,0,0,1);
+ ofRotate(doorAngle,0,0,-1);
lid.draw();
ofPopMatrix();
ofPushMatrix();
ofTranslate(-90,0,0);
ofRotate(180,0,1,0);
- ofRotate(doorAngle,0,0,1);
+ ofRotate(doorAngle,0,0,-1);
lid.draw();
ofPopMatrix();
ofPopMatrix();
diff --git a/gaunt01/src/trapdoor.h b/gaunt01/src/trapdoor.h
index 43121e3..b1318b3 100644
--- a/gaunt01/src/trapdoor.h
+++ b/gaunt01/src/trapdoor.h
@@ -17,12 +17,15 @@ creaking sound player
class trapdoor
{
public:
- trapdoor(ofRectangle boundingRect=ofRectangle(0,0,100,100),ofVec2f _doorSize=ofVec2f(10,10));
+ trapdoor(ofVec2f _boundTR=ofVec2f(0,0),ofVec2f _boundBR=ofVec2f(0,0),ofVec2f _doorSize=ofVec2f(10,10));
virtual ~trapdoor();
void checkUpdate(const vector<ofVec3f>& players);
void draw();
void start();
+
+ vector<ofVec2f> getCorners();
+ ofVec2f bounds2UV(ofVec2f pt);
protected:
private:
@@ -30,6 +33,9 @@ class trapdoor
morphmesh lid;
ofVec2f position;
+ ofVec2f boundTR;
+ ofVec2f boundBR;
+ ofVec2f size;
float startTime;
float triggerTime; //time threshold