//-------------------------------------------------------------- void testApp::setupDrawableOFPath(){ #ifndef COMMAND_LINE_ONLY vector<string> subdirs = ofSplitString("OF path: " + getOFRoot(), "/"); int textLength = 0; int padding = 5; string path = ""; int lines=1; int fontSize = 8; float leading = 1.7; ofPathRect.x = padding; ofPathRect.y = padding; ofPathDrawPoint.x = padding*2; ofPathDrawPoint.y = padding*2 + fontSize * leading; for(int i = 0; i < subdirs.size(); i++) { if (i > 0 && i<subdirs.size()-1) { subdirs[i] += "/"; } if(textLength + subdirs[i].length()*fontSize < ofGetWidth()-padding){ textLength += subdirs[i].length()*fontSize; path += subdirs[i]; }else { path += "\n"; textLength = 0; lines++; } } ofPathRect.width = textLength + padding*2; if (lines > 1){ ofPathRect.width = ofGetWidth() - padding*2; } ofPathRect.height = lines * fontSize * leading + (padding*2); drawableOfPath = path; panelAddons.setPosition(panelAddons.getPosition().x, ofPathRect.y + ofPathRect.height + padding); examplesPanel.setPosition(examplesPanel.getPosition().x, ofPathRect.y + ofPathRect.height + padding); #endif }
//-------------------------------------------------------------- void ofApp::loadCsvToMemes(string filePath){ ofFile file(filePath); if(!file.exists()){ ofLogError("The file " + filePath + " is missing"); } ofBuffer buffer(file); //データをVector(配列)に読み込む //CSVファイルを読み込んで、1行ごとに配列linesの要素として読み込む for (ofBuffer::Line it = buffer.getLines().begin(), end = buffer.getLines().end(); it != end; ++it) { string line = *it; vector<string> data = ofSplitString(line, ","); if (data.size()>=6) { Meme meme; meme.user_id = data[0]; meme.zone_date = data[1]; meme.zone_focus = ofToFloat(data[3]); meme.zone_calm = ofToFloat(data[4]); meme.zone_posture = ofToFloat(data[5]); memes.push_back(meme); if(it == buffer.getLines().begin()){ max_focus = min_focus = meme.zone_focus; max_calm = min_calm = meme.zone_calm; max_posture = min_posture = meme.zone_posture; } else{ //データをひとつずつ比較しながら最小値最大値を調べる max_focus = (meme.zone_focus > max_focus) ? meme.zone_focus : max_focus; min_focus = (meme.zone_focus < min_focus) ? meme.zone_focus : min_focus; max_calm = (meme.zone_calm > max_calm) ? meme.zone_calm : max_calm; min_calm = (meme.zone_calm < min_calm) ? meme.zone_calm : min_calm; max_posture = (meme.zone_posture > max_posture) ? meme.zone_posture : max_posture; min_posture = (meme.zone_posture < min_posture) ? meme.zone_posture : min_posture; } } } }
void ofxLayout::updateAssets(ofxLayoutElement *element){ if(element->hasStyle(OSS_KEY::BACKGROUND_IMAGE)){ string imageFilename = element->getStringStyle(OSS_KEY::BACKGROUND_IMAGE); ofxLoaderBatch* imagesBatch = assets.getBatch(IMAGES_BATCH); if(ofStringTimesInString(imageFilename, ":")){ vector<string> ids = ofSplitString(imageFilename, ":"); imagesBatch = assets.getBatch(IMAGES_BATCH)->getBatch(ids[0]); imageFilename = ids[1]; } ofFile file(ofToDataPath(imageFilename)); string bgImgExt = ofToLower(file.getExtension()); bool fileExists = ofFile::doesFileExist(imageFilename); if(bgImgExt == "svg"){ if(fileExists){ element->loadSvg(imageFilename); } else if(element->isSVG){ element->getSvg()->clear(); } } else if((bgImgExt == "jpg" || bgImgExt == "png") &&!imageFilename.empty() && !imagesBatch->hasTexture(imageFilename)){ imagesBatch->addTexture(imageFilename, imageFilename); imagesBatch->loadTexture(imageFilename); } } // Get fonts if(element->hasStyle(OSS_KEY::FONT_FAMILY)){ string fontFilename = element->getStringStyle(OSS_KEY::FONT_FAMILY); if(fonts->count(fontFilename) == 0){ (*fonts)[fontFilename] = new ofxFontStash(); fonts->at(fontFilename)->setup(fontFilename, 1.0, 2048, true, 8, 1.0f ); } } }
//-------------------------------------------------------------- void testApp::setup() { ofDisableAntiAliasing(); ofBackgroundHex(0xfdefc2); ofSetLogLevel(OF_LOG_NOTICE); ofSetVerticalSync(true); // Box2d box2d.init(); box2d.setGravity(0, 30); box2d.createGround(); box2d.setFPS(30.0); // load the lines we saved... ifstream f; f.open(ofToDataPath("lines.txt").c_str()); vector <string> strLines; while (!f.eof()) { string ptStr; getline(f, ptStr); strLines.push_back(ptStr); } f.close(); for (int i=0; i<strLines.size(); i++) { vector <string> pts = ofSplitString(strLines[i], ","); if(pts.size() > 0) { ofPtr <ofxBox2dEdge> edge = ofPtr<ofxBox2dEdge>(new ofxBox2dEdge); for (int j=0; j<pts.size(); j+=2) { if(pts[j].size() > 0) { float x = ofToFloat(pts[j]); float y = ofToFloat(pts[j+1]); edge.get()->addVertex(x, y); } } edge.get()->create(box2d.getWorld()); edges.push_back(edge); } } }
void ofxRPiCameraVideoGrabber::setup(CameraState cameraState) { setup(cameraState.cameraSettings); map<string, string> keyValueMap = cameraState.keyValueMap; for(auto iterator = keyValueMap.begin(); iterator != keyValueMap.end(); iterator++) { string key = iterator->first; string value = iterator->second; //ofLogVerbose(__func__) << "key: " << key << " value: " << value; if(key == "sharpness") setSharpness(ofToInt(value)); if(key == "contrast") setContrast(ofToInt(value)); if(key == "brightness") setBrightness(ofToInt(value)); if(key == "saturation") setSaturation(ofToInt(value)); if(key == "ISO") setISO(ofToInt(value)); if(key == "AutoISO") setAutoISO(ofToBool(value)); if(key == "DRE") setDRE(ofToInt(value)); if(key == "cropRectangle") { vector<string> rectValues = ofSplitString(value, ","); if(rectValues.size() == 4) { setSensorCrop(ofToInt(rectValues[0]), ofToInt(rectValues[1]), ofToInt(rectValues[2]), ofToInt(rectValues[3])); } } if(key == "zoomLevelNormalized") setZoomLevelNormalized(ofToFloat(value)); if(key == "mirror") setMirror(value); if(key == "rotation") setRotation(ofToInt(value)); if(key == "imageFilter") setImageFilter(value); if(key == "exposurePreset") setExposurePreset(value); if(key == "evCompensation") setEvCompensation(ofToInt(value)); if(key == "autoShutter") setAutoShutter(ofToBool(value)); if(key == "shutterSpeed") setShutterSpeed(ofToInt(value)); if(key == "meteringType") setMeteringType(value); if(key == "SoftwareSaturationEnabled") setSoftwareSaturation(ofToBool(value)); if(key == "SoftwareSharpeningEnabled") setSoftwareSharpening(ofToBool(value)); } }
//-------------------------------------------------------------- void ofApp::setup(){ currentIndex = 0; //Path to the comma delimited file string filePath = "morse.csv"; //Use a ofTrueTypeFont for scalable text font.load("frabk.ttf", 122); //Load file placed in bin/data ofFile file(filePath); if(!file.exists()){ ofLogError("The file " + filePath + " is missing"); } ofBuffer buffer(file); //Read file line by line for (ofBuffer::Line it = buffer.getLines().begin(), end = buffer.getLines().end(); it != end; ++it) { string line = *it; //Split line into strings vector<string> words = ofSplitString(line, ","); //Store strings into a custom container MorseCodeSymbol symbol; symbol.character = words[0]; symbol.code = words[1]; //Save MorseCodeSymbols for later morseCodeSymbols.push_back(symbol); //Debug output ofLogVerbose("symbol.character: " + symbol.character); ofLogVerbose("symbol.code: " + symbol.code); } //Load our Morse code sounds player.setup(); }
void ofApp::loadURL_recentLetters(ofHttpResponse &response){ for (int i=0; i<allEntries.size(); i++) { vector<string> cutEntries=ofSplitString(allEntries[i], ","); //delete the first parts in all of them ofStringReplace(cutEntries[0], "\"ID\":\"", ""); ofStringReplace(cutEntries[1], "\"letter\":\"", ""); ofStringReplace(cutEntries[2], "\"owner\":\"", ""); //delete the last " in all of them ofStringReplace(cutEntries[0], "\"", ""); ofStringReplace(cutEntries[1], "\"", ""); ofStringReplace(cutEntries[2], "\"", ""); Letter entry(cutEntries[0], cutEntries[1], cutEntries[2], i); if(allLetters.size()<5){ allLetters.push_back(entry); allLetters[allLetters.size()-1].loadImage(); } else{ for (int i=0; i<allLetters.size(); i++) { if (entry._id==allLetters[i]._id) { break; } if (i==allLetters.size()-1) { allLetters.insert(allLetters.begin(),entry); allLetters[0].loadImage(); allLetters.pop_back(); for (int j=1; j<allLetters.size(); j++) { printf("%i", j); allLetters[j].reset(); } break; } } } } if (response.status==200 && response.request.name=="async_req") { //setup which ones are shown first currLetterImgNo1=allLetters.size()-1; currLetterImgNo2=allLetters.size()-2; currLetterImgNo3=allLetters.size()-3; currLetterImgNo4=allLetters.size()-4; currLetterImgNo5=allLetters.size()-5; } }
//-------------------------------------------------------------- void testApp::bangFired(ofxTLBangEventArgs& bang){ if(bang.track->getName() == "scene"){ vector<string> parts = ofSplitString(bang.flag, " "); timeline.stop(); particleRenderer.sampleTextureColors(player.getVideoPlayer()->getPixelsRef()); player.getVideoPlayer()->stop(); if(parts.size() == 2 && scenePaths.find(parts[0]) != scenePaths.end() && loadScene(scenePaths[parts[0]])) { player.getVideoPlayer()->setFrame(ofToInt(parts[1])); player.update(); if(!supressPlay){ player.getVideoPlayer()->play(); } timeline.play(); } } }
//-------------------------------------------------------------- void testApp::frameEvent() { // clear the screen ofBackground(255, 255, 255); // move and draw all the balls for (int i = 0; i < balls.size(); i++) { balls[i]->calc(); balls[i]->draw(); } // read any incoming messages if (client.messageAvailable()) { vector<string> msg = client.getDataMessage(); vector<string> xy = ofSplitString(msg[0], ","); float x = ofToInt(xy[0]); float y = ofToInt(xy[1]); Ball* ball = new Ball(x, y, client.getMWidth(), client.getMHeight()); balls.push_back(ball); } }
void ofApp::urlResponse(ofHttpResponse & response){ printf(" received response\n"); loadingResponseDone=true; theResponse=ofToString(response.data); ofStringReplace(theResponse, "[{", ""); ofStringReplace(theResponse, "}]", ""); //printf("%s", theResponse.c_str()); allEntries=ofSplitString(theResponse, "},{"); if (URLsToLoad[currentURLNo]==recentPostcards){ loadURL_recentPostcards(response); } else if (URLsToLoad[currentURLNo]==recentLetters){ loadURL_recentLetters(response); } else if(URLsToLoad[currentURLNo]==currentAlphabet){ loadURL_alphabet(response); } else if (URLsToLoad[currentURLNo]==currentQuestion){ loadQuestion(response); } }
//-------------------------------------------------------------- string BaseModel::getApplicationPath(){ // from http://stackoverflow.com/questions/799679/programatically-retrieving-the-absolute-path-of-an-os-x-command-line-app/1024933#1024933 if(applicationPath == ""){ int ret; pid_t pid; char pathbuf[1024]; pid = getpid(); ret = proc_pidpath (pid, pathbuf, sizeof(pathbuf)); if(ret <= 0){ ofLogError() << "PID " << pid << " proc_pidpath(): " << strerror(errno); }else{ ofLogVerbose() << "proc " << pid << " path: " << pathbuf; } applicationPath = string(pathbuf); vector<string> pathParts = ofSplitString(applicationPath, "/"); applicationName = pathParts[pathParts.size() - 1]; } return applicationPath; }
vector<string> ofxFTPClient::list(string path) { try{ startFtpSesssion(); string res; ftpClient->login(user, pass); istream &ist = ftpClient->beginList(path, true); Poco::StreamCopier::copyToString(ist, res); ftpClient->endList(); return ofSplitString(res, "\n", true, true); endFtpSession(); } catch (Poco::Exception& exc) { cout << exc.displayText() << endl; // return 0; } }
void ofApp::draw(){ ofPushMatrix(); ofTranslate(300, 0); ofSetColor(0); vector<string> lines = ofSplitString(ocrResult, "\n"); for(int i = 0; i < lines.size(); i++) { ofDrawBitmapString(lines[i], 10, 20 + i * 12); } ofSetColor(255); vidGrabber.draw(0, 10); grayImg.draw(400, 10); scaled.draw(0, 400); ofPopMatrix(); gui.draw(); }
string config(string file){ string ret; ifstream config(ofToDataPath(file).c_str()); while (config.peek()!=EOF) { string nextLine; getline(config, nextLine); vector<string> token=ofSplitString(nextLine, "="); if(token.size()){ if(!token[0].compare("ROOT_DIR")){ ret = token[1]; } } else { ret="."; } } config.close(); return ret; }
/* void ofxTextInputField::setCursorPositionFromXY() { cursorPosition = cursorx; vector<string> parts = ofSplitString(text, "\n"); for(int i = 0 ; i < cursory; i++) { cursorPosition += parts[i].size() + i; // for carriage returns } } */ int ofxTextInputField::getCursorPositionFromMouse(int x, int y) { int cursorX = 0; int cursorY = 0; float pos = y - bounds.y - VERTICAL_PADDING; pos /= fontRef->getLineHeight(); int line = pos; cursorY = line; vector<string> lines = ofSplitString(text, "\n"); if(cursorY>=lines.size()-1) cursorY = lines.size()-1; if(lines.size()>0) { cursorX = fontRef->getPosition(lines[cursorY], x - HORIZONTAL_PADDING - bounds.x); } int c = 0; for(int i = 0; i < cursorY; i++) { c += lines[i].size() + 1; } c += cursorX; return c; }
void testApp::urlResponse(ofHttpResponse & response){ loadingResponseDone=true; theResponse=ofToString(response.data); ofStringReplace(theResponse, "[{", ""); ofStringReplace(theResponse, "}]", ""); allEntries=ofSplitString(theResponse, "},{"); if (URLsToLoad[currentURLNo]==recentPostcardsBerlin){ loadURL_recentPostcards(response); } else if (URLsToLoad[currentURLNo]==recentLettersBerlin){ loadURL_recentLetters(response); } else if(URLsToLoad[currentURLNo]==currentAlphabetBerlin && berlinAlphabetLoaded==false){ loadURL_alphabetGerman(response); } else if(URLsToLoad[currentURLNo]==currentAlphabetBerlin && berlinAlphabetLoaded==true){ loadURL_alphabetLatvian(response); } else if (URLsToLoad[currentURLNo]==currentQuestion){ loadQuestion(response); } }
//------------------------------------------------------------------------------ void ofxHTTPBaseRequest::setFormFieldsFromURI(const URI& uri) { // attempt to extract uri query as form fields vector <string> queryTokens = ofSplitString(uri.getQuery(),"&",true,true); vector<string>::const_iterator iter = queryTokens.begin(); while(iter != queryTokens.end()) { string queryToken = (*iter); size_t index = queryToken.find_first_of("="); if(index != string::npos) { string name = queryToken.substr(0,index); string value = queryToken.substr(index + 1); addFormField(name,value); } else { addFormField(queryToken); } ++iter; } }
bool LedsManager::parseLedLine(string& line, ofPoint& position) { if(line.size() == 0){ return false; } char chars[] = "{}"; removeCharsFromString(line, chars); //vector <string> strings = ofSplitString(line, ". " ); //id = ofToInt(strings[0]); vector <string> positionsStrings = ofSplitString(line, ", " ); position.x = ofToFloat(positionsStrings[0])*0.1; position.y = ofToFloat(positionsStrings[1])*0.1; position.z = ofToFloat(positionsStrings[2])*0.1; return true; }
void shakeData::loadDAT(string filename) { file=filename; ifstream input(ofToDataPath(file).c_str()); string buffer; int lineCount=0; getline(input,buffer); double lastTime=0; while(!input.eof()){ getline(input, buffer); vector<string> spl=ofSplitString(buffer," \t"); if(spl.size()){ float time=ofToFloat(spl[0]); uData.push_back(dataPoint(ofToFloat(spl[1]),time-lastTime)); sampFreq=1/(time-lastTime); lastTime=time; } } input.close(); processData(); }
//--------------------------------------------------- // On Serial Message // // Get incomming message and send to correct Customer // void ofApp::onNewMessage(string & message) { cout << "onNewMessage, message: " << message << "\n"; int _customerIndex; int _command; int _valInt; string _valString; vector<string> input = ofSplitString(message, ":"); if(input.size() == 3) { _customerIndex = ofToInt(input.at(0)); _command = ofToInt(input.at(1)); _valString = ofToString(input.at(2)); _valInt = ofToInt(input.at(2)); arrCustomers[_customerIndex].handleSerialMessage(_command, _valString, _valInt); } }
//-------------------------------------------------------------- void ofxStreetViewCollector::loadPoints(string path){ ofXml xml; // points.clear(); if (xml.load(path)) { if(xml.exists("SVPoint")){ xml.setTo("SVPoint[0]"); do { if(xml.getName() == "SVPoint"){ SVPoint point; point.ID = xml.getValue("id"); string pos = xml.getValue("pos"); vector<string>p = ofSplitString(pos, ", "); point.setPos(stringToDouble(p[0]), stringToDouble(p[1]), stringToDouble(p[2])); if (xml.exists("links")) { xml.setTo("links[0]"); if (xml.getName() == "links") { if (xml.exists("link")) { xml.setTo("link[0]"); do { if (xml.getName() == "link") { point.links.push_back(xml.getValue()); } } while(xml.setToSibling()); } } xml.setToParent(); xml.setToParent(); } if(points.count(point.ID) == 0){ savePoint(point); points[point.ID] = point; } } } while( xml.setToSibling() ); } } }
int Telemetry::parse(string line) { ofLogNotice() << "onNewSerialLine, message: " << line << endl; vector<string> input = ofSplitString(line, ","); string msgtype = input.at(0); if(msgtype == "GPSL") { if( input.size() == 3) { ofLogNotice() << "GPSL line found"; gps.lat = ofToFloat( input.at(1) ); gps.lon = ofToFloat( input.at(2) ); int i = 0; ofNotifyEvent( onGpsCoordinates, i ); } else { ofLogNotice() << "ignored GPS reading: " << line; } } else if (msgtype == "GPSQ") { if( input.size() == 4) { ofLogNotice() << "GPSQ line found"; gps.fix = ofToBool( input.at(1) ); gps.quality = ofToInt( input.at(2) ); gps.satelites = ofToInt( input.at(3) ); } else { ofLogNotice() << "ignored GPS reading: " << line; } } else if(msgtype == "IMU") { if( input.size() == 4) { imu.yaw = ofToFloat( input.at(1) ); imu.pitch = ofToFloat( input.at(2) ); imu.roll = ofToFloat( input.at(3) ); } else { ofLogNotice() << "rejected IMU reading: " << line; } // ofLogNotice() << "IMU line found"; // for ( std::vector<std::string>::iterator it=input.begin(); it<input.end(); it++) { // std::cout << ' ' << *it; // } } }
void ofApp::loadURL_recentPostcards(ofHttpResponse &response){ if (allEntries.size()>1) { for(int i=0; i<allEntries.size(); i++){ vector<string> cutEntries =ofSplitString(allEntries[i], ","); //delete the first parts in all of them ofStringReplace(cutEntries[0], "\"ID\":\"", ""); ofStringReplace(cutEntries[1], "\"longitude\":\"", ""); ofStringReplace(cutEntries[2], "\"latitude\":\"", ""); ofStringReplace(cutEntries[3], "\"postcardText\":\"", ""); ofStringReplace(cutEntries[4], "\"owner\":\"", ""); //delete the last " in all of them ofStringReplace(cutEntries[0], "\"", ""); ofStringReplace(cutEntries[1], "\"", ""); ofStringReplace(cutEntries[2], "\"", ""); ofStringReplace(cutEntries[3], "\"", ""); ofStringReplace(cutEntries[4], "\"", ""); Postcard entry(cutEntries[0], cutEntries[1], cutEntries[2],cutEntries[3],cutEntries[4]); if(allPostcards.size()<5){ allPostcards.push_back(entry); allPostcards[allPostcards.size()-1].loadImage(); } else{ for (int i=0; i<allPostcards.size(); i++) { if (entry._id==allPostcards[i]._id) { break; } if (i==allPostcards.size()-1) { allPostcards.insert(allPostcards.begin(),entry); allPostcards[0].loadImage(); allPostcards.pop_back(); break; } } } } } if (response.status==200 && response.request.name=="async_req") { //setup which ones are shown first //currImgNo=allPostcards.size()-1; } }
//------------------------------------------------------------------------------ void ofApp::onWebSocketFrameReceivedEvent(WebSocketFrameEventArgs& evt) { std::string userId = evt.getConnectionRef().getClientAddress().toString(); std::string rawStringMessage = evt.getFrameRef().getText(); // === e.g. "20,44" std:vector<std::string> tokens = ofSplitString(rawStringMessage,","); //if message has 2 tokens, it means mouse position if(tokens.size() == 2) { float x = ofMap(ofToInt(tokens[0]), 0, 640, 0, ofGetWidth()); float y = ofMap(ofToInt(tokens[1]), 0, 480, 0, ofGetHeight()); ofVec2f position = ofVec2f(x,y); for(std::vector<Person>::iterator p = people.begin(); p != people.end(); ++p){ if ((*p).id == evt.getConnectionRef().getClientAddress().toString()){ (*p).pos = position; } } } //else, it means a click else if(tokens.size() == 1) { for(std::vector<Person>::iterator p = people.begin(); p != people.end(); ++p){ if ((*p).id == evt.getConnectionRef().getClientAddress().toString()){ (*p).col = ofColor(ofRandom(255),ofRandom(255),ofRandom(255)); (*p).curvature = ofRandom(800, 3000); } } } else { ofLogError("ofApp::onWebSocketFrameReceivedEvent") << "Unable to read message " << evt.getFrameRef().getText(); } }
void phdWarper::setAsString(string & _setup) { vector<string> items = ofSplitString(_setup, ";", true, true); if(items.size() > 17 && items[0] == "W") { setSides(ofToInt(items[1])); double x1, y1, x2, y2, x3, y3, x4, y4; x1 = ofToFloat(items[2]); y1 = ofToFloat(items[3]); x2 = ofToFloat(items[4]); y2 = ofToFloat(items[5]); x3 = ofToFloat(items[6]); y3 = ofToFloat(items[7]); x4 = ofToFloat(items[8]); y4 = ofToFloat(items[9]); setSrcQuad(x1,y1,x2,y2,x3,y3,x4,y4); x1 = ofToFloat(items[10]); y1 = ofToFloat(items[11]); x2 = ofToFloat(items[12]); y2 = ofToFloat(items[13]); x3 = ofToFloat(items[14]); y3 = ofToFloat(items[15]); x4 = ofToFloat(items[16]); y4 = ofToFloat(items[17]); setDstQuad(x1,y1,x2,y2,x3,y3,x4,y4); } }
cloudsSequencer::cloudsSequencer(string f, vector<lukeNote>& n) { string sline; ofFile seqfile (GetCloudsDataPath()+"sound/seqs/" + f); if(!seqfile.exists()) { ofLogError("can't find sequence!"); } ofBuffer seqbuf(seqfile); while(!seqbuf.isLastLine()) { sline = seqbuf.getNextLine(); vector<string> temp = ofSplitString(sline, " "); lukeNote foo; foo.starttime = ofToFloat(temp[0])/1000.; foo.pitch = ofToInt(temp[1]); foo.velo = (ofToFloat(temp[2])/128.); foo.dur = ofToFloat(temp[3])/1000.; //cout << foo.starttime << ": " << foo.pitch << " " << foo.velo << " " << foo.dur << endl; n.push_back(foo); } }
//-------------------------------------------------------------- void testApp::mpeMessageEvent(ofxMPEEventArgs& event){ //received a message from the server string msg = event.message; cout << msg << endl; vector<string> xy = ofSplitString(msg, ";"); if(xy[0]=="ball") { float x = ofToInt(xy[1]); float y = ofToInt(xy[2]); float vx = ofToInt(xy[3]); float vy = ofToInt(xy[4]); float c = ofToInt(xy[5]); Ball* ball = new Ball(x, y, client.getMWidth(), client.getMHeight(),vx,vy,c); balls.push_back(ball); } else if (xy[0] == "random") { rnd = ofToFloat(xy[1]); } }
void ofApp::onMessage(ofxLibwebsockets::Event & e){ cout << "message: " << e.message <<endl; vector<string> msg = ofSplitString( e.message , " "); if (msg[0] == "/time"){ remoteTime = ofToInt(msg[1]); if( abs( localTime-remoteTime ) > 10 ){ resync(remoteTime); } } else if (msg[0] == "/trigger"){ twinkle->triggerPulse(ofToInt(msg[1])); } else if (msg[0] =="/welcome"){ socket.send("/imHost"); switchScene(ofToInt(msg[1])); } else if (msg[0] == "/sceneChange" ){ switchScene(ofToInt(msg[1])); } else if(msg[0] == "/home"){ noPlace->addHome(msg[1]); } }
//-------------------------------------------------------------- void Path3D::parsePts(string filename, ofPolyline &polyline){ ofFile file = ofFile(ofToDataPath(filename)); polyline.clear(); if(!file.exists()){ ofLogError("The file " + filename + " is missing"); } ofBuffer buffer(file); //Read file for (ofBuffer::Line it = buffer.getLines().begin(); it != buffer.getLines().end(); it++) { string line = *it; float scalar = 10; ofVec3f offset; if (filename == "path_XZ.txt"){ offset = ofVec3f(0, 0, 0); scalar = 3; } else if (filename == "path_YZ.txt"){ offset = ofVec3f(0, 0, 0); scalar = 3; } else{ offset = ofVec3f(0, 0, .25); scalar = 3; } ofStringReplace(line, "{", ""); ofStringReplace(line, "}", ""); cout<<line<<endl; vector<string> coords = ofSplitString(line, ", "); // get x y z coordinates ofVec3f p = ofVec3f(ofToFloat(coords[0])*scalar,ofToFloat(coords[1])*scalar,ofToFloat(coords[2])*scalar); p += offset; polyline.addVertex(p); } }
vector<string> ofGLSupportedExtensions(){ #ifdef TARGET_OPENGLES char* extensions = (char*)glGetString(GL_EXTENSIONS); if(extensions){ string extensions_str = extensions; return ofSplitString(extensions_str," "); }else{ return vector<string>(); } #else int numExtensions=0; glGetIntegerv(GL_NUM_EXTENSIONS, &numExtensions); std::vector<std::string> extensions; for(int i=0;i<numExtensions;i++){ char* extension = (char*)glGetStringi(GL_EXTENSIONS, i); if(extension){ extensions.emplace_back(extension); } } return extensions; #endif }