summaryrefslogtreecommitdiff
path: root/gaunt01/src
diff options
context:
space:
mode:
Diffstat (limited to 'gaunt01/src')
-rw-r--r--gaunt01/src/bird.cpp34
-rw-r--r--gaunt01/src/bird.h10
-rw-r--r--gaunt01/src/main.cpp2
-rw-r--r--gaunt01/src/morphmesh.cpp15
-rw-r--r--gaunt01/src/morphmesh.h8
-rw-r--r--gaunt01/src/testApp.cpp10
-rw-r--r--gaunt01/src/testApp.h3
7 files changed, 71 insertions, 11 deletions
diff --git a/gaunt01/src/bird.cpp b/gaunt01/src/bird.cpp
index 9af751e..7d9fb02 100644
--- a/gaunt01/src/bird.cpp
+++ b/gaunt01/src/bird.cpp
@@ -18,7 +18,9 @@ bird::bird()
else printf("animation XML file not parsed\n");
model.sequences["flap"].start();
- currentseq="hover";
+
+ //how to track state/ bring animation in and out
+ state=SCANNING;
texture.loadImage("TextureBird.jpg");
@@ -204,6 +206,28 @@ void bird::update(map<int,player>& players, float angle){
else diveRate*=0.9f;
}
+ switch (state) {
+ case SCANNING:
+ if (diveRate>0.5f) {
+ model.sequences["flap"].fadeout(0.5);
+ model.sequences["swoop"].start();
+ state=SWOOPING;
+ }
+ break;
+ case SWOOPING:
+ if (diveRate<0.5f) {
+ model.sequences["swoop"].fadeout(0.5);
+ model.sequences["flap"].start();
+ state=SWOOPING;
+ }
+ break;
+ case ATTACKING:
+ break;
+ }
+
+ if (diveRate<0.0f) setSpeed(1.0f-diveRate);
+ else setSpeed(1.0f);
+
//if (sign(turnRate)) turnRate=min(2.0f,turnRate);
//else turnRate=max(-2.0f,turnRate);
@@ -224,7 +248,7 @@ void bird::update(map<int,player>& players, float angle){
while (heading <-180) heading=heading+360;
position-=direction.rotated(heading,ofVec3f(0,0,-1))*(velocity*ofGetHeight()*(1.0f+diveRate))*timeSeg; //.rotate(heading,ofVec3f(0,1,0))
- position +=ofVec3f(0,0,1)*diveRate*timeSeg;
+ position +=ofVec3f(0,0,5)*diveRate*timeSeg;
}
void bird::draw(){
glEnable(GL_DEPTH_TEST);
@@ -271,4 +295,10 @@ void bird::drawDebug(){
}
+void bird::setSpeed(float speed){
+ model.speed=speed;
+}
+float bird::getSpeed(){
+ return model.speed;
+}
diff --git a/gaunt01/src/bird.h b/gaunt01/src/bird.h
index 366f7f9..29a7a70 100644
--- a/gaunt01/src/bird.h
+++ b/gaunt01/src/bird.h
@@ -50,6 +50,10 @@
#define DEBUG 1
+#define SCANNING 1
+#define SWOOPING 2
+#define ATTACKING 3
+
class bird
{
public:
@@ -63,7 +67,7 @@ class bird
void setBounds(ofPlane* _bounds);
void setCentre(ofVec2f _centre);
- string currentseq;
+ int state;
morphmesh model;
ofRay pointer;
@@ -84,6 +88,10 @@ class bird
bool leaving;
float centrehead;
+
+ //animation speed
+ void setSpeed(float speed);
+ float getSpeed();
float heading;
diff --git a/gaunt01/src/main.cpp b/gaunt01/src/main.cpp
index 1f3ac12..d8ec5c8 100644
--- a/gaunt01/src/main.cpp
+++ b/gaunt01/src/main.cpp
@@ -6,7 +6,7 @@
int main( ){
ofAppGlutWindow window;
- ofSetupOpenGL(&window, 1024,768, OF_FULLSCREEN ); // <-------- setup the GL context
+ ofSetupOpenGL(&window, 1024,768, OF_WINDOW ); // <-------- setup the GL context
printf("%ix%i on screen %ix%i\n",ofGetWidth(),ofGetHeight(),ofGetScreenWidth(),ofGetScreenHeight());
// this kicks off the running of my app
// can be OF_WINDOW or OF_FULLSCREEN
diff --git a/gaunt01/src/morphmesh.cpp b/gaunt01/src/morphmesh.cpp
index a126002..6dc3338 100644
--- a/gaunt01/src/morphmesh.cpp
+++ b/gaunt01/src/morphmesh.cpp
@@ -82,8 +82,12 @@ void sequence::stop(){
vector<morphWeight> sequence::evaluate(float time){
float now=ofGetElapsedTimef();
- float seqtime=time-startTime;
- float looptime=fmod(seqtime,length);
+ float seqtime=now-startTime;
+ float animtime=time-startTime;
+ //for this to be correct time has to begin at actual startTime and proceed relatively
+ //stopTime has to be based on absolute time
+ //fadeweight algorithm has to be absolute
+ float looptime=fmod(animtime,length);
float fadeWeight=(seqtime<fadeinTime?seqtime/fadeinTime:seqtime>fadeoutTime&&fadeoutTime>-1?1.0-(seqtime/(stopTime-startTime)):1.0);
vector<morphWeight> weights;
map<string,track>::iterator i;
@@ -96,6 +100,7 @@ vector<morphWeight> sequence::evaluate(float time){
morphmesh::morphmesh()
{
loaded=false;
+ speed=1.0f;
/*
//testing track function
@@ -155,14 +160,16 @@ void morphmesh::draw(const vector<morphWeight>& weights){
}
void morphmesh::drawAnimated(){
- float time=ofGetElapsedTimef();
+ //compute time increment
+ time+=(ofGetElapsedTimef()-lastTime)*speed;
+ lastTime=ofGetElapsedTimef();
vector<morphWeight> weights;
map<string,sequence>::iterator i;
for( i = sequences.begin(); i != sequences.end(); i++ ) {
if (i->second.active) {
vector<morphWeight> newWeights=i->second.evaluate(time);
weights.insert(weights.end(),newWeights.begin(),newWeights.end());
- if (i->second.stopTime>0&&time>i->second.stopTime) i->second.active=false;
+ if (i->second.stopTime>0&&ofGetElapsedTimef()>i->second.stopTime) i->second.active=false;
}
}
draw(weights);
diff --git a/gaunt01/src/morphmesh.h b/gaunt01/src/morphmesh.h
index bc22c3d..2e7eee7 100644
--- a/gaunt01/src/morphmesh.h
+++ b/gaunt01/src/morphmesh.h
@@ -55,7 +55,6 @@ class track
track();
map<float,float> keys;
float evaluate(float time);
-
};
class sequence
@@ -66,6 +65,10 @@ class sequence
//the sequence knows the time (absolute seconds) it was started
//sequencer keeps track of playback time and start/stop of sequences
//tracks is a map of time,value pairs - built in interpolation via multimap
+
+ //180612
+ //switching to relative time
+ //sequence start and stoptimes should be absolute but anim cycle times should be relative
public:
sequence(string _name="",float _length=1.0,float _fadeinTime=-2.0,float _fadeoutTime=-2.0);
string name;
@@ -103,8 +106,11 @@ class morphmesh : public ofMesh
int getNumTargets();
int getNumSequences();
map<string,sequence> sequences; //public for direct access
+ float speed; //animation playback speed
protected:
private:
+ float time; //time since morphmesh begun relative to playback speed
+ float lastTime; //used to compute relative time;
map< string,vector<ofVec3f> > morphs;
bool loaded;
};
diff --git a/gaunt01/src/testApp.cpp b/gaunt01/src/testApp.cpp
index efd9459..db133c8 100644
--- a/gaunt01/src/testApp.cpp
+++ b/gaunt01/src/testApp.cpp
@@ -23,6 +23,8 @@ void testApp::setup(){
this->windowWidth = ofGetWidth();
this->windowHeight = ofGetHeight();
}
+
+ mirror=true;
bLearnBakground = true;
cam_angle=0;
@@ -99,7 +101,7 @@ void testApp::setup(){
cam.setPosition(windowWidth/2,windowHeight/2,-windowWidth);
cam.lookAt(ofVec3f(windowWidth/2,windowHeight/2,0),ofVec3f(0, -1, 0));
cam.setFov(41.1); //39.85); //53.13);
- cam.cacheMatrices(); //stop error messages
+ cam.cacheMatrices(); //stop error messages - changed API?
testpts=new ofVec3f[4];
@@ -459,6 +461,8 @@ void testApp::update(){
colorImg.setFromPixels(vidPlayer.getPixels(), 640,480);
//accumImg.setFromPixels(vidPlayer.getPixels(), 640,480);
}
+
+ if (mirror) colorImg.mirror(false,true);
colorImg.updateTexture();
@@ -1003,6 +1007,9 @@ void testApp::keyPressed(int key){
case 'q':
drawStats=!drawStats;
break;
+ case 'm':
+ mirror=!mirror;
+ break;
case 's':
saveSettings("settings.xml");
break;
@@ -1174,6 +1181,7 @@ void testApp::loadSettings(string filename){
cam_angle=ofToInt(XML.getAttribute("gauntlet","cam_angle","none",0));
threshold=ofToInt(XML.getAttribute("gauntlet","threshold","none",0));
diffchannel=ofToInt(XML.getAttribute("gauntlet","keyChannel","none",0));
+ learningRate=ofToFloat(XML.getAttribute("gauntlet","learningRate","none",0));
if(XML.pushTag("bounds")) {
for (int i=0;i<XML.getNumTags("vertex");i++){
border.push_back(ofVec2f(ofToFloat(XML.getAttribute("vertex","x","0",i)),ofToFloat(XML.getAttribute("vertex","y","0",i))));
diff --git a/gaunt01/src/testApp.h b/gaunt01/src/testApp.h
index 529acec..320292b 100644
--- a/gaunt01/src/testApp.h
+++ b/gaunt01/src/testApp.h
@@ -38,7 +38,7 @@
#define chan_S 5
#define chan_V 6
-#define DEBUG 0
+#define DEBUG 1
class testApp : public ofBaseApp{
@@ -58,6 +58,7 @@ class testApp : public ofBaseApp{
void gotMessage(ofMessage msg);
int windowWidth, windowHeight;
+ bool mirror; //horiz flip
int mode;