//-------------------------------------------------------------------------- void arduinoConnect::update(){ // update the arduino, get any data or messages. for(int i=0; i<numArduinos; i++){ //cout << "udpdate for ard " << i << endl; ard[i].update(); if (ard[i].isArduinoReady()){ if(!bSetupArduino[i]){ setupArduino(i); //REsetup this arduino bSetupArduino[i] = true; } accelX[i] = ard[i].getAnalog(0); accelY[i] = ard[i].getAnalog(1); accelZ[i] = ard[i].getAnalog(2); if((((testApp*)ofGetAppPtr())->bDebug)){ //if debugging, keep value history accelXHistory[i][frameCount] = accelX[i] - 300; accelYHistory[i][frameCount] = accelY[i] - 300; accelZHistory[i][frameCount] = accelZ[i] - 370; } } else setupArduino(i); //REsetup this arduino } frameCount++; if (frameCount >= 300) frameCount = 0; }
//-------------------------------------------------------------- void ofApp::update(){ if (arduinoAttached){ updateArduino(); if (!bSetupArduino){ if (ard.isArduinoReady()){ ofLogNotice("Connecting") << "setting up arduino"; setupArduino(0); } } } }
//-------------------------------------------------------------- void testApp::update(){ if ( ard.isArduinoReady()){ // 1st: setup the arduino if haven't already: if (bSetupArduino == false){ setupArduino(); bSetupArduino = true; // only do this once } // 2nd do the update of the arduino updateArduino(); } }
void ofApp::setup() { // Set framerate to 60 FPS ofSetFrameRate(60); // ARDUINO SETUP setupArduino(); // CLIENT SERVER SETUP setupOSC(); // ASTEROIDS GAME SETUP // we decided to remove the sounds for this delivery because audio was not suported in the classrooms (54.008 and 54.009) loadAsteroids(); noPlayers = 2; SpaceShip* player; player = new SpaceShip(1); players.push_back(player); players[0]->setImage("ship_green.png"); player = new SpaceShip(2); players.push_back(player); players[1]->setImage("ship_blue.png"); ofBackground(0); // Set background to black debug = false; //shot.setSpeed(4.0f); //shot.setVolume(0.3f); ofxLabel line; // no idea what is this line for // GUI SETUP // the gui shows the remaining lifes and the score of each player but since we use // the game logic of the other team, the lifes do not decrease when the player dies // now, the game finishes when a player reaches 5000 points gui.setup(); gui.add(Player1Lifes.setup("Player1 Lifes", "3")); gui.add(Player2Lifes.setup("Player2 Lifes", "3")); gui.add(Player1Score.setup("Player1 Score", "0")); gui.add(Player2Score.setup("Player2 Score", "0")); serialConnection.writeByte('h'); }
//-------------------------------------------------------------- void ofApp::update(){ if(myArduino.isArduinoReady()){ //when bsetupArduino is false it will run the setupArdiono to define the in and output of the arduiono if(bSetupArduino==false){ setupArduino(); // we started running arduino, so no need to start setup again. bSetupArduino=true; } //2nd run the update updateArduino(); } if(GameStart==true){ check= ofGetElapsedTimeMillis(); if(check>=counter){ distanceRight=myArduino.getAnalog(0); //analog pin A0 distanceLeft=myArduino.getAnalog(1); //analog pin A1 // change 0-1023 to centimeters Rightvolt=ofMap(distanceRight, 0, 1023, 0, 5000); //5 volts Leftvolt=ofMap(distanceLeft, 0, 1023, 0, 5000); Right=(21.61/(Rightvolt-0.1696))*1000; Left=(21.61/(Leftvolt-0.1696))*1000; counter=check+500; } //map the variables of the ir sensor to the width and hight of the screen. x=ofMap(Right,8,30,ofGetWidth(),0); y=ofMap(Left,8,30,ofGetHeight(),0); // if the value of the sensors is higher then 50 set player in center of the screen. if(Right>30){ x=ofGetWidth()/2; } if(Left>30){ y=ofGetHeight()/2; } //make target smaller; for(int i=0; i<points; i++){ rectSize= 40 - i*2; } //player code for(int i=0; i<1+points; i++){ player[i].update(); player[i].checkEdges(); } if(rectSize<1){ GameStart=false; time=check; } }else{ rectSize=40; } cout<<check/1000<< endl; }
//-------------------------------------------------------------- void gamuzaMain::setup(){ flagSystemLoaded = false; // first line of gamuza setup ////////////////////////////////////////////// // load settings from xml loadGamuzaSettings(); // automation isFullscreen = false; if(autoPilot){ gamuzaFullscreen(); } ////////////////////////////////////////////// ////////////////////////////////////////////// // init general openframeworks settings ofSetEscapeQuitsApp(false); ofSetFrameRate(200); ofEnableSmoothing(); ofSetLogLevel(OF_LOG_VERBOSE); ////////////////////////////////////////////// ////////////////////////////////////////////// // OSC data sending @ host_number(IP),host_port gamuzaSetup.lock(); setupOSC(); gamuzaSetup.unlock(); ////////////////////////////////////////////// ////////////////////////////////////////////// // AUDIO if(audioActivated){ gamuzaSetup.lock(); setupAudio(); gamuzaSetup.unlock(); } ////////////////////////////////////////////// ////////////////////////////////////////////// // MIDI gamuzaSetup.lock(); setupMidi(); gamuzaSetup.unlock(); ////////////////////////////////////////////// ////////////////////////////////////////////// // OPENNI if(openniActivated){ gamuzaSetup.lock(); sensorKinect.setupDevice(workingW,workingH,useKinectInfrared,sensorKinectLedState); gamuzaSetup.unlock(); } ////////////////////////////////////////////// ////////////////////////////////////////////// // FBO second screen output texture gamuzaSetup.lock(); setupFBO(); gamuzaSetup.unlock(); ////////////////////////////////////////////// ////////////////////////////////////////////// // ARDUINO if(arduinoActivated){ gamuzaSetup.lock(); setupArduino(); gamuzaSetup.unlock(); } ////////////////////////////////////////////// ////////////////////////////////////////////// // GUI // include setup of webcams & audio inputs gamuzaSetup.lock(); setupSettingPanel(); setupGui(); gamuzaSetup.unlock(); ////////////////////////////////////////////// ////////////////////////////////////////////// // SYSTEM currentSavedFrame = 0; gaFrameCounter = 0; ////////////////////////////////////////////// ////////////////////////////////////////////// // set log level to error only ofSetLogLevel(OF_LOG_ERROR); sendPrivateMessage(GAMUZA_CONSOLE_LOG, " "); ////////////////////////////////////////////// }
//-------------------------------------------------------------- void ofApp::update(){ //all math stuff //first step //if my arduino is ready ---> its a must to make openframworks to run with the arduino if(myArduino.isArduinoReady()){ //when bsetupArduino is false it will run the setupArdiono to define the in and output of the arduiono if(bSetupArduino==false){ setupArduino(); // we started running arduino, so no need to start setup again. bSetupArduino=true; } //2nd run the update updateArduino(); } if(hasLostGame==false){ //playerspeed //player one controls if(players[1].up==true){ players[1].YposPlayer --; } if(players[1].down==true){ players[1].YposPlayer++; } if(players[1].left==true){ players[1].XposPlayer --; } if(players[1].right==true){ players[1].XposPlayer++; } //player 2 controls if(players[2].up==true){ players[2].YposPlayer --; } if(players[2].down==true){ players[2].YposPlayer++; } if(players[2].left==true){ players[2].XposPlayer --; } if(players[2].right==true){ players[2].XposPlayer++; } pullToPlayer(); // //player score counter. player 1 if(ofDist(players[1].XposPlayer,players[1].YposPlayer,players[2].XposWeapon,players[2].YposWeapon) < players[1].playerRadius+WeaponRadius){ players[2].playerHit=true; Hitvalue2++; if(players[2].playerHit==true && Hitvalue2==1){ players[2].playerScore++; Hit.play(); } }else{ players[2].playerHit=false; Hitvalue2=0; } //player score 2 if(ofDist(players[2].XposPlayer,players[2].YposPlayer,players[1].XposWeapon,players[1].YposWeapon) < players[1].playerRadius+WeaponRadius){ players[1].playerHit=true; Hitvalue1++; //counts up when true if(players[1].playerHit==true && Hitvalue1==1){ //when it is 1 score will go +1 players[1].playerScore++; Hit.play(); } //when false the counter will reset so when it hits again you add 1 to the score again. }else{ players[1].playerHit=false; Hitvalue1=0; } if(players[1].playerScore>=5 || players[2].playerScore==5){ hasLostGame=true; } } }
//-------------------------------------------------------------- void testApp::setup(){ setupArduino(); ofSetVerticalSync(true); ofSetWindowShape(900, 480); ps3eye.initGrabber(620, 480); gui.setup("PS3Eye"); gui.setPosition(660,20); ofxToggle * autoGainAndShutter = new ofxToggle("Auto Gain & Shutter", false); autoGainAndShutter->addListener(this, &testApp::onAutoGainAndShutterChange); gui.add(autoGainAndShutter); ofxFloatSlider * gain = new ofxFloatSlider("Gain", 0.5, 0.0, 1.0); gain->addListener(this, &testApp::onGainChange); gui.add(gain); ofxFloatSlider * shutter = new ofxFloatSlider("Shutter", 0.5, 0.0, 1.0); shutter->addListener(this, &testApp::onShutterChange); gui.add(shutter); ofxFloatSlider * gamma = new ofxFloatSlider("Gamma", 0.5, 0.0, 1.0); gamma->addListener(this, &testApp::onGammaChange); gui.add(gamma); ofxFloatSlider * brightness = new ofxFloatSlider("Brightness", 0.5, 0.0, 1.0); brightness->addListener(this, &testApp::onBrightnessChange); gui.add(brightness); ofxFloatSlider * contrast = new ofxFloatSlider("Contrast", 0.5, 0.0, 1.0); contrast->addListener(this, &testApp::onContrastChange); gui.add(contrast); ofxFloatSlider * hue = new ofxFloatSlider("Hue", 0.5, 0.0, 1.0); hue->addListener(this, &testApp::onHueChange); gui.add(hue); ofxIntSlider * flicker = new ofxIntSlider("Flicker Type", 0, 0, 2); flicker->addListener(this, &testApp::onFlickerChange); gui.add(flicker); ofxIntSlider * wb = new ofxIntSlider("White Balance Mode", 4, 1, 4); wb->addListener(this, &testApp::onFlickerChange); gui.add(wb); ofxToggle * led = new ofxToggle("LED", true); led->addListener(this, &testApp::onLedChange); gui.add(led); gui.loadFromFile("settings.xml"); // Load initial values onAutoGainAndShutterChange(gui.getToggle("Auto Gain & Shutter")); onGainChange(gui.getFloatSlider("Gain")); onShutterChange(gui.getFloatSlider("Shutter")); onGammaChange(gui.getFloatSlider("Gamma")); onBrightnessChange(gui.getFloatSlider("Brightness")); onContrastChange(gui.getFloatSlider("Contrast")); onHueChange(gui.getFloatSlider("Hue")); onLedChange(gui.getToggle("LED")); onFlickerChange(gui.getIntSlider("Flicker")); onWhiteBalanceChange(gui.getIntSlider("White Balance")); image.allocate(480, 480); imageSmall.allocate(48, 48); display.allocate(image.getWidth(), image.getHeight(), OF_IMAGE_GRAYSCALE); bmp.allocate(imageSmall.getWidth(), imageSmall.getHeight(), OF_IMAGE_GRAYSCALE); ofImage imageA; ofImage imageG; ofImage imageC; ofImage imageT; imageA.loadImage("A.png"); imageG.loadImage("G.png"); imageC.loadImage("C.png"); imageT.loadImage("T.png"); bases.push_back(imageA); bases.push_back(imageG); bases.push_back(imageT); bases.push_back(imageC); debug = false; stage = 0; stageDuration.push_back(0); stageDuration.push_back(3); stageDuration.push_back(5); stageDuration.push_back(20); stageDuration.push_back(5); ofSetWindowPosition(0, 0); ofSetFullscreen(true); /* x=0.f; y=500.f; r=20.f; tweener_1.setup(1.f, // @duration: tween duration in seconds - @default: 1.f 0.5f, // @delay: delay to start the tween (will also apply to repat BACK_AND_FORTH and LOOP) - @default: 0.f &(Sine::easeOut), // @easingFunc: tween equasion (All PennerEasing equasions are available) - @default: &(Linear::easeNone) BACK_AND_FORTH, // @repeat: NONE, LOOP or BACK_AND_FORTH - @default: NONE &(Sine::easeIn)); // @backEasingFunc: if specified, will be used on the way back (only for repeat BACK_AND_FORTH) - @default: NULL tweener_1.addTween(&x, // @var: pointer to the variable we want to tween 500);*/ }
//-------------------------------------------------------------- void gamuzaMain::setup(){ flagSystemLoaded = false; // first line of gamuza setup ////////////////////////////////////////////// // load settings from xml loadGamuzaSettings(); if(START_WITH_FULLSCREEN){ isFullscreen = true; }else{ isFullscreen = false; } // automation if(autoPilot){ gamuzaFullscreen(); } ////////////////////////////////////////////// ////////////////////////////////////////////// // init general openframeworks settings ofSetFrameRate(FPS); ofEnableSmoothing(); ofSetLogLevel(OF_LOG_VERBOSE); ////////////////////////////////////////////// ////////////////////////////////////////////// // AUDIO if(audioActivated){ gamuzaSetup.lock(); setupAudio(); gamuzaSetup.unlock(); } ////////////////////////////////////////////// ////////////////////////////////////////////// // OPENNI if(openniActivated){ gamuzaSetup.lock(); sensorKinect.setupDevice(workingW,workingH,useKinectInfrared,sensorKinectLedState); gamuzaSetup.unlock(); } ////////////////////////////////////////////// ////////////////////////////////////////////// // FBO second screen output texture gamuzaSetup.lock(); setupFBO(); gamuzaSetup.unlock(); ////////////////////////////////////////////// ////////////////////////////////////////////// // OSC data sending @ host_number(IP),host_port if(oscActivated){ gamuzaSetup.lock(); setupOSC(); gamuzaSetup.unlock(); } ////////////////////////////////////////////// ////////////////////////////////////////////// // ARDUINO if(arduinoActivated){ gamuzaSetup.lock(); setupArduino(); gamuzaSetup.unlock(); } ////////////////////////////////////////////// ////////////////////////////////////////////// // GUI // include setup of webcams & audio inputs gamuzaSetup.lock(); setupGui(); gamuzaSetup.unlock(); ////////////////////////////////////////////// ////////////////////////////////////////////// // SYSTEM currentSavedFrame = 0; ////////////////////////////////////////////// ////////////////////////////////////////////// // set log level to error only ofSetLogLevel(OF_LOG_ERROR); ////////////////////////////////////////////// }