diff UI code/3DboxGL.h @ 0:a223551fdc1f

First commit - copy from tweakathlon.
author Robert Tubb <rt300@eecs.qmul.ac.uk>
date Fri, 10 Oct 2014 11:46:42 +0100
parents
children 055e0c43afe5
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/UI code/3DboxGL.h	Fri Oct 10 11:46:42 2014 +0100
@@ -0,0 +1,232 @@
+//
+//  3DboxGL.h
+//  tweakathlon
+//
+//  Created by Robert Tubb on 17/04/2014.
+//
+// same as 3d biox but with better 3d visualisation
+
+#ifndef __tweakathlon___DboxGL__
+#define __tweakathlon___DboxGL__
+
+#include <iostream>
+#include "3Dbox.h"
+#include "UIElement.h"
+
+#endif /* defined(__tweakathlon___DboxGL__) */
+
+//Universal function which sets normals for the triangle meshvoid
+void setNormals( ofMesh &mesh );
+
+float euclideanDistance(vector<float> v1, vector<float> v2);
+
+class Leap3DBoxGL : public Leap3DBox {
+public:
+    Leap3DBoxGL(float ax,
+              float ay,
+              float awidth,
+              float aheight,
+              float azx,
+              float azy,
+              const UIProps& props);
+    
+    void draw(){
+        if(hidden)return;
+        if(on){
+            ofSetColor(foregroundHi);
+        }else{
+            ofSetColor(foregroundLo);
+            
+        }
+        if(inactive){
+            ofSetColor(fgInactive);
+        }
+
+        
+        
+        ofPushMatrix();
+        ofDisableAlphaBlending();
+        ofEnableDepthTest();
+        // move to correct pos
+        
+        ofTranslate( x+width/2, y+height/2, camTrans);
+        ofRotate( angleX, 1, 0, 0 );
+        ofRotate( angleY, 0, 1, 0 );
+
+        setNormals(boxMesh);
+        ofSetColor(foregroundHi);
+        boxMesh.draw();
+        
+                 // draw indicators
+        drawIndicator();
+        ofPopMatrix();
+        
+        drawLabels();
+    };
+    
+    void drawIndicator(){
+
+        if (hintShowing && (hintZ > zVal)){
+            hintColor = calculateHintColor();
+            draw3DCrossHairs(hintX, hintY, hintZ,hintColor);
+            
+        }
+        
+        // draw indicator
+        draw3DCrossHairs(xVal,yVal,zVal, indicatorColor);
+        // put light in indicateor
+        //
+        
+        
+        if (hintShowing && hintZ <= zVal){
+            hintColor = calculateHintColor();
+            draw3DCrossHairs(hintX, hintY, hintZ,hintColor);
+            
+        }
+    }
+    void draw3DCrossHairs(float x , float y, float z, ofColor c){
+        
+        float ix = x*width - width/2;
+        float iy = (1-y)*width - width/2;
+        float iz = (1-z)*width - width/2;
+        
+        float left = - width/2;
+        float bot = width/2;
+        float front = width/2;
+        //
+        ofSetColor(c);
+        ofSetLineWidth(2.);
+        // line to bottom
+        ofLine(ix,iy,iz,ix,bot,iz);
+        // line to left
+        ofLine(ix,iy,iz,left,iy,iz);
+
+        //blob
+        ofDrawIcoSphere(ix,iy,iz,12);
+        // line to front (a bit wierd?)
+        ofLine(ix,iy,iz,ix,iy,front);
+        
+
+        
+    }
+    ofColor calculateHintColor(){
+
+        
+        // this is all duplicate code and may change so a bit bad >:(
+        float dist = sqrt( 127.*127.*((xVal - hintX)*(xVal - hintX) + (yVal - hintY)*(yVal - hintY) + (zVal - hintZ)*(zVal - hintZ)) );
+        
+        auto dimComp = sqrt(3.0);
+        int band = -1;
+        if (dist < TARGET_SCORE_CC_BAND*dimComp){
+
+            band = 1;
+
+        }else if (dist < TARGET_SCORE_CC_BAND*2*dimComp){
+
+            band = 2;
+
+            
+        }else if (dist < TARGET_SCORE_CC_BAND*3*dimComp){
+
+            band = 3;
+
+            
+        }else if (dist < TARGET_SCORE_CC_BAND*4*dimComp){
+
+            band = 4;
+
+            
+        }else if (dist < TARGET_SCORE_CC_BAND*6*dimComp){ // 30
+
+            band = 5;
+            
+        }else if (dist < TARGET_SCORE_CC_BAND*9*dimComp){ // 45
+            band = 6;
+            
+        }else{
+            band = 7;
+ 
+        }
+
+        
+        ofColor c;
+        if(band == 1){
+            // yellow red blue
+            c = ofColor(255,255,0,255);
+        }else if(band == 2){
+            c = ofColor(255,0,0,255);
+        }else if(band == 3){
+            c = ofColor(45,45,255,255);
+        }else if(band == 4){
+            c = ofColor(0,255,0,255);
+        }else{
+            c = ofColor(150,235,200,255);
+        }
+        return c;
+        
+    }
+    void drawCylinders(){
+        ofPushMatrix();
+        ofTranslate( x, y, camTrans);
+        // vertical
+        ofSetColor(0,255,0);
+        ofDrawCylinder(0, 0, 32, 500*yVal);
+        
+        // into screen
+        ofSetColor(255,0,0);
+        ofRotate( 90, 1, 0, 0 );
+        ofDrawCylinder(70, 0, 32, 500*zVal);
+        ofRotate( -90, 1, 0, 0 );
+        // l/r horizona
+        ofSetColor(0,0,255);
+        ofRotate( 90, 0, 0, 1 );
+        ofDrawCylinder(70, 300, 32, 500*xVal);
+        
+        
+        ofPopMatrix();
+    }
+    float valToScreen(float val){
+        float sc;
+        return sc;
+    };
+    
+    bool handleMyTouch(int x, int y, touchType ttype, int touchID){
+        static float lastTX = 0.,lastTY = 0.;
+
+
+        if (ttype == TOUCH_MOVED && touchID == 0){
+            float dx = x -lastTX;
+            float dy = y - lastTY;
+            
+            angleY += dx/3;
+            angleX += dy/3;
+
+        }
+        
+        if (ttype == TOUCH_MOVED && touchID == 1){
+            float dx = x -lastTX;
+            float dy = y - lastTY;
+            
+            // adjust light angle?
+            angleY += dx/3;
+            angleX += dy/3;
+            
+        }
+        
+        //cout << angleX << " : " << angleY << endl;
+        
+        lastTX = x;
+        lastTY = y;
+        return true;
+
+    };
+    
+    float angleX;
+    float angleY;
+    float depth;
+    ofMesh boxMesh;
+    float camTrans;
+    ofColor indicatorColor;
+    
+};
+