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@0
|
15
|
rt300@0
|
16 #endif /* defined(__tweakathlon___DboxGL__) */
|
rt300@0
|
17
|
rt300@0
|
18 //Universal function which sets normals for the triangle meshvoid
|
rt300@0
|
19 void setNormals( ofMesh &mesh );
|
rt300@0
|
20
|
rt300@0
|
21 float euclideanDistance(vector<float> v1, vector<float> v2);
|
rt300@0
|
22
|
rt300@0
|
23 class Leap3DBoxGL : public Leap3DBox {
|
rt300@0
|
24 public:
|
rt300@0
|
25 Leap3DBoxGL(float ax,
|
rt300@0
|
26 float ay,
|
rt300@0
|
27 float awidth,
|
rt300@0
|
28 float aheight,
|
rt300@0
|
29 float azx,
|
rt300@0
|
30 float azy,
|
rt300@0
|
31 const UIProps& props);
|
rt300@0
|
32
|
rt300@0
|
33 void draw(){
|
rt300@0
|
34 if(hidden)return;
|
rt300@0
|
35 if(on){
|
rt300@0
|
36 ofSetColor(foregroundHi);
|
rt300@0
|
37 }else{
|
rt300@0
|
38 ofSetColor(foregroundLo);
|
rt300@0
|
39
|
rt300@0
|
40 }
|
rt300@0
|
41 if(inactive){
|
rt300@0
|
42 ofSetColor(fgInactive);
|
rt300@0
|
43 }
|
rt300@0
|
44
|
rt300@0
|
45
|
rt300@0
|
46
|
rt300@0
|
47 ofPushMatrix();
|
rt300@0
|
48 ofDisableAlphaBlending();
|
rt300@0
|
49 ofEnableDepthTest();
|
rt300@0
|
50 // move to correct pos
|
rt300@0
|
51
|
rt300@0
|
52 ofTranslate( x+width/2, y+height/2, camTrans);
|
rt300@0
|
53 ofRotate( angleX, 1, 0, 0 );
|
rt300@0
|
54 ofRotate( angleY, 0, 1, 0 );
|
rt300@0
|
55
|
rt300@0
|
56 setNormals(boxMesh);
|
rt300@0
|
57 ofSetColor(foregroundHi);
|
rt300@0
|
58 boxMesh.draw();
|
rt300@0
|
59
|
rt300@0
|
60 // draw indicators
|
rt300@0
|
61 drawIndicator();
|
rt300@0
|
62 ofPopMatrix();
|
rt300@0
|
63
|
rt300@0
|
64 drawLabels();
|
rt300@0
|
65 };
|
rt300@0
|
66
|
rt300@0
|
67 void drawIndicator(){
|
rt300@0
|
68
|
rt300@0
|
69 if (hintShowing && (hintZ > zVal)){
|
rt300@0
|
70 hintColor = calculateHintColor();
|
rt300@0
|
71 draw3DCrossHairs(hintX, hintY, hintZ,hintColor);
|
rt300@0
|
72
|
rt300@0
|
73 }
|
rt300@0
|
74
|
rt300@0
|
75 // draw indicator
|
rt300@0
|
76 draw3DCrossHairs(xVal,yVal,zVal, indicatorColor);
|
rt300@0
|
77 // put light in indicateor
|
rt300@0
|
78 //
|
rt300@0
|
79
|
rt300@0
|
80
|
rt300@0
|
81 if (hintShowing && hintZ <= zVal){
|
rt300@0
|
82 hintColor = calculateHintColor();
|
rt300@0
|
83 draw3DCrossHairs(hintX, hintY, hintZ,hintColor);
|
rt300@0
|
84
|
rt300@0
|
85 }
|
rt300@0
|
86 }
|
rt300@0
|
87 void draw3DCrossHairs(float x , float y, float z, ofColor c){
|
rt300@0
|
88
|
rt300@0
|
89 float ix = x*width - width/2;
|
rt300@0
|
90 float iy = (1-y)*width - width/2;
|
rt300@0
|
91 float iz = (1-z)*width - width/2;
|
rt300@0
|
92
|
rt300@0
|
93 float left = - width/2;
|
rt300@0
|
94 float bot = width/2;
|
rt300@0
|
95 float front = width/2;
|
rt300@0
|
96 //
|
rt300@0
|
97 ofSetColor(c);
|
rt300@0
|
98 ofSetLineWidth(2.);
|
rt300@0
|
99 // line to bottom
|
rt300@0
|
100 ofLine(ix,iy,iz,ix,bot,iz);
|
rt300@0
|
101 // line to left
|
rt300@0
|
102 ofLine(ix,iy,iz,left,iy,iz);
|
rt300@0
|
103
|
rt300@0
|
104 //blob
|
rt300@0
|
105 ofDrawIcoSphere(ix,iy,iz,12);
|
rt300@0
|
106 // line to front (a bit wierd?)
|
rt300@0
|
107 ofLine(ix,iy,iz,ix,iy,front);
|
rt300@0
|
108
|
rt300@0
|
109
|
rt300@0
|
110
|
rt300@0
|
111 }
|
rt300@0
|
112 ofColor calculateHintColor(){
|
rt300@0
|
113
|
rt300@0
|
114
|
rt300@0
|
115 // this is all duplicate code and may change so a bit bad >:(
|
rt300@0
|
116 float dist = sqrt( 127.*127.*((xVal - hintX)*(xVal - hintX) + (yVal - hintY)*(yVal - hintY) + (zVal - hintZ)*(zVal - hintZ)) );
|
rt300@0
|
117
|
rt300@0
|
118 auto dimComp = sqrt(3.0);
|
rt300@0
|
119 int band = -1;
|
rt300@0
|
120 if (dist < TARGET_SCORE_CC_BAND*dimComp){
|
rt300@0
|
121
|
rt300@0
|
122 band = 1;
|
rt300@0
|
123
|
rt300@0
|
124 }else if (dist < TARGET_SCORE_CC_BAND*2*dimComp){
|
rt300@0
|
125
|
rt300@0
|
126 band = 2;
|
rt300@0
|
127
|
rt300@0
|
128
|
rt300@0
|
129 }else if (dist < TARGET_SCORE_CC_BAND*3*dimComp){
|
rt300@0
|
130
|
rt300@0
|
131 band = 3;
|
rt300@0
|
132
|
rt300@0
|
133
|
rt300@0
|
134 }else if (dist < TARGET_SCORE_CC_BAND*4*dimComp){
|
rt300@0
|
135
|
rt300@0
|
136 band = 4;
|
rt300@0
|
137
|
rt300@0
|
138
|
rt300@0
|
139 }else if (dist < TARGET_SCORE_CC_BAND*6*dimComp){ // 30
|
rt300@0
|
140
|
rt300@0
|
141 band = 5;
|
rt300@0
|
142
|
rt300@0
|
143 }else if (dist < TARGET_SCORE_CC_BAND*9*dimComp){ // 45
|
rt300@0
|
144 band = 6;
|
rt300@0
|
145
|
rt300@0
|
146 }else{
|
rt300@0
|
147 band = 7;
|
rt300@0
|
148
|
rt300@0
|
149 }
|
rt300@0
|
150
|
rt300@0
|
151
|
rt300@0
|
152 ofColor c;
|
rt300@0
|
153 if(band == 1){
|
rt300@0
|
154 // yellow red blue
|
rt300@0
|
155 c = ofColor(255,255,0,255);
|
rt300@0
|
156 }else if(band == 2){
|
rt300@0
|
157 c = ofColor(255,0,0,255);
|
rt300@0
|
158 }else if(band == 3){
|
rt300@0
|
159 c = ofColor(45,45,255,255);
|
rt300@0
|
160 }else if(band == 4){
|
rt300@0
|
161 c = ofColor(0,255,0,255);
|
rt300@0
|
162 }else{
|
rt300@0
|
163 c = ofColor(150,235,200,255);
|
rt300@0
|
164 }
|
rt300@0
|
165 return c;
|
rt300@0
|
166
|
rt300@0
|
167 }
|
rt300@0
|
168 void drawCylinders(){
|
rt300@0
|
169 ofPushMatrix();
|
rt300@0
|
170 ofTranslate( x, y, camTrans);
|
rt300@0
|
171 // vertical
|
rt300@0
|
172 ofSetColor(0,255,0);
|
rt300@0
|
173 ofDrawCylinder(0, 0, 32, 500*yVal);
|
rt300@0
|
174
|
rt300@0
|
175 // into screen
|
rt300@0
|
176 ofSetColor(255,0,0);
|
rt300@0
|
177 ofRotate( 90, 1, 0, 0 );
|
rt300@0
|
178 ofDrawCylinder(70, 0, 32, 500*zVal);
|
rt300@0
|
179 ofRotate( -90, 1, 0, 0 );
|
rt300@0
|
180 // l/r horizona
|
rt300@0
|
181 ofSetColor(0,0,255);
|
rt300@0
|
182 ofRotate( 90, 0, 0, 1 );
|
rt300@0
|
183 ofDrawCylinder(70, 300, 32, 500*xVal);
|
rt300@0
|
184
|
rt300@0
|
185
|
rt300@0
|
186 ofPopMatrix();
|
rt300@0
|
187 }
|
rt300@0
|
188 float valToScreen(float val){
|
rt300@0
|
189 float sc;
|
rt300@0
|
190 return sc;
|
rt300@0
|
191 };
|
rt300@0
|
192
|
rt300@0
|
193 bool handleMyTouch(int x, int y, touchType ttype, int touchID){
|
rt300@0
|
194 static float lastTX = 0.,lastTY = 0.;
|
rt300@0
|
195
|
rt300@0
|
196
|
rt300@0
|
197 if (ttype == TOUCH_MOVED && touchID == 0){
|
rt300@0
|
198 float dx = x -lastTX;
|
rt300@0
|
199 float dy = y - lastTY;
|
rt300@0
|
200
|
rt300@0
|
201 angleY += dx/3;
|
rt300@0
|
202 angleX += dy/3;
|
rt300@0
|
203
|
rt300@0
|
204 }
|
rt300@0
|
205
|
rt300@0
|
206 if (ttype == TOUCH_MOVED && touchID == 1){
|
rt300@0
|
207 float dx = x -lastTX;
|
rt300@0
|
208 float dy = y - lastTY;
|
rt300@0
|
209
|
rt300@0
|
210 // adjust light angle?
|
rt300@0
|
211 angleY += dx/3;
|
rt300@0
|
212 angleX += dy/3;
|
rt300@0
|
213
|
rt300@0
|
214 }
|
rt300@0
|
215
|
rt300@0
|
216 //cout << angleX << " : " << angleY << endl;
|
rt300@0
|
217
|
rt300@0
|
218 lastTX = x;
|
rt300@0
|
219 lastTY = y;
|
rt300@0
|
220 return true;
|
rt300@0
|
221
|
rt300@0
|
222 };
|
rt300@0
|
223
|
rt300@0
|
224 float angleX;
|
rt300@0
|
225 float angleY;
|
rt300@0
|
226 float depth;
|
rt300@0
|
227 ofMesh boxMesh;
|
rt300@0
|
228 float camTrans;
|
rt300@0
|
229 ofColor indicatorColor;
|
rt300@0
|
230
|
rt300@0
|
231 };
|
rt300@0
|
232
|