void testApp::loadGestures(ofFileDialogResult dialogResult) { ofxXmlSettings file; if(!file.loadFile(dialogResult.filePath)) return; gvfh.gvf_clear(); initColors(); int gestureCount = file.getNumTags("GESTURE"); if(gestureCount < 1) return; cout << gestureCount << " gestures." << endl; for(int i = 0; i < gestureCount; i++) { file.pushTag("GESTURE", i); ofPoint p; p.x = file.getValue("INIT_POINT:X", (double)-1); p.y = file.getValue("INIT_POINT:Y", (double)-1); file.pushTag("POINTS"); int pointCount = file.getNumTags("PT"); if(pointCount < 1) return; gvfh.gvf_learn(); gvfh.addTemplateGesture(p, generateRandomColor()); for(int j = 0; j < pointCount; j++) { p.x = file.getValue("PT:X", (double)-1, j); p.y = file.getValue("PT:Y", (double)-1, j); gvfh.gvf_data(p); } file.popTag(); file.popTag(); gvfh.gvf_follow(); } }
//-------------------------------------------------------------- void testApp::mousePressed(int x, int y, int button){ // a new gesture will not start if the user clicks on the UI area or outside the gesture area if(currentGesture.isPointInGestureArea(x, y) && !currentGesture.isPointInArea(guiArea, x, y)) { // the current gesture is initialised with its initial point currentGesture.initialiseNonNormalised(x, y); // here the point is already normalised ofPoint initialPoint = currentGesture.getInitialOfPoint(); if(gvfh.get_state() == STATE_LEARNING) { gvfh.addTemplateGesture(initialPoint, generateRandomColor()); } // first point is always 0.5 (the gesture's initialPoint property can be used to translate the gesture) currentGesture.addPoint(ofPoint(0.5, 0.5)); isMouseDrawing = true; } }
void linepath(float x1,float y1,float x2,float y2)//function tht generates points on a straight line { // through (x1,y1) and (x2,y2) for the shapes to move static int shapeDecider=0; //using digital differential analyser algorithm struct randomnumbers r; radius=7; r=generateRandomColor(); float steps,dx,dy,xinc,yinc,k,x,y,ang=0; dx=x2-x1; dy=y2-y1; if(abs(dx)>abs(dy)) steps=abs(dx); else steps=abs(dy); xinc=(float)dx/(float)steps; yinc=(float)dy/(float)steps; x=x1; y=y1; //shapeDecider is a variable that decides which shape will appear when on the screen for(k=0;k<steps;k++) { glClear(GL_COLOR_BUFFER_BIT); if(shapeDecider%3==0) { teamTheme(); // to display the team theme drawCircle(x,y,r.redc,r.greenc,r.bluec,0);// to draw circle along the line (x1,y1) to (x2,y2) glutSwapBuffers(); drawSquare(-x,-y,r.reds,r.greens,r.blues,0); glutSwapBuffers(); } else if(shapeDecider%3==1) { teamTheme(); glutSwapBuffers(); drawSquare(x,y,r.reds,r.greens,r.blues,0); glutSwapBuffers(); drawCircle(-x,-y,r.redc,r.greenc,r.bluec,0.25); smallDelay(); glutSwapBuffers(); //smallDelay(); } else { teamTheme(); glutSwapBuffers(); drawTriangle(x,y,1,1,1,ang); glutSwapBuffers(); drawCircle(-x,-y,r.redc,r.greenc,r.bluec,0); glutSwapBuffers(); smallDelay(); } x+=xinc; y+=yinc; ang+=100; // this parameter is to rotate the triangle } if(shapeDecider<25) shapeDecider++; else shapeDecider=0; }