From 470c897cac4d55c78cd7a08c06442f6e12ad3545 Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Wed, 27 Jun 2012 09:36:16 +0100 Subject: fps thing --- src/main.cpp | 2 +- src/testApp.cpp | 64 ++++++++++++++++++++++++++++++++++++++++++++++++--------- src/testApp.h | 4 ++++ 3 files changed, 59 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/main.cpp b/src/main.cpp index ad74a97..5e84581 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6,7 +6,7 @@ int main( ){ ofAppGlutWindow window; - ofSetupOpenGL(&window, 450,800, OF_WINDOW ); // <-------- setup the GL context + ofSetupOpenGL(&window, 720,400, 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/src/testApp.cpp b/src/testApp.cpp index 3b0b9b1..ae42217 100644 --- a/src/testApp.cpp +++ b/src/testApp.cpp @@ -35,6 +35,18 @@ function to interpolate position */ +std::vector split(std::string l, char delim) +{ + std::istringstream stm(l); + std::vector tokens; + for (;;) { + std::string word; + if (!getline(stm, word, delim)) break; + tokens.push_back(word); + } + return tokens; +} + void testApp::setup(){ printf("setup: %ix%i on screen %ix%i\n",ofGetWidth(),ofGetHeight(),ofGetScreenWidth(),ofGetScreenHeight()); @@ -59,7 +71,7 @@ void testApp::setup(){ camera.cacheMatrices(); //stop error messages */ - ofSetFrameRate(60); + ofSetFrameRate(25); ofSetCircleResolution(windowWidth); ofEnableSmoothing(); @@ -69,7 +81,7 @@ void testApp::setup(){ camera.setFov(6.5); camera.cacheMatrices(); - numLines=20; + numLines=100; lines = new ofPoint[numLines]; imeis = new string[numLines]; @@ -83,6 +95,9 @@ void testApp::setup(){ } } + start=10; + end=15; + bgimg.allocate(256,256,OF_IMAGE_COLOR); @@ -129,17 +144,33 @@ void testApp::setup(){ //-------------------------------------------------------------- void testApp::update(){ - char udpMessage[1024]; + //check incoming messages + //create device or update as necessary + char udpMessage[1024]; udpConnection.Receive(udpMessage,1024); string message=udpMessage; - if(message!=""){ - printf("%s\n",message.c_str()); + if(message.length()){ + vector tokens=split(message,','); + string imsi=tokens[0].substr(4); + //long dev=atol(n.c_str()); something crazy going on. this always seems to read out 32 bits + if (!tokens[0].substr(0,4).compare("IMSI")) { //not an event + if (!devices.count(imsi)) { + //create a new device at a random position + float a=ofRandom(TWO_PI); + float r=ofRandom(windowWidth/2); + devices[imsi]=obtsDevice(imsi,icons,ofVec2f(a,r)); + } + printf("%s\n",imsi.c_str()); + } + else printf("%s\n",tokens[0].c_str()); } - } //-------------------------------------------------------------- void testApp::draw(){ + if (ofRandom(1.0)>0.99) start=min(99,start+1); + if (ofRandom(1.0)>0.98) end=min(99,end+1); + glDisable(GL_LIGHTING); bgimg.draw(0,0,windowWidth,windowHeight); @@ -166,32 +197,45 @@ void testApp::draw(){ } - for (int i=0;i::iterator i=devices.begin();i!=devices.end();i++){ + (*i).second.draw(timeScale); + } + + ofPopMatrix(); + camera.end(); ofSetHexColor(0xffffff); char reportStr[1024]; sprintf(reportStr, "fps: %f", ofGetFrameRate()); ofDrawBitmapString(reportStr, 10, windowHeight-10); + + //ofSaveFrame(); } //-------------------------------------------------------------- void testApp::keyPressed(int key){ switch (key){ case ' ': + ofSaveFrame(); + printf("[%8.2f] saved an image\n",ofGetElapsedTimef()); break; } } diff --git a/src/testApp.h b/src/testApp.h index bb7e6b1..29c9d03 100644 --- a/src/testApp.h +++ b/src/testApp.h @@ -25,10 +25,14 @@ class testApp : public ofBaseApp{ ofxUDPManager udpConnection; ofCamera camera; + + map devices; int numLines; ofPoint *lines; string *imeis; + + int start,end; ofImage bgimg; ofColor *cols; -- cgit v1.2.3