changeset 25:8eb530e0601b

textured hand moves correctly to 6 midi params.
author Robert Tubb <rt300@eecs.qmul.ac.uk>
date Tue, 28 Oct 2014 15:19:22 +0000
parents b339acf124df
children 8d7ae43b2edd
files MessageOrganiser.mm UI code/3DboxGL.h UI code/3DboxGL.mm UI code/6Dbox.h UI code/6Dbox.mm UI code/UIElement.h main.mm testApp.mm
diffstat 8 files changed, 157 insertions(+), 100 deletions(-) [+]
line wrap: on
line diff
--- a/MessageOrganiser.mm	Mon Oct 27 17:40:05 2014 +0000
+++ b/MessageOrganiser.mm	Tue Oct 28 15:19:22 2014 +0000
@@ -103,6 +103,9 @@
     }else{
         cout << "ERROR ERROR: ui type not handled by setUIToParam!" << endl;
     }
+    if (box6D->isShowing()){
+        box6D->setValueAndScale(index, value);
+    }
     
 };
 
--- a/UI code/3DboxGL.h	Mon Oct 27 17:40:05 2014 +0000
+++ b/UI code/3DboxGL.h	Tue Oct 28 15:19:22 2014 +0000
@@ -52,7 +52,7 @@
         ofRotate( angleX, 1, 0, 0 );
         ofRotate( angleY, 0, 1, 0 );
 
-        setNormals(boxMesh);
+        
         ofSetColor(foregroundHi);
         boxMesh.draw();
         
--- a/UI code/3DboxGL.mm	Mon Oct 27 17:40:05 2014 +0000
+++ b/UI code/3DboxGL.mm	Tue Oct 28 15:19:22 2014 +0000
@@ -26,7 +26,7 @@
     depth = width; // its a cube
     
     // where is the camera
-    camTrans = 0;
+    camTrans = 200;
     
     // cube is centred on 0,0,0
     float I = width/2;
@@ -103,6 +103,7 @@
 //    boxMesh.addVertex(lbr);
     
     boxMesh.setupIndicesAuto();
+    setNormals(boxMesh);
 }
 
 
--- a/UI code/6Dbox.h	Mon Oct 27 17:40:05 2014 +0000
+++ b/UI code/6Dbox.h	Tue Oct 28 15:19:22 2014 +0000
@@ -26,11 +26,15 @@
     void drawIndicatorBlob(float x, float y, float z, ofColor c);
     void draw6DOFIndicatorBlob(float x, float y, float z, ofColor c, float r, float p, float yaw);
     void setTexture(ofImage* img);
+    void setValue(int index, int value);
+    void setValueAndScale(int index, int value);
 private:
     float hw, hh, hl, scale;
+    float minAngVal, maxAngVal;
     void setUpHandMesh();
-    
-    float roll, pitch, yaw;
+    void setUpThumb(ofPoint baseTR, ofPoint baseBR);
+    void makeTexFace(ofPoint LT, ofPoint RT, ofPoint  RB, ofPoint LB);
+    float rollVal, pitchVal, yawVal;
     
     ofMesh handMesh;
     ofImage* texImg;
--- a/UI code/6Dbox.mm	Mon Oct 27 17:40:05 2014 +0000
+++ b/UI code/6Dbox.mm	Tue Oct 28 15:19:22 2014 +0000
@@ -17,20 +17,20 @@
 Leap3DBoxGL(ax,ay,awidth, aheight, azx, azy, props)
 {
 
-    roll = 0.0;
-    pitch = 0.0;
-    yaw = 0.0;
-    
+    rollVal = 0.0;
+    pitchVal = 0.0;
+    yawVal = 0.0;
+
     // set up hand mesh
     // width 0.5
     // length 1
     // height 0.25
     hw = 0.5;
-    hh = 0.25;
+    hh = 0.15;
     hl = 1.0;
-    scale = 0.1;
+    scale = 40;
     
-    string fname = ofFilePath::getAbsolutePath(ofToDataPath("perf.jpeg"));
+    string fname = ofFilePath::getAbsolutePath(ofToDataPath("marble.jpeg"));
     ofFile f = ofFile(fname);
     defaultImage.loadImage(fname);
     setTexture(&defaultImage);
@@ -38,101 +38,141 @@
     
 }
 
+void Leap6DBox::setValue(int index, int value){
+    if (index == 0){
+        
+    }
+}
+
+void Leap6DBox::setValueAndScale(int which, int val){
+    
+    
+    if(which == 0)      xVal =  (val - minVal)/(maxVal - minVal);
+    if(which == 1)      yVal =  (val - minVal)/(maxVal - minVal);
+    if(which == 2)      zVal =  (val - minVal)/(maxVal - minVal);
+    // angles
+    
+    if(which == 3)      rollVal =  57.3*  (2.0*(val - minVal)/(maxVal - minVal) - 1.0);
+    if(which == 4)      pitchVal = 57.3*  (2.0*(val - minVal)/(maxVal - minVal) - 1.0);
+    if(which == 5)      yawVal =   57.3*  (2.0*(val - minVal)/(maxVal - minVal) - 1.0);
+}
+
+void Leap6DBox::makeTexFace(ofPoint LT, ofPoint RT, ofPoint  RB, ofPoint LB){
+    
+    ofPoint texCoordLT = ofPoint(0, 0.5);
+    ofPoint texCoordLB = ofPoint(0, 0);
+    ofPoint texCoordRT = ofPoint(0.5, 0.5);
+    ofPoint texCoordRB = ofPoint(0.5, 0);
+    
+    handMesh.addVertex(LT);
+    handMesh.addTexCoord(texCoordLT);
+    handMesh.addVertex(LB);
+    handMesh.addTexCoord(texCoordLB);
+    handMesh.addVertex(RB);
+    handMesh.addTexCoord(texCoordRB);
+
+    
+    
+    handMesh.addVertex(LT);
+    handMesh.addTexCoord(texCoordLT);
+
+    handMesh.addVertex(RB);
+    handMesh.addTexCoord(texCoordRB);
+    handMesh.addVertex(RT);
+    handMesh.addTexCoord(texCoordRT);
+}
 void Leap6DBox::setUpHandMesh(){
-    ofPoint rtr = ofPoint(hw, hh, hl);
-    ofPoint ltr = ofPoint(-hw, hh, hl);
-    ofPoint rbr = ofPoint(hw, -hh, hl);
-    ofPoint rtf = ofPoint(hw, hh, -hl);
-    ofPoint lbr = ofPoint(-hw, -hh, hl);
-    ofPoint rbf = ofPoint(hw, -hh, -hl);
-    ofPoint lbf = ofPoint(-hw, -hh, -hl);
-    ofPoint ltf = ofPoint(-hw, hh, -hl);
+    ofPoint rtr = ofPoint(hw, hh, -hl);
+    ofPoint ltr = ofPoint(-hw, hh, -hl);
+    ofPoint rbr = ofPoint(hw, -hh, -hl);
+    ofPoint rtf = ofPoint(hw, hh, hl);
+    ofPoint lbr = ofPoint(-hw, -hh, -hl);q
+    ofPoint rbf = ofPoint(hw, -hh, hl);
+    ofPoint lbf = ofPoint(-hw, -hh, hl);
+    ofPoint ltf = ofPoint(-hw, hh, hl);
  
     int imageWidth = 259;
     int imageHeight = 254;
-    
-    ofPoint texCoordLT = ofPoint(0, 0);
-    ofPoint texCoordLB = ofPoint(0, imageHeight);
-    ofPoint texCoordRT = ofPoint(imageWidth, 0);
-    ofPoint texCoordRB = ofPoint(imageWidth, imageHeight);
-    
-    
-    // now build faces
-    // rear
-    // now build faces
-    // rear
-    handMesh.addVertex(ltr);
-    handMesh.addTexCoord(texCoordLT);
-    
-    handMesh.addVertex(rtr);
-    handMesh.addTexCoord(texCoordRT);
-    handMesh.addVertex(rbr);
-    handMesh.addTexCoord(texCoordRB);
-    
-    handMesh.addVertex(ltr);
-    handMesh.addTexCoord(texCoordLT);
-    handMesh.addVertex(rbr);
-    handMesh.addTexCoord(texCoordRB);
-    handMesh.addVertex(lbr);
-    handMesh.addTexCoord(texCoordLB);
+
+    // back
+    makeTexFace(ltr, rtr, rbr, lbr);
     
     // left
-    handMesh.addVertex(ltf);
-    handMesh.addVertex(ltr);
-    handMesh.addVertex(lbr);
+    makeTexFace(ltr,ltf, lbf, lbr);
     
-    handMesh.addVertex(ltf);
-    handMesh.addVertex(lbr);
-    handMesh.addVertex(lbf);
+    // front
+    makeTexFace(ltf, rtf, rbf, lbf);
+    
+    // right
+    makeTexFace(rtf,rtr, rbr, rbf);
+    
+    //top
+    makeTexFace(ltr, rtr, rtf, ltf);
     
     // bottom
-    handMesh.addVertex(lbf);
-    handMesh.addVertex(lbr);
-    handMesh.addVertex(rbr);
+    makeTexFace(lbf, rbf, rbr, lbr);
     
-    handMesh.addVertex(lbf);
-    handMesh.addVertex(rbr);
-    handMesh.addVertex(rbf);
+    setUpThumb(ltf, lbf);
+  
+    handMesh.setupIndicesAuto();
+    setNormals(handMesh);
+}
+void Leap6DBox::setUpThumb(ofPoint baseTR, ofPoint baseBR){
+    // 3 triangles
 
+    ofPoint baseTL = baseTR;
+    ofPoint baseBL = baseBR;
+    baseTL.z -= 0.5*hl;
+    baseBL.z -= 0.5*hl;
+    ofPoint tip = baseBL;
+    tip.x -= hw;
+    tip.y += hh;
+    
+    
+    ofPoint texCoordLT = ofPoint(0, 0.5);
+    ofPoint texCoordLB = ofPoint(0, 0);
+    ofPoint texCoordRT = ofPoint(0.5, 0.5);
+    ofPoint texCoordRB = ofPoint(0.5, 0);
+    
+    // front
+    handMesh.addVertex(baseTR);
+    handMesh.addTexCoord(texCoordLT);
+    handMesh.addVertex(tip);
+    handMesh.addTexCoord(texCoordRB);
+    handMesh.addVertex(baseBR);
+    handMesh.addTexCoord(texCoordLB);
+
+    
     // top
-    handMesh.addVertex(ltf);
-    handMesh.addVertex(ltr);
-    handMesh.addVertex(rtf);
+
+    handMesh.addVertex(baseTL);
+    handMesh.addTexCoord(texCoordLB);
+    handMesh.addVertex(tip);
+    handMesh.addTexCoord(texCoordRB);
+    handMesh.addVertex(baseTR);
+    handMesh.addTexCoord(texCoordLT);
+
+    // back
+    handMesh.addVertex(baseTL);
+    handMesh.addTexCoord(texCoordLT);
+    handMesh.addVertex(baseBL);
+    handMesh.addTexCoord(texCoordLB);
+    handMesh.addVertex(tip);
+    handMesh.addTexCoord(texCoordRB);
+
+
+    // left
+    handMesh.addVertex(baseBL);
+    handMesh.addTexCoord(texCoordLT);
+    handMesh.addVertex(baseBR);
+    handMesh.addTexCoord(texCoordLB);
+    handMesh.addVertex(tip);
+    handMesh.addTexCoord(texCoordRB);
+
+
     
-    handMesh.addVertex(ltr);
-    handMesh.addVertex(rtr);
-    handMesh.addVertex(rtf);
-    
-    // right
-    handMesh.addVertex(rbf);
-    handMesh.addVertex(rtf);
-    handMesh.addVertex(rbr);
-    
-    handMesh.addVertex(rtf);
-    handMesh.addVertex(rtr);
-    handMesh.addVertex(rbr);
- 
-    // front
-    handMesh.addVertex(ltf);
-    handMesh.addTexCoord(texCoordLT);
-    
-    handMesh.addVertex(rtf);
-    handMesh.addTexCoord(texCoordRT);
-    handMesh.addVertex(rbf);
-    handMesh.addTexCoord(texCoordRB);
-    
-    handMesh.addVertex(ltf);
-    handMesh.addTexCoord(texCoordLT);
-    handMesh.addVertex(rbf);
-    handMesh.addTexCoord(texCoordRB);
-    handMesh.addVertex(lbf);
-    handMesh.addTexCoord(texCoordLB);
-    // TODO now make triange thumb
-    
-    
-    handMesh.setupIndicesAuto();
+
 }
-
 void Leap6DBox::setTexture(ofImage* img){
     texImg = img;
     
@@ -140,7 +180,7 @@
 }
 
 void Leap6DBox::drawIndicatorBlob(float x, float y, float z, ofColor c){
-    draw6DOFIndicatorBlob(x, y, z, c, roll, pitch, yaw);
+    draw6DOFIndicatorBlob(x, y, z, c, rollVal, pitchVal, yawVal);
 }
 
 void Leap6DBox::draw6DOFIndicatorBlob(float x, float y, float z, ofColor c, float r, float p, float yaw){
@@ -151,15 +191,18 @@
     static ofMatrix4x4 m;
     static ofMatrix4x4 rot;
 	m.makeScaleMatrix(scale,scale,scale);
-    rot.makeRotationMatrix(roll, fwd, pitch, right, yaw, up);
+    rot.makeRotationMatrix(rollVal, fwd, pitchVal, right, yawVal, up);
 	m.translate(x,y,z);
     
     ofPushMatrix();
     ofMultMatrix(m);
     ofMultMatrix(rot);
+    
+    ofSetColor(255,255,255);
     // render
     (*texImg).bind();
-    boxMesh.draw();
+    
+    handMesh.draw();
     (*texImg).unbind();
     ofPopMatrix();
     
--- a/UI code/UIElement.h	Mon Oct 27 17:40:05 2014 +0000
+++ b/UI code/UIElement.h	Tue Oct 28 15:19:22 2014 +0000
@@ -60,6 +60,9 @@
         on = true;
     
     };
+    bool isShowing(){
+        return !hidden;
+    }
     bool touch(int x, int y, touchType ttype, int touchID);
     
     virtual void addHandler(UICallbackFunction handlerFunction, int paramID) // virtual?
--- a/main.mm	Mon Oct 27 17:40:05 2014 +0000
+++ b/main.mm	Tue Oct 28 15:19:22 2014 +0000
@@ -5,9 +5,10 @@
 
 int main(){
     ofAppiOSWindow * window = new ofAppiOSWindow();
-    window->enableHardwareOrientation();
-    window->enableOrientationAnimation();
+    //window->enableHardwareOrientation();
+    //window->enableOrientationAnimation();
     window->enableAntiAliasing(4);
+    window->enableDepthBuffer();
 	window->enableRetina();
     
     ofSeedRandom();
--- a/testApp.mm	Mon Oct 27 17:40:05 2014 +0000
+++ b/testApp.mm	Tue Oct 28 15:19:22 2014 +0000
@@ -38,7 +38,8 @@
     ofEnableSeparateSpecularLight();
     
     ofEnableDepthTest();
-    ofEnableAlphaBlending();
+    glEnable(GL_DEPTH_TEST);
+//    ofEnableAlphaBlending();
 
 
     //--------------------------------------
@@ -52,7 +53,7 @@
     
 	ofSoundStreamSetup(2, 2, this, 44100, ofxPd::blockSize()*ticksPerBuffer, 3);
     
-    if(false){ // force start
+    if(true){ // force start
         startTheExpTests();
     }else{
         
@@ -261,7 +262,8 @@
     trainingMessageOrganiser.setControlPanel(controlPanel);
     expMessageOrganiser.setControlPanel(controlPanel);
     controlPanel->showBorder(true);
-
+    controlPanel->hide();
+    
     Leap6DBox * box = new Leap6DBox(300 , 210 , (*props).XYsize*0.75,(*props).XYsize*0.75,150,50, *props);
     searchMessageOrganiser.setBox(box);
     trainingMessageOrganiser.setBox(box);