annotate UI code/3DboxGL.h @ 52:89944ab3e129 tip

fix oF linker errors ios8
author Robert Tubb <rt300@eecs.qmul.ac.uk>
date Tue, 03 Feb 2015 13:18:23 +0000
parents 3af380769779
children
rev   line source
rt300@0 1 //
rt300@0 2 // 3DboxGL.h
rt300@0 3 // tweakathlon
rt300@0 4 //
rt300@0 5 // Created by Robert Tubb on 17/04/2014.
rt300@0 6 //
rt300@0 7 // same as 3d biox but with better 3d visualisation
rt300@0 8
rt300@0 9 #ifndef __tweakathlon___DboxGL__
rt300@0 10 #define __tweakathlon___DboxGL__
rt300@0 11
rt300@0 12 #include <iostream>
rt300@0 13 #include "3Dbox.h"
rt300@0 14 #include "UIElement.h"
rt300@34 15 #include "algorithms.h"
rt300@0 16
rt300@0 17 //Universal function which sets normals for the triangle meshvoid
rt300@0 18 void setNormals( ofMesh &mesh );
rt300@0 19
rt300@34 20 //float euclideanDistance(vector<float> v1, vector<float> v2);
rt300@0 21
rt300@0 22 class Leap3DBoxGL : public Leap3DBox {
rt300@0 23 public:
rt300@0 24 Leap3DBoxGL(float ax,
rt300@0 25 float ay,
rt300@0 26 float awidth,
rt300@0 27 float aheight,
rt300@0 28 float azx,
rt300@0 29 float azy,
rt300@0 30 const UIProps& props);
rt300@0 31
rt300@0 32 void draw(){
rt300@0 33 if(hidden)return;
rt300@0 34 if(on){
rt300@0 35 ofSetColor(foregroundHi);
rt300@0 36 }else{
rt300@0 37 ofSetColor(foregroundLo);
rt300@0 38
rt300@0 39 }
rt300@0 40 if(inactive){
rt300@0 41 ofSetColor(fgInactive);
rt300@0 42 }
rt300@0 43
rt300@0 44
rt300@0 45
rt300@0 46 ofPushMatrix();
rt300@0 47 ofDisableAlphaBlending();
rt300@0 48 ofEnableDepthTest();
rt300@0 49 // move to correct pos
rt300@0 50
rt300@0 51 ofTranslate( x+width/2, y+height/2, camTrans);
rt300@0 52 ofRotate( angleX, 1, 0, 0 );
rt300@0 53 ofRotate( angleY, 0, 1, 0 );
rt300@0 54
rt300@25 55
rt300@0 56 ofSetColor(foregroundHi);
rt300@0 57 boxMesh.draw();
rt300@0 58
rt300@0 59 // draw indicators
rt300@0 60 drawIndicator();
rt300@0 61 ofPopMatrix();
rt300@0 62
rt300@0 63 drawLabels();
rt300@0 64 };
rt300@0 65
rt300@0 66 void drawIndicator(){
rt300@0 67
rt300@0 68 if (hintShowing && (hintZ > zVal)){
rt300@0 69 hintColor = calculateHintColor();
rt300@26 70 draw3DCrossHairs(hintX, hintY, hintZ,hintColor, true);
rt300@0 71
rt300@0 72 }
rt300@0 73
rt300@0 74 // draw indicator
rt300@0 75 draw3DCrossHairs(xVal,yVal,zVal, indicatorColor);
rt300@0 76 // put light in indicateor
rt300@0 77 //
rt300@0 78
rt300@0 79
rt300@0 80 if (hintShowing && hintZ <= zVal){
rt300@0 81 hintColor = calculateHintColor();
rt300@26 82 draw3DCrossHairs(hintX, hintY, hintZ,hintColor, true);
rt300@0 83
rt300@0 84 }
rt300@0 85 }
rt300@26 86 void draw3DCrossHairs(float x , float y, float z, ofColor c, bool isHint = false){
rt300@0 87
rt300@0 88 float ix = x*width - width/2;
rt300@0 89 float iy = (1-y)*width - width/2;
rt300@0 90 float iz = (1-z)*width - width/2;
rt300@0 91
rt300@0 92 float left = - width/2;
rt300@0 93 float bot = width/2;
rt300@0 94 float front = width/2;
rt300@0 95 //
rt300@0 96 ofSetColor(c);
rt300@0 97 ofSetLineWidth(2.);
rt300@0 98 // line to bottom
rt300@0 99 ofLine(ix,iy,iz,ix,bot,iz);
rt300@0 100 // line to left
rt300@0 101 ofLine(ix,iy,iz,left,iy,iz);
rt300@0 102
rt300@0 103 //blob
rt300@26 104 drawIndicatorBlob(ix,iy,iz,c, isHint);
rt300@23 105 // line to front (a bit wierde?)
rt300@0 106 ofLine(ix,iy,iz,ix,iy,front);
rt300@0 107
rt300@0 108
rt300@0 109
rt300@0 110 }
rt300@26 111 virtual void drawIndicatorBlob( float x, float y, float z, ofColor c, bool isHint = false){
rt300@23 112 ofSetColor(c);
rt300@23 113 ofDrawIcoSphere(x,y,z,12);
rt300@23 114 }
rt300@0 115 ofColor calculateHintColor(){
rt300@0 116
rt300@0 117
rt300@0 118 // this is all duplicate code and may change so a bit bad >:(
rt300@0 119 float dist = sqrt( 127.*127.*((xVal - hintX)*(xVal - hintX) + (yVal - hintY)*(yVal - hintY) + (zVal - hintZ)*(zVal - hintZ)) );
rt300@0 120
rt300@0 121 auto dimComp = sqrt(3.0);
rt300@0 122 int band = -1;
rt300@0 123 if (dist < TARGET_SCORE_CC_BAND*dimComp){
rt300@0 124
rt300@0 125 band = 1;
rt300@0 126
rt300@0 127 }else if (dist < TARGET_SCORE_CC_BAND*2*dimComp){
rt300@0 128
rt300@0 129 band = 2;
rt300@0 130
rt300@0 131
rt300@0 132 }else if (dist < TARGET_SCORE_CC_BAND*3*dimComp){
rt300@0 133
rt300@0 134 band = 3;
rt300@0 135
rt300@0 136
rt300@0 137 }else if (dist < TARGET_SCORE_CC_BAND*4*dimComp){
rt300@0 138
rt300@0 139 band = 4;
rt300@0 140
rt300@0 141
rt300@0 142 }else if (dist < TARGET_SCORE_CC_BAND*6*dimComp){ // 30
rt300@0 143
rt300@0 144 band = 5;
rt300@0 145
rt300@0 146 }else if (dist < TARGET_SCORE_CC_BAND*9*dimComp){ // 45
rt300@0 147 band = 6;
rt300@0 148
rt300@0 149 }else{
rt300@0 150 band = 7;
rt300@0 151
rt300@0 152 }
rt300@0 153
rt300@0 154
rt300@0 155 ofColor c;
rt300@0 156 if(band == 1){
rt300@0 157 // yellow red blue
rt300@0 158 c = ofColor(255,255,0,255);
rt300@0 159 }else if(band == 2){
rt300@0 160 c = ofColor(255,0,0,255);
rt300@0 161 }else if(band == 3){
rt300@0 162 c = ofColor(45,45,255,255);
rt300@0 163 }else if(band == 4){
rt300@0 164 c = ofColor(0,255,0,255);
rt300@0 165 }else{
rt300@0 166 c = ofColor(150,235,200,255);
rt300@0 167 }
rt300@0 168 return c;
rt300@0 169
rt300@0 170 }
rt300@0 171 void drawCylinders(){
rt300@0 172 ofPushMatrix();
rt300@0 173 ofTranslate( x, y, camTrans);
rt300@0 174 // vertical
rt300@0 175 ofSetColor(0,255,0);
rt300@0 176 ofDrawCylinder(0, 0, 32, 500*yVal);
rt300@0 177
rt300@0 178 // into screen
rt300@0 179 ofSetColor(255,0,0);
rt300@0 180 ofRotate( 90, 1, 0, 0 );
rt300@0 181 ofDrawCylinder(70, 0, 32, 500*zVal);
rt300@0 182 ofRotate( -90, 1, 0, 0 );
rt300@0 183 // l/r horizona
rt300@0 184 ofSetColor(0,0,255);
rt300@0 185 ofRotate( 90, 0, 0, 1 );
rt300@0 186 ofDrawCylinder(70, 300, 32, 500*xVal);
rt300@0 187
rt300@0 188
rt300@0 189 ofPopMatrix();
rt300@0 190 }
rt300@0 191 float valToScreen(float val){
rt300@0 192 float sc;
rt300@0 193 return sc;
rt300@0 194 };
rt300@0 195
rt300@0 196 bool handleMyTouch(int x, int y, touchType ttype, int touchID){
rt300@0 197 static float lastTX = 0.,lastTY = 0.;
rt300@0 198
rt300@0 199
rt300@0 200 if (ttype == TOUCH_MOVED && touchID == 0){
rt300@0 201 float dx = x -lastTX;
rt300@0 202 float dy = y - lastTY;
rt300@0 203
rt300@0 204 angleY += dx/3;
rt300@0 205 angleX += dy/3;
rt300@0 206
rt300@0 207 }
rt300@0 208
rt300@0 209 if (ttype == TOUCH_MOVED && touchID == 1){
rt300@0 210 float dx = x -lastTX;
rt300@0 211 float dy = y - lastTY;
rt300@0 212
rt300@0 213 // adjust light angle?
rt300@0 214 angleY += dx/3;
rt300@0 215 angleX += dy/3;
rt300@0 216
rt300@0 217 }
rt300@0 218
rt300@0 219 //cout << angleX << " : " << angleY << endl;
rt300@0 220
rt300@0 221 lastTX = x;
rt300@0 222 lastTY = y;
rt300@0 223 return true;
rt300@0 224
rt300@0 225 };
rt300@0 226
rt300@32 227
rt300@32 228 void makeTexFace(ofMesh * theMesh, ofPoint LT, ofPoint RT, ofPoint RB, ofPoint LB){
rt300@32 229
rt300@32 230 ofPoint texCoordLT = ofPoint(0, 1.);
rt300@32 231 ofPoint texCoordLB = ofPoint(0, 0);
rt300@32 232 ofPoint texCoordRT = ofPoint(1., 1.);
rt300@32 233 ofPoint texCoordRB = ofPoint(1., 0.);
rt300@32 234
rt300@32 235 theMesh->addVertex(LT);
rt300@32 236 theMesh->addTexCoord(texCoordLT);
rt300@32 237 theMesh->addVertex(LB);
rt300@32 238 theMesh->addTexCoord(texCoordLB);
rt300@32 239 theMesh->addVertex(RB);
rt300@32 240 theMesh->addTexCoord(texCoordRB);
rt300@32 241
rt300@32 242
rt300@32 243
rt300@32 244 theMesh->addVertex(LT);
rt300@32 245 theMesh->addTexCoord(texCoordLT);
rt300@32 246
rt300@32 247 theMesh->addVertex(RB);
rt300@32 248 theMesh->addTexCoord(texCoordRB);
rt300@32 249 theMesh->addVertex(RT);
rt300@32 250 theMesh->addTexCoord(texCoordRT);
rt300@32 251 }
rt300@32 252
rt300@0 253 float angleX;
rt300@0 254 float angleY;
rt300@0 255 float depth;
rt300@0 256 ofMesh boxMesh;
rt300@0 257 float camTrans;
rt300@0 258 ofColor indicatorColor;
rt300@0 259
rt300@0 260 };
rt300@0 261
rt300@24 262 #endif /* defined(__tweakathlon___DboxGL__) */