Mercurial > hg > wabletios
changeset 8:4ea605899aca
Hide controls for supernatant.
author | Robert Tubb <rt300@eecs.qmul.ac.uk> |
---|---|
date | Tue, 14 May 2013 10:34:32 +0100 |
parents | 8584d661c8da |
children | 0e03760cf2d9 |
files | globalForces.h lump.h lump.mm mesh.h mesh.mm scanpath.h scanpath.mm testApp.h testApp.mm |
diffstat | 9 files changed, 212 insertions(+), 28 deletions(-) [+] |
line wrap: on
line diff
--- a/globalForces.h Wed Feb 06 13:48:49 2013 +0000 +++ b/globalForces.h Tue May 14 10:34:32 2013 +0100 @@ -10,6 +10,7 @@ #include "2dvector.h" #include "ofMain.h" +#include "json.h" #include "ofxiPhone.h" #include "ofxiPhoneExtras.h" #include <list> @@ -38,7 +39,7 @@ int exciteShapeX, exciteShapeY; // general params double speedLimit, wallBounce; - double delt; // time step between frames + double delt; // time step between frames not used really double volume; forceTouchPoint* forceTouchPoints;
--- a/lump.h Wed Feb 06 13:48:49 2013 +0000 +++ b/lump.h Tue May 14 10:34:32 2013 +0100 @@ -38,7 +38,8 @@ TwoVector position; TwoVector previousPosition; double totalForceMag; - double size; + //double size; + int myIndexInMesh; int grabID; // which touch is this lump grabbed by? Lump(); // default constructor
--- a/lump.mm Wed Feb 06 13:48:49 2013 +0000 +++ b/lump.mm Tue May 14 10:34:32 2013 +0100 @@ -18,6 +18,7 @@ // default constr Lump::Lump(){ //cout << "constructing a default lump" << endl; + // myIndexInMesh = index; HOW TO GET THIS?? mass = 10.0; inverseMass = 1.0/mass; // not needed - used csquared for force friction = 0.996; @@ -32,7 +33,7 @@ highlighted = false; constrained = false; totalForceMag = 0.0; - size = 3; //sqrt(mass/3.0); + //size = 3; //sqrt(mass/3.0); isInScanPath = false; isScanPathStart = false; isScanPathEnd = false;
--- a/mesh.h Wed Feb 06 13:48:49 2013 +0000 +++ b/mesh.h Tue May 14 10:34:32 2013 +0100 @@ -14,11 +14,12 @@ #include "lump.h" #include "scanpath.h" #include "globalForces.h" - +#include "json.h" class Mesh{ public: - + int dim1, dim2; + bool radial; // tells us if mesh is radial or not // toggles bool syrup; @@ -43,7 +44,8 @@ enum constrainMode { CONSTRAIN_CORNERS, CONSTRAIN_EDGES,CONSTRAIN_EDGES_XY, CONSTRAIN_SINGLE_POINT, CONSTRAIN_SINGLE_POINT_X, CONSTRAIN_SINGLE_POINT_Y, CONSTRAIN_GRAB_REGION,CONSTRAIN_GRAB_REGION_X,CONSTRAIN_GRAB_REGION_Y, CONSTRAIN_ALL_X, CONSTRAIN_ALL_Y}; double GRAB_RANGE; - + enum MeshType {SQUARE_CROSS_MESH, SPIDER_MESH, SPIDER_CROSS_MESH, DROPLET_MESH, LINE_MESH, TRIANGLE_MESH, GROUNDED_LINE_MESH, HOLED_SPIDER_MESH}; + MeshType meshType; // MEMBER FUNCTIONS Mesh(); @@ -107,11 +109,17 @@ void clearScanPath(); void disconnectDraw(); // enables you to draw scanpths anywhere int inscribeScanPath(double ax, double ay); + + // inscribeScanPathFromJson + // called by scanpath.update wavetables double getNextSample(); virtual void update(); - + +// save stuff + Json::Value convertToJsonForSaving(); + protected: int prevLump;
--- a/mesh.mm Wed Feb 06 13:48:49 2013 +0000 +++ b/mesh.mm Tue May 14 10:34:32 2013 +0100 @@ -50,6 +50,28 @@ // interface (called from testApp) /////////// +//-------------------------------------------------------------- +Json::Value Mesh::convertToJsonForSaving(){ + Json::Value jmesh; + + jmesh["meshType"] = meshType; + jmesh["dim1"] = dim1; + jmesh["dim1"] = dim2; + int j = 0; + + for(int i=0;i<lumps.size();i++){ + if(lumps[i].constrained){ + j++; + jmesh["constrainedLumps"][j] = i; + } + } + + // get list of indexes for lumps and springs in scanpath + // iterate over scanpath elements + + return jmesh; + +} //-------------------------------------------------------------- void Mesh::update(){ @@ -127,7 +149,6 @@ } - } //-------------------------------------------------------------- void Mesh::draw(){ @@ -142,7 +163,7 @@ lumps[i].draw(); } - // scanPath.draw(); // uncomment if you want to see the output waveform + } @@ -606,7 +627,10 @@ return -1; } -// +// --------------------------------------------------------------------------------------- + + + void Mesh::hit(double dax, double day,int velocity, GlobalForces::excitationTypes aEType, GlobalForces::excitationShapes aEShape){ // set filter to something low globalForces.homingAmt = 0.0; @@ -743,7 +767,7 @@ /****************************************/ //-------------------------------------------------------------- SquareCrossMesh::SquareCrossMesh(int height, int width): Mesh() { - + meshType = SQUARE_CROSS_MESH; makeComponents(height, width); setLumpPositions(); @@ -1021,6 +1045,8 @@ // SpiderMesh */ /****************************************/ SpiderMesh::SpiderMesh(int aNumSpokes,int aNumRings) : Mesh(){ + meshType = SPIDER_MESH; + numSpokes = aNumSpokes; numRings = aNumRings; @@ -1227,6 +1253,7 @@ /****************************************/ //-------------------------------------------------------------- HoledSpiderMesh::HoledSpiderMesh(int aNumSpokes,int aNumRings) : Mesh(){ + meshType = HOLED_SPIDER_MESH; numSpokes = aNumSpokes; numRings = aNumRings; radial = true; @@ -1404,6 +1431,7 @@ /****************************************/ //-------------------------------------------------------------- SpiderCrossMesh::SpiderCrossMesh(int aNumSpokes,int aNumRings) : Mesh(){ + meshType = SPIDER_CROSS_MESH; numSpokes = aNumSpokes; numRings = aNumRings; radial = true; @@ -1603,6 +1631,7 @@ /****************************************/ LineMesh::LineMesh(int aNumSegments) : Mesh(){ + meshType = LINE_MESH; numSegments = aNumSegments; radial = false; @@ -1692,6 +1721,7 @@ /****************************************/ GroundedLineMesh::GroundedLineMesh(int aNumSegments) : Mesh(){ + meshType = GROUNDED_LINE_MESH; numSegments = aNumSegments; radial = false; makeComponents(aNumSegments, 0); @@ -1807,7 +1837,7 @@ /****************************************/ // more of a balloon really - filled with compressible gas DropletMesh::DropletMesh(int aNumSegments) : Mesh(){ - + meshType = DROPLET_MESH; restArea = 1.0; radial = true; numSegments = aNumSegments; @@ -1969,6 +1999,7 @@ /****************************************/ //-------------------------------------------------------------- TriangleMesh::TriangleMesh(int height, int width): Mesh() { + meshType = TRIANGLE_MESH; radial = false; makeComponents(height, width);
--- a/scanpath.h Wed Feb 06 13:48:49 2013 +0000 +++ b/scanpath.h Tue May 14 10:34:32 2013 +0100 @@ -11,6 +11,7 @@ #define _SCANPATHH #include "lump.h" #include "spring.h" +#include "json.h" #include <vector> struct Element{ Lump * eLump; @@ -77,9 +78,12 @@ // redone stuff void initWavetables(); void addElement(Lump* const aLump, Spring * const aSpring); - + Lump * getLump(int index); + Spring * getSpring(int index); + void updateWavetables(); + Json::Value convertToJsonForSaving(); }; #endif \ No newline at end of file
--- a/scanpath.mm Wed Feb 06 13:48:49 2013 +0000 +++ b/scanpath.mm Tue May 14 10:34:32 2013 +0100 @@ -80,7 +80,7 @@ int rightsampnum = 0; float sampscale = 0.0, prevsampscale = 0.0, interp = 0.0; - ofSetColor(0, 0, 0); + ofSetColor(256, 0, 0); double step = double(numElements)/width; // how much we are stepping thru wave per pixel for(int i = 0; i < width; i++){ @@ -156,6 +156,26 @@ } //---------------------------------------------------------------- +Lump * ScanPath::getLump(int index){ + if(index < pathElements.size()){ + return pathElements[index].eLump; + }else{ + cerr << "bad scanpath::getLump index\n"; + return NULL; + } + +} +//---------------------------------------------------------------- +Spring * ScanPath::getSpring(int index){ + if(index < pathElements.size()){ + return pathElements[index].eSpring; + }else{ + cerr << "bad scanpath::getSpring index\n"; + return NULL; + } +} + +//---------------------------------------------------------------- void ScanPath::updateWavetables(){ // swap old , new double * temp; @@ -182,7 +202,7 @@ for(int i = 0; i < numElements; i++){ // double check - wavetableUpdate[i] = pathElements[i].eLump->scanRadialDisplacement(); + wavetableUpdate[i] = pathElements[i].eLump->scanDisplacement(); } @@ -386,4 +406,18 @@ return sample; } -//---------------------------------------------------------------- \ No newline at end of file +//---------------------------------------------------------------- + +Json::Value ScanPath::convertToJsonForSaving(){ + Json::Value jscanpath; + jscanpath["numElements"] = numElements; + // shiit. pointers mean nothing. the lups won't know which index they are. + return jscanpath; +} + +//---------------------------------------------------------------- + +//---------------------------------------------------------------- + +//---------------------------------------------------------------- +
--- a/testApp.h Wed Feb 06 13:48:49 2013 +0000 +++ b/testApp.h Tue May 14 10:34:32 2013 +0100 @@ -6,6 +6,8 @@ #include "ofMain.h" #include "ofxiPhone.h" #include "ofxiPhoneExtras.h" +#include "ofxiPhoneExternalDisplay.h" +#include "ofxiPhoneAppDelegate.h" #include "2dvector.h" #include "lump.h" @@ -19,6 +21,8 @@ #include "globalForces.h" #include "globalUI.h" +#include "json.h" + #define SAMPLE_RATE 44100 // listen on port 12345 #define INPORT 12345 @@ -31,12 +35,13 @@ -class testApp : public ofxiPhoneApp { +class testApp : public ofxiPhoneApp, public ofxiPhoneExternalDisplay{ public: int timesOpened; bool audioOn; bool drawingOn; + bool controlsShowing; bool paused; //bool inscribeScanPathMode; @@ -86,7 +91,7 @@ void restartAudioStream(); void audioRequested (float * input, int bufferSize, int nChannels); void audioReceived(float * input, int bufferSize, int nChannels); - + //void deviceOrientationChanged(int newOrientation); void handleMessages(); void drawMessages(); @@ -94,6 +99,10 @@ void regenerateMesh(string meshType, int dim1 = 3, int dim2 = 3); void deleteMesh(); + Json::Value convertToJsonForSaving(); + void savePreset(); + void constructPresetFromJson(Json::Value presetJson); + ofxOscReceiver receiver; ofxOscSender sender; ofTrueTypeFont font; @@ -111,8 +120,10 @@ ofxUICanvas *guiL; ofxUICanvas *guiR; + ofxUICanvas *guiSH; void guiLEvent(ofxUIEventArgs &e); void guiREvent(ofxUIEventArgs &e); + void guiSHEvent(ofxUIEventArgs &e); void setupGui(); void drawSidePanels();
--- a/testApp.mm Wed Feb 06 13:48:49 2013 +0000 +++ b/testApp.mm Tue May 14 10:34:32 2013 +0100 @@ -42,18 +42,17 @@ floating scan path, with interpolation band limited touch points (invisible springs connecting to mesh?) - - - + */ extern GlobalForces globalForces; extern GlobalUI globalUI; extern ScanPath scanPath; //-------------------------------------------------------------- -void testApp::setup(){ +void testApp::setup(){ + ofxiPhoneSetOrientation( OFXIPHONE_ORIENTATION_LANDSCAPE_RIGHT ); theMesh = NULL; - ofxiPhoneSetOrientation(OFXIPHONE_ORIENTATION_LANDSCAPE_RIGHT); + ofxAccelerometer.setup(); // listen on the given port @@ -99,9 +98,44 @@ paused = false; audioOn = true; + + ofxiPhoneExternalDisplay::mirrorOn(); + + + //ofxiPhoneSetOrientation(OFXIPHONE_ORIENTATION_LANDSCAPE_LEFT); + + [ofxiPhoneGetGLView() updateDimensions]; + + + } - - +Json::Value testApp::convertToJsonForSaving(){ + Json::Value root; + + root["pitch"] = pitch; // + + + // pitch; + + // globalForces.convertToJsonForSaving(); + // root["mesh"] = mesh.convertToJsonForSaving(); + root["mesh"] = theMesh->convertToJsonForSaving(); + + return root; +} +void testApp::savePreset(){ + convertToJsonForSaving(); + //save json to file + +} +void testApp::constructPresetFromJson(Json::Value presetJson){ + + // construct mesh with right type and size + // impose saved constraints + // make saved scanpath + // recall global settings + pitch = presetJson["pitch"].asDouble(); +} //-------------------------------------------------------------- //-------------------------------------------------------------- // App running stuff @@ -133,7 +167,13 @@ } handleMessages(); // !?!?? - + if(ofxiPhoneExternalDisplay::isExternalScreenConnected()){ + if(!ofxiPhoneExternalDisplay::isMirroring()){ + ofxiPhoneExternalDisplay::mirrorOn(); + //printf("turned on Mirroring!\n"); + } + } + } //-------------------------------------------------------------- @@ -142,7 +182,11 @@ if(theMesh != NULL) theMesh->draw(); } - drawSidePanels(); + if(controlsShowing){ + drawSidePanels(); + }else{ + scanPath.draw(); // uncomment if you want to see the output waveform + } } //-------------------------------------------------------------- // background for UI @@ -1206,7 +1250,7 @@ // RIGHT GUI ----------------------- - guiR = new ofxUICanvas(ofGetWidth()-128, 0, 128, ofGetHeight()); + guiR = new ofxUICanvas(ofGetWidth()-128, 0, 128, ofGetHeight()-64); guiR->addSpacer(length-xInit, 2); @@ -1242,6 +1286,14 @@ //guiR->loadSettings(ofxiPhoneGetDocumentsDirectory() + "guiSettings.xml"); radio->activateToggle("GRAB"); + // show hide ctrls + guiSH = new ofxUICanvas(ofGetWidth()-128, ofGetHeight()-64, 128, 64); + + + guiSH->addSpacer(length-xInit, 2); + guiSH->addToggle("CTRLS", false, dim, dim); + ofAddListener(guiSH->newGUIEvent, this, &testApp::guiSHEvent); + } //-------------------------------------------------------------- void testApp::UIcallBack(int buttID){ @@ -1249,6 +1301,29 @@ } //-------------------------------------------------------------- +void testApp::guiSHEvent(ofxUIEventArgs &e) +{ + if(e.widget->getName() == "CTRLS"){ + // ???? + + cout << ((ofxUIButton *)e.widget)->getValue(); + + if( ((ofxUIButton *)e.widget)->getValue() == 0) { + cout << "CTRLS oofff"; + guiR->setVisible(false); + guiL->setVisible(false); + controlsShowing = false; + }else{ + cout << "CTRLS onnn"; + guiR->setVisible(true); + guiL->setVisible(true); + controlsShowing = true; + } + + } +} + +//-------------------------------------------------------------- void testApp::guiREvent(ofxUIEventArgs &e) { if(e.widget->getName() == "TOUCH MODE") @@ -1347,3 +1422,21 @@ } + +//-------------------------------------------------------------- +/* +void testApp::deviceOrientationChanged(int newOrientation){ + + cout << "orientation: " << newOrientation; + + if(newOrientation == 4){ + ofxiPhoneSetOrientation( OF_ORIENTATION_DEFAULT ); + + }else if(newOrientation == 3){ + ofxiPhoneSetOrientation( OF_ORIENTATION_90_LEFT ); + }else if(newOrientation == 3){ + ofxiPhoneSetOrientation( OF_ORIENTATION_90_LEFT ); + } + +} +*/