summaryrefslogtreecommitdiff
path: root/gaunt01
diff options
context:
space:
mode:
authorTim Redfern <tim@eclectronics.org>2012-06-22 13:06:42 +0100
committerTim Redfern <tim@eclectronics.org>2012-06-22 13:06:42 +0100
commit5606e9f56d1333c32fd711a74f372669948bae8d (patch)
tree287f5c28e9492663972cb1b5cdf04c6eb453fb4c /gaunt01
parent11a2a8968984d35e59809d5c4ef602db9fac52dc (diff)
new media files
Diffstat (limited to 'gaunt01')
-rw-r--r--gaunt01/bin/data/whistle1.wavbin0 -> 206212 bytes
-rw-r--r--gaunt01/bin/data/whistle2.wavbin0 -> 300690 bytes
-rw-r--r--gaunt01/src/bird.cpp33
-rw-r--r--gaunt01/src/bird.h4
-rw-r--r--gaunt01/src/testApp.cpp120
5 files changed, 86 insertions, 71 deletions
diff --git a/gaunt01/bin/data/whistle1.wav b/gaunt01/bin/data/whistle1.wav
new file mode 100644
index 0000000..0283359
--- /dev/null
+++ b/gaunt01/bin/data/whistle1.wav
Binary files differ
diff --git a/gaunt01/bin/data/whistle2.wav b/gaunt01/bin/data/whistle2.wav
new file mode 100644
index 0000000..0271571
--- /dev/null
+++ b/gaunt01/bin/data/whistle2.wav
Binary files differ
diff --git a/gaunt01/src/bird.cpp b/gaunt01/src/bird.cpp
index 6e7ff92..fadfcab 100644
--- a/gaunt01/src/bird.cpp
+++ b/gaunt01/src/bird.cpp
@@ -17,19 +17,25 @@ 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();
+ model.sequences["swoop"].start();
//how to track state/ bring animation in and out
- state=SCANNING;
+ state=SWOOPING;
- sounds=new ofSoundPlayer[7];
- sounds[0].loadSound("aggressive1.wav");
- sounds[1].loadSound("aggressive2.wav");
- sounds[2].loadSound("chirp1.wav");
- sounds[3].loadSound("chirp2.wav");
- sounds[4].loadSound("rattle1.wav");
- sounds[5].loadSound("rattle2.wav");
- sounds[6].loadSound("rattle3.wav");
+ aggressives=new ofSoundPlayer[2];
+ aggressives[0].loadSound("aggressive1.wav");
+ aggressives[1].loadSound("aggressive2.wav");
+ chirps=new ofSoundPlayer[2];
+ chirps[0].loadSound("chirp1.wav");
+ chirps[1].loadSound("chirp2.wav");
+ rattles=new ofSoundPlayer[3];
+ rattles[0].loadSound("rattle1.wav");
+ rattles[1].loadSound("rattle2.wav");
+ rattles[2].loadSound("rattle3.wav");
+
+ //emit a rattle when the bird becomes vsisible and when it switches back to scanning
+ //emit a chirp when it switches to swooping
+ //emit an aggressive noise when it attacks
texture.loadImage("TextureBird.jpg");
@@ -221,6 +227,8 @@ void bird::update(map<int,player>& players, float angle){
model.sequences["flap"].fadeout(0.5);
model.sequences["swoop"].start();
state=SWOOPING;
+ int whichsound=(int)ofRandom(1.9999999);
+ chirps[whichsound].play();
}
break;
case SWOOPING:
@@ -228,6 +236,8 @@ void bird::update(map<int,player>& players, float angle){
model.sequences["swoop"].fadeout(0.5);
model.sequences["flap"].start();
state=SCANNING;
+ int whichsound=(int)ofRandom(2.9999999);
+ rattles[whichsound].play();
}
break;
case ATTACKING:
@@ -252,6 +262,9 @@ void bird::update(map<int,player>& players, float angle){
//flap faster while climbing + swoop
//bird noises
+ //where does it start
+ //whistles rather than chirps
+
heading=heading+(turnRate*timeSeg);
while (heading>180) heading=heading-360;
while (heading <-180) heading=heading+360;
diff --git a/gaunt01/src/bird.h b/gaunt01/src/bird.h
index 967e7bd..fdaf915 100644
--- a/gaunt01/src/bird.h
+++ b/gaunt01/src/bird.h
@@ -108,7 +108,9 @@ class bird
float lastTime;
- ofSoundPlayer* sounds;
+ ofSoundPlayer* aggressives;
+ ofSoundPlayer* chirps;
+ ofSoundPlayer* rattles;
ofImage texture;
diff --git a/gaunt01/src/testApp.cpp b/gaunt01/src/testApp.cpp
index 2664979..6af06ad 100644
--- a/gaunt01/src/testApp.cpp
+++ b/gaunt01/src/testApp.cpp
@@ -23,7 +23,7 @@ void testApp::setup(){
this->windowWidth = ofGetWidth();
this->windowHeight = ofGetHeight();
}
-
+
mirror=true;
bLearnBakground = true;
@@ -52,12 +52,12 @@ void testApp::setup(){
bgImg.allocate(640,480);
bgImg.setUseTexture(true);
-
+
grayImage.allocate(640,480);
grayBg.allocate(640,480);
*/
-
+
colorImg.allocate(640,480);
colorImg.setUseTexture(true);
currentFrame.allocate(CAM_WIDTH_FG, CAM_HEIGHT_FG);
@@ -67,16 +67,16 @@ void testApp::setup(){
grayFrame.allocate(CAM_WIDTH_FG, CAM_HEIGHT_FG);
grayBg.allocate(CAM_WIDTH_FG, CAM_HEIGHT_FG);
grayDiff.allocate(CAM_WIDTH_FG, CAM_HEIGHT_FG);
-
+
mogoutput.allocate(CAM_WIDTH_FG, CAM_HEIGHT_FG);
learningRate = 0.01f;
bFirstFrame=true;
-
+
diffchannel=chan_V;
hsvback = cvCreateImage(cvGetSize(currentFrame.getCvImage()), currentFrame.getCvImage()->depth, currentFrame.getCvImage()->nChannels);
//backchan = cvCreateImage(cvGetSize(currentFrame.getCvImage()), 8, 1);
-
+
removeShadows=false;
shadowThreshold=10;
////////////////////////////
@@ -140,7 +140,7 @@ void testApp::setup(){
}
scaleFactor=ofVec2f(windowWidth/1280.0f,windowHeight/768.0f);
- gameState=PLAYING; //TITLES; //
+ gameState=TITLES; //PLAYING; //TITLES; //
segTimes[TITLES]=4.0;
segTimes[CREDIT]=2.5;
@@ -317,13 +317,13 @@ void testApp::updatePlane(){
else printf("bound plane 4 not found\n");
pn=(p-projector.getGlobalPosition()).getPerpendicular(ofVec3f(-1,0,0));
bounds[3]=ofPlane(p,pn); //,-pn,ofVec2f(1000,1000));
-
+
l=ofVec2f(windowWidth/2,windowHeight/2);
r=projector.castPixel(l.x,l.y);
if (plane.intersect(r,centre)) printf("found centre point at %f,%f,%f\n",centre.x,centre.y,centre.z);
else printf("centre point not found\n");
ofVec3f c=centre.rotated(cam_angle,ofVec3f(-1,0,0));
-
+
Bird.setBounds(bounds);
Bird.setCentre(ofVec2f(c.x,c.y));
@@ -462,11 +462,11 @@ void testApp::update(){
colorImg.setFromPixels(vidPlayer.getPixels(), 640,480);
//accumImg.setFromPixels(vidPlayer.getPixels(), 640,480);
}
-
+
if (mirror) colorImg.mirror(false,true);
colorImg.updateTexture();
-
+
/*
grayImage = colorImg;
@@ -499,42 +499,42 @@ void testApp::update(){
//hard coded size threshold of 100 pix
contourFinder.findContours(grayDiff, 200, (640*480)/3, 20, false); // don't find holes
-
+
*/
-
+
cv::Mat img = colorImg.getCvImage();
-
+
//if (frameno%1==0) { //I THINK THIS APPROACH IS OK to attempt to lower cpu hit from accumulating?
-
+
//cv::Rect roi(0, 0, 32, 32); //doesn't seem that easy to apply the ROI weighted and you still have to convert a whole image each frame?
-
+
//cv::Mat imgroi = img(roi);
-
+
if (bFirstFrame) {
img.convertTo(accumulator, CV_32FC3);
bFirstFrame=false;
}
-
+
cv::Mat im3;
img.convertTo(im3, CV_32FC3);
-
+
//accumulator;
accumulateWeighted(im3, accumulator, max(1.0f/(ofGetElapsedTimef()*30.0f),learningRate));
accumulator.convertTo(outmat,CV_8UC3);
-
+
IplImage* tmp = new IplImage(outmat);
background=tmp;
background.updateTexture();
-
+
//printf("tmp: %ix%i channels: %i depth:%i\n",tmp->width,tmp->height,tmp->nChannels,tmp->depth);
-
-
+
+
//get correct channel into backchan
-
+
vector<cv::Mat> chans;
-
+
//to remove shadows, need hsv of foreground and background
if (diffchannel>chan_B||removeShadows) cvtColor(outmat, hsvback, CV_BGR2HSV);
switch (diffchannel) {
@@ -563,64 +563,64 @@ void testApp::update(){
chans[2].copyTo(backchan);
break;
}
-
+
tmp = new IplImage(backchan);
grayBg = tmp;
-
+
//}
//first, optionally remove shadows from FG
//possibly use 1/4 screen res?
-
+
//to remove shadows, need hsv of foreground and background
if (diffchannel>chan_B||removeShadows) cvtColor(img, hsvfront, CV_BGR2HSV);
-
+
cv::Mat outimg;
-
+
if (removeShadows) {
vector<cv::Mat> slicesFront, slicesBack;
cv::Mat valFront, valBack, satFront, satBack;
-
+
// split image to H,S and V images
split(hsvfront, slicesFront);
split(hsvback, slicesBack);
-
+
slicesFront[2].copyTo(valFront); // get the value channel
slicesFront[1].copyTo(satFront); // get the sat channel
-
+
slicesBack[2].copyTo(valBack); // get the value channel
slicesBack[1].copyTo(satBack); // get the sat channel
-
+
int x,y;
for(x=0; x<currentFrame.getWidth(); ++x) {
for(y=0; y<currentFrame.getHeight(); ++y) {
bool sat = ((satFront.at<cv::Vec3b>(y,x)[0] > satBack.at<cv::Vec3b>(y,x)[0]-shadowThreshold) &&
(satFront.at<cv::Vec3b>(y,x)[0] < satBack.at<cv::Vec3b>(y,x)[0]+shadowThreshold));
-
+
if(sat && (valFront.at<cv::Vec3b>(y,x)[0] < valBack.at<cv::Vec3b>(y,x)[0])) {
- hsvfront.at<cv::Vec3b>(y,x)[0]= hsvback.at<cv::Vec3b>(y,x)[0];
- hsvfront.at<cv::Vec3b>(y,x)[1]= hsvback.at<cv::Vec3b>(y,x)[1];
+ hsvfront.at<cv::Vec3b>(y,x)[0]= hsvback.at<cv::Vec3b>(y,x)[0];
+ hsvfront.at<cv::Vec3b>(y,x)[1]= hsvback.at<cv::Vec3b>(y,x)[1];
hsvfront.at<cv::Vec3b>(y,x)[2]= hsvback.at<cv::Vec3b>(y,x)[2];
}
-
+
}
}
//convert back into RGB if necessary
-
+
if (diffchannel<chan_H) cvtColor(hsvfront, outimg, CV_HSV2BGR);
else outimg=hsvfront;
-
+
}else {
outimg=img;
- }
-
+ }
+
//select correct channel for comparison and put into grayFrame
-
+
//vector<cv::Mat> chans;
split(outimg,chans);
-
+
switch (diffchannel) {
case chan_R:
chans[0].copyTo(frontchan);
@@ -641,14 +641,14 @@ void testApp::update(){
chans[2].copyTo(frontchan);
break;
}
-
+
//IplImage* tmp = new IplImage(outmat);
tmp = new IplImage(frontchan);
grayFrame = tmp;
-
+
grayDiff.clear();
grayDiff.allocate(640,480);
-
+
// take the abs value of the difference between background and incoming and then threshold:
grayDiff.absDiff(grayBg, grayFrame);
grayDiff.threshold(threshold);
@@ -659,14 +659,14 @@ void testApp::update(){
/*
//MOG
mog(img, outmat, mogf);
-
+
// Complement the image
//cv::threshold(outmat, output, threshold, 255, cv::THRESH_BINARY_INV);
IplImage* tmp1 = new IplImage(outmat);
//printf("tmp: %ix%i channels: %i depth:%i\n",tmp->width,tmp->height,tmp->nChannels,tmp->depth);
//printf("grayDiff: %ix%i channels: %i depth:%i\n",grayDiff.getCvImage()->width,grayDiff.getCvImage()->height,grayDiff.getCvImage()->nChannels,grayDiff.getCvImage()->depth);
grayDiff=tmp1; //copy to ofx
-*/
+*/
grayDiff.resize(windowWidth,windowHeight); //wasteful??
@@ -712,7 +712,7 @@ void testApp::update(){
}
}
- Bird.update(players,cam_angle);
+ if (gameState==PLAYING) Bird.update(players,cam_angle);
}
@@ -775,7 +775,7 @@ void testApp::draw(){
glDisable(GL_BLEND);
ofPopMatrix();
-
+
glDisable(GL_DEPTH_TEST);
ofSetHexColor(0xffffff);
bindTexture(colorImg); //colorImg.getTextureReference().bind();
@@ -895,7 +895,7 @@ void testApp::draw(){
//trapDoor.drawDebug();
ofPopMatrix();
- Bird.drawDebug();
+ if (gameState==PLAYING) Bird.drawDebug();
ofSetHexColor(0x77ff77);
@@ -923,7 +923,7 @@ void testApp::draw(){
else ofSetHexColor(0x555555);
ofPushMatrix();
ofRotate(cam_angle,1,0,0);
-
+
ofLine(Bird.position,Bird.playpos[i]);
ofPopMatrix();
@@ -942,7 +942,7 @@ void testApp::draw(){
char numStr[16];
sprintf(numStr, "%i", blobsManager.blobs[i].id);
ofDrawBitmapString(numStr, blob.boundingRect.x, blob.boundingRect.y);
-
+
/*
ofPushMatrix();
ofRotate(cam_angle,1,0,0);
@@ -1034,7 +1034,7 @@ void testApp::keyPressed(int key){
case '0':
mode=CALIBRATE;
break;
-
+
case '1':
diffchannel = chan_R;
break;
@@ -1053,14 +1053,14 @@ void testApp::keyPressed(int key){
case '6':
diffchannel = chan_V;
break;
-
+
/*
case 's':
removeShadows=!removeShadows;
printf(removeShadows?"removing shadows\n":"not removing shadows\n");
break;
-
-
+
+
case '1':
if (Bird.currentseq!="hover") {
//mesh.sequences["trans_flaphover"].stopAt(0.3);
@@ -1139,7 +1139,7 @@ void testApp::keyPressed(int key){
gameState=(gameState+1)%4;
gameStart=ofGetElapsedTimef();
break;
-
+
*/
}
}
@@ -1179,7 +1179,7 @@ void testApp::windowResized(int w, int h){
}
-//-------------------------------------------0-------------------
+//--------------------------------------------------------------
void testApp::gotMessage(ofMessage msg){
}