summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Redfern <tim@eclectronics.org>2012-04-12 21:50:39 +0100
committerTim Redfern <tim@eclectronics.org>2012-04-12 21:50:39 +0100
commitd45a554faaf557b9e9a4b7a43b73b89f03800a96 (patch)
tree6825b969ccada08fa638d5f47ac15b5515e1f8ac
parent6ddd691156f1a3a24be9045056db39e78041b8d8 (diff)
bird shadow
-rw-r--r--gaunt01/bin/data/settings.xml2
-rw-r--r--gaunt01/gaunt01_win.cbp6
-rw-r--r--gaunt01/src/bird.cpp35
-rw-r--r--gaunt01/src/bird.h16
-rw-r--r--gaunt01/src/testApp.cpp117
-rw-r--r--gaunt01/src/testApp.h5
-rw-r--r--gaunt01/src/trapdoor.cpp12
-rw-r--r--gaunt01/src/trapdoor.h6
-rw-r--r--morpher/morpher.layout12
9 files changed, 166 insertions, 45 deletions
diff --git a/gaunt01/bin/data/settings.xml b/gaunt01/bin/data/settings.xml
index 5b23dd9..ff6dfa0 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="-55" threshold="20" />
+<gauntlet cam_angle="-55" threshold="30" />
diff --git a/gaunt01/gaunt01_win.cbp b/gaunt01/gaunt01_win.cbp
index 4b7a79f..e6246b6 100644
--- a/gaunt01/gaunt01_win.cbp
+++ b/gaunt01/gaunt01_win.cbp
@@ -157,6 +157,12 @@
<Add after='cmd /c if not exist &quot;$(PROJECT_DIR)bin/data&quot; mkdir &quot;$(PROJECT_DIR)bin/data&quot;' />
<Mode after="always" />
</ExtraCommands>
+ <Unit filename="src\bird.cpp">
+ <Option virtualFolder="src\" />
+ </Unit>
+ <Unit filename="src\bird.h">
+ <Option virtualFolder="src\" />
+ </Unit>
<Unit filename="src\main.cpp">
<Option virtualFolder="src" />
</Unit>
diff --git a/gaunt01/src/bird.cpp b/gaunt01/src/bird.cpp
index 0a17563..e27a2a2 100644
--- a/gaunt01/src/bird.cpp
+++ b/gaunt01/src/bird.cpp
@@ -16,20 +16,20 @@ bird::bird()
if (model.loadSeqs("Bird-anim.xml")) printf("animation loaded with %i sequences\n",model.getNumSequences());
else printf("animation XML file not parsed\n");
-
+
model.sequences["flap"].start();
currentseq="hover";
-
+
texture.loadImage("TextureBird.jpg");
//starting pos
- position=ofVec3f(ofGetWidth()/2,ofGetHeight(),-100); //ofGetHeight()/4);
- heading=ofVec3f(-1,0,0);
- direction=ofVec3f(-1,0,0);
+ position=ofVec3f(ofGetWidth()/2,ofGetHeight(),-ofGetHeight()/4);
+ heading=-90;
+ direction=ofVec3f(0,-1,0); //director for a heading of 0, level
velocity=ofGetWidth()/50;
- turnAngle=-1;
- diveAngle=0;
+ turnRate=20;
+ diveRate=0;
lastTime=ofGetElapsedTimef();
}
@@ -43,20 +43,35 @@ void bird::update(const vector<ofVec3f>& players){
float time=ofGetElapsedTimef();
float timeSeg=time-lastTime;
lastTime=time;
- position+=direction*velocity*timeSeg;
+ heading+=turnRate*timeSeg;
+
+ position-=direction.rotated(heading,ofVec3f(0,0,-1))*velocity*timeSeg; //.rotate(heading,ofVec3f(0,1,0))
}
void bird::draw(){
glEnable(GL_DEPTH_TEST);
ofPushMatrix();
ofTranslate(position);
- //ofRotate(direction);
ofRotate(90,0,0,1);
ofRotate(90,-1,0,0);
+ ofRotate(heading+90,0,1,0);
+ ofSetHexColor(0xffffff);
ofScale(.15,.15,.15);
bindTexture(texture);
- model.drawAnimated();
+ model.drawAnimated();
unbindTexture(texture);
ofPopMatrix();
glDisable(GL_DEPTH_TEST);
}
+void bird::drawShadow(){
+ ofPushMatrix();
+ ofTranslate(position);
+ ofRotate(90,0,0,1);
+ ofRotate(90,-1,0,0);
+ ofRotate(heading+90,0,1,0);
+ ofSetHexColor(0x000000);
+ ofTranslate(0,(-ofGetHeight()/4)+5,0);
+ ofScale(.15,0,.15);
+ model.drawAnimated();
+ ofPopMatrix();
+}
diff --git a/gaunt01/src/bird.h b/gaunt01/src/bird.h
index e4b7f65..140a102 100644
--- a/gaunt01/src/bird.h
+++ b/gaunt01/src/bird.h
@@ -37,23 +37,27 @@ class bird
virtual ~bird();
void update(const vector<ofVec3f>& players);
void draw();
+ void drawShadow();
+
+ string currentseq;
+ morphmesh model;
protected:
private:
ofVec3f position;
- ofVec3f heading;
+ float heading;
ofVec3f direction;
float velocity; //per second
- float turnAngle; //per second
- float diveAngle; //per second
+ float turnRate; //per second
+ float diveRate; //per second
float lastTime;
- morphmesh model;
+
ofImage texture;
-
- string currentseq;
+
+
};
#endif // BIRD_H
diff --git a/gaunt01/src/testApp.cpp b/gaunt01/src/testApp.cpp
index 172190f..6660103 100644
--- a/gaunt01/src/testApp.cpp
+++ b/gaunt01/src/testApp.cpp
@@ -3,6 +3,16 @@
//--------------------------------------------------------------
//units ~ 10cm
//
+/*
+Can use a floating point image or array to accumulate the screen and generate averaged background?
+
+Is this too much work for every frame? Should it be put in a seperate thread?
+
+
+
+
+
+*/
void testApp::setup(){
bLearnBakground = true;
@@ -24,12 +34,23 @@ void testApp::setup(){
useCamera=false;
vidPlayer.play();
}
-
+
+/*
colorImg.allocate(640,480);
colorImg.setUseTexture(true);
grayImage.allocate(640,480);
grayBg.allocate(640,480);
- grayDiff.allocate(640,480);
+ grayDiff.allocate(640,480);
+ */
+ colorImg.allocate(640,480);
+ colorImg.setUseTexture(true);
+
+ grayImage.allocate(ofGetWidth(),ofGetHeight());
+ grayBg.allocate(ofGetWidth(),ofGetHeight());
+ grayDiff.allocate(ofGetWidth(),ofGetHeight());
+
+
+
blobsManager.normalizePercentage = 0.7;
blobsManager.giveLowestPossibleIDs = false;
@@ -60,6 +81,7 @@ void testApp::setup(){
mode=PLAY;
+ drawStats=false;
}
@@ -167,7 +189,9 @@ void testApp::update(){
colorImg.setFromPixels(vidPlayer.getPixels(), 640,480);
}
+
grayImage = colorImg;
+ grayImage.resize(ofGetWidth(),ofGetHeight());
if (bLearnBakground == true){
grayBg = grayImage; // the = sign copys the pixels from grayImage into grayBg (operator overloading)
bLearnBakground = false;
@@ -176,6 +200,8 @@ void testApp::update(){
// take the abs value of the difference between background and incoming and then threshold:
grayDiff.absDiff(grayBg, grayImage);
grayDiff.threshold(threshold);
+ //grayDiff.adaptiveThreshold( threshold); //int blockSize, int offset=0,bool invert=false, bool gauss=false);
+ grayDiff.erode_3x3();
// find contours which are between the size of 20 pixels and 1/3 the w*h pixels.
// also, find holes is set to true so we will get interior contours as well....
@@ -219,6 +245,13 @@ void testApp::draw(){
ground.draw();
unbindTexture(colorImg);
+ Bird.update(players);
+
+ ofPushMatrix();
+ ofRotate(cam_angle,1,0,0);
+ Bird.drawShadow();
+ ofPopMatrix();
+
/*
glEnable(GL_BLEND);
glBlendFunc(GL_CONSTANT_ALPHA,GL_ONE);
@@ -228,7 +261,7 @@ void testApp::draw(){
*/
for (int i = 0; i < contourFinder.nBlobs; i++){
ofxCvBlob blob=contourFinder.blobs[i];
- if (rectsCross(blob.boundingRect,trapDoor.getBoundingRect())){
+ //if (rectsCross(blob.boundingRect,trapDoor.getBoundingRect())){ //ALWAYS draw players?
//create outline mesh
playeroutline=ofPolyline(blob.pts);
tesselator.tessellateToMesh(playeroutline,OF_POLY_WINDING_NONZERO,player,true);
@@ -241,15 +274,20 @@ void testApp::draw(){
//get screen basepoint
ofRectangle r=blob.boundingRect;
ofVec2f blobBase=ofVec2f(r.x+(r.width/2),r.y+r.height-(r.width/2));
- if (trapDoor.getInnerRect().inside(blobBase.x,blobBase.y)) trapDoor.trigger();
-
- colorImg.getTextureReference().bind();
- player.draw(); //trapdoor.getoffset());
- colorImg.getTextureReference().unbind();
+ if (trapDoor.getInnerRect().inside(blobBase.x,blobBase.y)) {
+ trapDoor.trigger();
+
+ ofPushMatrix();
+ ofTranslate(0,0,trapDoor.getFalldist()*ofGetScreenHeight());
+ colorImg.getTextureReference().bind();
+ player.draw(); //trapdoor.getoffset());
+ colorImg.getTextureReference().unbind();
+ ofPopMatrix();
+ }
}
- }
+ //}
+
- Bird.update(players);
ofPushMatrix();
ofRotate(cam_angle,1,0,0);
@@ -332,14 +370,16 @@ void testApp::draw(){
}
- // 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;
}
+ if (drawStats||mode==CALIBRATE) {
+ ofSetHexColor(0xffffff);
+ char reportStr[1024];
+ sprintf(reportStr, "threshold %i\nnum blobs found %i, fps: %f", threshold, contourFinder.nBlobs, ofGetFrameRate());
+ ofDrawBitmapString(reportStr, 10, ofGetHeight()-40);
+ }
cam.end();
}
@@ -366,15 +406,58 @@ void testApp::keyPressed(int key){
cam_angle-=1;
updatePlane();
break;
+ case 'q':
+ drawStats=!drawStats;
+ break;
case 's':
saveSettings("settings.xml");
break;
- case '1':
+ case '9':
mode=PLAY;
break;
- case '2':
+ case '0':
mode=CALIBRATE;
break;
+ case '1':
+ if (Bird.currentseq!="hover") {
+ //mesh.sequences["trans_flaphover"].stopAt(0.3);
+ //mesh.sequences["trans_flaphover"].start();
+ Bird.model.sequences[Bird.currentseq].fadeout(0.5);
+ Bird.model.sequences["hover"].fadein(0.5);
+ Bird.currentseq="hover";
+ }
+ break;
+ case '2':
+ if (Bird.currentseq!="flap") {
+ //mesh.sequences["trans_hoverflap"].stopAt(0.3);
+ //mesh.sequences["trans_hoverflap"].start();
+ Bird.model.sequences[Bird.currentseq].fadeout(0.5);
+ Bird.model.sequences["flap"].fadein(0.5);
+ Bird.currentseq="flap";
+ }
+ break;
+ case '3':
+ if (Bird.currentseq!="swoop") {
+ //mesh.sequences["trans_hoverflap"].stopAt(0.3);
+ //mesh.sequences["trans_hoverflap"].start();
+ Bird.model.sequences[Bird.currentseq].fadeout(0.25);
+ Bird.model.sequences["swoop_trans"].fadein(0.25);
+ Bird.model.sequences["swoop_trans"].stopTime=ofGetElapsedTimef()+1.0;
+ Bird.model.sequences["swoop"].startAt(1.0);
+ Bird.currentseq="swoop";
+ }
+ break;
+ case '4':
+ if (Bird.currentseq!="attack") {
+ //mesh.sequences["trans_hoverflap"].stopAt(0.3);
+ //mesh.sequences["trans_hoverflap"].start();
+ Bird.model.sequences[Bird.currentseq].fadeout(0.2);
+ Bird.model.sequences["attack_trans"].fadein(0.2);
+ Bird.model.sequences["attack_trans"].stopTime=ofGetElapsedTimef()+0.6;
+ Bird.model.sequences["attack"].startAt(0.6);
+ Bird.currentseq="attack";
+ }
+ break;
}
}
diff --git a/gaunt01/src/testApp.h b/gaunt01/src/testApp.h
index 9ee79db..50187bd 100644
--- a/gaunt01/src/testApp.h
+++ b/gaunt01/src/testApp.h
@@ -52,7 +52,8 @@ class testApp : public ofBaseApp{
ofVideoGrabber vidGrabber;
ofVideoPlayer vidPlayer;
- ofxCvColorImage colorImg;
+ ofxCvColorImage colorImg;
+ ofxCvFloatImage accumImg;
ofxCvGrayscaleImage grayImage;
ofxCvGrayscaleImage grayBg;
@@ -87,5 +88,7 @@ class testApp : public ofBaseApp{
bird Bird;
+ bool drawStats;
+
};
diff --git a/gaunt01/src/trapdoor.cpp b/gaunt01/src/trapdoor.cpp
index e1c37ec..3da9755 100644
--- a/gaunt01/src/trapdoor.cpp
+++ b/gaunt01/src/trapdoor.cpp
@@ -17,9 +17,7 @@ trapdoor::trapdoor(ofVec2f _boundTR,ofVec2f _boundBR,ofVec2f _doorSize)
boundTR=_boundTR;
boundBR=_boundBR;
- size=_doorSize;
-
- start();
+ size=_doorSize; start();
}
trapdoor::~trapdoor() {
@@ -35,6 +33,7 @@ void trapdoor::start(){
float y=boundTR.y+((boundBR.y-boundTR.y)*v);
startPos(ofVec2f(x,y));
+
}
void trapdoor::startPos(ofVec2f pos){
@@ -43,6 +42,7 @@ void trapdoor::startPos(ofVec2f pos){
doorAngle=0;
doorSpeed=0;
opening=false;
+ triggeredTime=-1;
//for (int i=0;i<4;i++) sounds[i].stop();
}
@@ -66,6 +66,7 @@ ofRectangle trapdoor::getInnerRect() {
return ofRectangle(boundingRect.x+(boundingRect.width/4),boundingRect.y+(boundingRect.height/4),boundingRect.width/2,boundingRect.height/2);
}
void trapdoor::trigger() {
+ triggeredTime=ofGetElapsedTimef();
startTime=ofGetElapsedTimef()-10;
}
@@ -77,6 +78,11 @@ ofVec2f trapdoor::bounds2UV(ofVec2f point){
return ofVec2f(u,v);
}
+float trapdoor::getFalldist(){
+ if (triggerTime>0) return (ofGetElapsedTimef()-triggeredTime);
+ else return 0;
+}
+
bool trapdoor::checkUpdate(const vector<ofVec3f>& players) {
float segTime=(ofGetElapsedTimef()-startTime);
if (segTime>10) {
diff --git a/gaunt01/src/trapdoor.h b/gaunt01/src/trapdoor.h
index 389e4ad..8cff4f4 100644
--- a/gaunt01/src/trapdoor.h
+++ b/gaunt01/src/trapdoor.h
@@ -27,13 +27,15 @@ class trapdoor
vector<ofVec2f> getCorners();
ofVec2f bounds2UV(ofVec2f pt);
-
+
void setBoundingRect(float x,float y, float width,float height);
ofRectangle getBoundingRect();
ofRectangle getInnerRect();
void trigger();
float getoffset();
+ float getFalldist();
+
protected:
private:
morphmesh surround;
@@ -59,6 +61,8 @@ class trapdoor
bool opening;
+ float triggeredTime;
+
};
#endif // TRAPDOOR_H
diff --git a/morpher/morpher.layout b/morpher/morpher.layout
index e0122f5..19ecc35 100644
--- a/morpher/morpher.layout
+++ b/morpher/morpher.layout
@@ -7,22 +7,22 @@
<File name="config.make" open="0" top="0" tabpos="9">
<Cursor position="478" topLine="0" />
</File>
- <File name="src/morphmesh.cpp" open="1" top="0" tabpos="10">
+ <File name="src/morphmesh.cpp" open="1" top="1" tabpos="6">
<Cursor position="3075" topLine="87" />
</File>
- <File name="src/morphmesh.h" open="1" top="0" tabpos="9">
+ <File name="src/morphmesh.h" open="1" top="0" tabpos="5">
<Cursor position="2727" topLine="67" />
</File>
- <File name="src/normBindTexture.cpp" open="1" top="0" tabpos="6">
+ <File name="src/normBindTexture.cpp" open="1" top="0" tabpos="2">
<Cursor position="0" topLine="3" />
</File>
- <File name="src/normBindTexture.h" open="1" top="0" tabpos="5">
+ <File name="src/normBindTexture.h" open="1" top="0" tabpos="1">
<Cursor position="0" topLine="0" />
</File>
- <File name="src/testApp.cpp" open="1" top="0" tabpos="8">
+ <File name="src/testApp.cpp" open="1" top="0" tabpos="4">
<Cursor position="524" topLine="0" />
</File>
- <File name="src/testApp.h" open="1" top="0" tabpos="7">
+ <File name="src/testApp.h" open="1" top="0" tabpos="3">
<Cursor position="597" topLine="0" />
</File>
</CodeBlocks_layout_file>