#include "testApp.h" //-------------------------------------------------------------- testApp::~testApp(){ saveSettings("settings.xml"); } //-------------------------------------------------------------- void testApp::setup(){ loadSettings("settings.xml"); ofBackground(0,0,0); ///ofSetVerticalSync(true); //some model / light stuff glEnable (GL_DEPTH_TEST); glShadeModel (GL_SMOOTH); glColorMaterial (GL_FRONT_AND_BACK, GL_DIFFUSE); glEnable (GL_COLOR_MATERIAL); printf("loading %s at %f,%f,%f",model_name.c_str(),model_x,model_y,model_z); //load the bottle model - the 3ds and the texture file need to be in the same folder model.loadModel(model_name, 1); model.setRotation(0, 180, 1, 0, 0); //model.setRotation(0, 90, 0, 1, 0); model.setPosition(model_x, model_y, model_z); //ofDisableArbTex(); mode=DISPLAY; whichClip=0; texture.loadMovie(clips[whichClip]); texture.setLoopState(OF_LOOP_NORMAL); texture.play(); light=true; camWidth = 320; // try to grab at this size. camHeight = 240; vidGrabber.setVerbose(true); vidGrabber.listDevices(); vidGrabber.setDeviceID(0); grabberAvailable=vidGrabber.initGrabber(camWidth,camHeight); //printf("asked for 320 by 240 - actual size is %i by %i\n", vidGrabber.width, vidGrabber.height); videoInverted = new unsigned char[camWidth*camHeight*3]; videoTexture.allocate(camWidth,camHeight, GL_RGB); ard.connect("/dev/ttyUSB0", 57600); ofAddListener(ard.EInitialized, this, &testApp::setupArduino); bSetupArduino = false; bSwitchArduino = false; } //-------------------------------------------------------------- void testApp::update(){ texture.idleMovie(); if (mode==GRAB) { vidGrabber.grabFrame(); if (vidGrabber.isFrameNew()){ int totalPixels = camWidth*camHeight*3; unsigned char * pixels = vidGrabber.getPixels(); for (int i = 0; i < totalPixels; i+=3){ unsigned int bright= (pixels[i]>>2)+ (pixels[i+1]>>1)+(pixels[i+1]>>2); //(0.2126*R) + (0.7152*G) + (0.0722*B) videoInverted[i] = (unsigned char)((226*bright)>>8); videoInverted[i+1] = (unsigned char)((200*bright)>>8); videoInverted[i+2] = (unsigned char)((20*bright)>>8); } videoTexture.loadData(videoInverted, camWidth,camHeight, GL_RGB); } } updateArduino(); } //-------------------------------------------------------------- void testApp::setupArduino(const int & version) { // remove listener because we don't need it anymore ofRemoveListener(ard.EInitialized, this, &testApp::setupArduino); // this is where you setup all the pins and pin modes, etc for (int i = 0; i < 13; i++){ ard.sendDigitalPinMode(i, ARD_OUTPUT); } ard.sendDigitalPinMode(7, ARD_INPUT); bSetupArduino = true; printf("arduino ready\n"); } //-------------------------------------------------------------- void testApp::updateArduino(){ // update the arduino, get any data or messages. ard.update(); // do not send anything until the arduino has been set up if (bSetupArduino) { if (bSwitchArduino!=ard.getDigital(7)) { bSwitchArduino=ard.getDigital(7); printf("pin 7 %i\n",bSwitchArduino); } } } //-------------------------------------------------------------- void testApp::draw(){ if (mode!=CALIBRATE&&bSetupArduino&!bSwitchArduino) return; for (int i=0;i': whichClip=(whichClip+1)%numClips; texture.stop(); texture.loadMovie(clips[whichClip]); texture.play(); break; case '/': light=!light; printf(light?"LIGHT ON\n":"LIGHT OFF\n"); break; } } //-------------------------------------------------------------- void testApp::keyReleased(int key){ if (activeView<0) for (int i=0;ikeys; XML.getAttributeNames("settings", keys, 0); mapsettings; for (int k=0;kkeys; XML.getAttributeNames("settings", keys, 0); for (int k=0;k