comparison src/testApp.cpp @ 8:584ef20184f6

FIX: segv when too many users present - added test on user id; increased MAX_USERS to 16; changed window title to 'Melody Triangle Tracker'; ADDED: full screen option (key 'F'); ADDED: /randinit message between /birth and /start
author samer
date Wed, 15 Feb 2012 10:55:40 +0000
parents 6c8f4c5fdb5c
children
comparison
equal deleted inserted replaced
7:b66834fbe860 8:584ef20184f6
98 98
99 //-------------------------------------------------------------- 99 //--------------------------------------------------------------
100 100
101 testApp::testApp(const char *host, int port, int FPS) { 101 testApp::testApp(const char *host, int port, int FPS) {
102 ofSetupOpenGL(&window, IMGWIDTH,IMGHEIGHT, OF_WINDOW); 102 ofSetupOpenGL(&window, IMGWIDTH,IMGHEIGHT, OF_WINDOW);
103 ofSetWindowTitle("Idyom Installation Tracker"); 103 ofSetWindowTitle("Melody Triangle Tracker");
104 ofSetFrameRate(FPS); 104 ofSetFrameRate(FPS);
105 105
106 // initialise OSC sender 106 // initialise OSC sender
107 printf("OSC target: %s:%d.\n",host,port); 107 printf("OSC target: %s:%d.\n",host,port);
108 printf("Will run at %d frames per second.\n",FPS); 108 printf("Will run at %d frames per second.\n",FPS);
180 180
181 if (draw_image==1) { 181 if (draw_image==1) {
182 for (int i=0, y=0; y<IMGHEIGHT; y++) { 182 for (int i=0, y=0; y<IMGHEIGHT; y++) {
183 for (int x=0; x<IMGWIDTH; x++, i++) { 183 for (int x=0; x<IMGWIDTH; x++, i++) {
184 int id=userRawPixels[i]; 184 int id=userRawPixels[i];
185 if (id>0) { 185 if (id>0 && id<=MAX_USERS) {
186 stats[id-1].accum(x,y,depthMap[i]); 186 stats[id-1].accum(x,y,depthMap[i]);
187 imagePixels[i]=(128/MAX_USERS)*id; 187 imagePixels[i]=(128/MAX_USERS)*id;
188 } else imagePixels[i] = 255; 188 } else imagePixels[i] = 255;
189 } 189 }
190 } 190 }
191 } else { 191 } else {
192 for (int i=0, y=0; y<IMGHEIGHT; y++) { 192 for (int i=0, y=0; y<IMGHEIGHT; y++) {
193 for (int x=0; x<IMGWIDTH; x++, i++) { 193 for (int x=0; x<IMGWIDTH; x++, i++) {
194 int id=userRawPixels[i]; 194 int id=userRawPixels[i];
195 if (id>0) stats[id-1].accum(x,y,depthMap[i]); 195 if (id>0 && id<=MAX_USERS) {
196 stats[id-1].accum(x,y,depthMap[i]);
197 }
196 } 198 }
197 } 199 }
198 } 200 }
199 201
200 for (int id0=0; id0<MAX_USERS; id0++) { 202 for (int id0=0; id0<MAX_USERS; id0++) {
201 if (stats[id0].area()>0) { 203 if (stats[id0].area()>0) {
202 if (!users[id0].present) { 204 if (!users[id0].present) {
203 send_osc_i(sender,"/birth",id0+1); 205 send_osc_i(sender,"/birth",id0+1);
206 send_osc_i(sender,"/randinit",id0+1);
204 send_osc_i(sender,"/start",id0+1); 207 send_osc_i(sender,"/start",id0+1);
205 users[id0].present=true; 208 users[id0].present=true;
206 } 209 }
207 update_user(id0+1,stats[id0],&users[id0]); 210 update_user(id0+1,stats[id0],&users[id0]);
208 } else { 211 } else {
283 286
284 287
285 void testApp::draw(){ 288 void testApp::draw(){
286 char buf[64]; 289 char buf[64];
287 ofSetColor(255,255,255); 290 ofSetColor(255,255,255);
291 ofScale(ofGetWidth()/(float)IMGWIDTH,ofGetHeight()/(float)IMGHEIGHT);
288 292
289 if (draw_image) userImage.draw(0, 0, IMGWIDTH, IMGHEIGHT); 293 if (draw_image) userImage.draw(0, 0, IMGWIDTH, IMGHEIGHT);
290 // ofSetColor(0); 294 // ofSetColor(0);
291 // ofLine(IMGWIDTH,0,IMGWIDTH,IMGHEIGHT); 295 // ofLine(IMGWIDTH,0,IMGWIDTH,IMGHEIGHT);
292 296
306 font.drawString(ofToString(k+1), coors[0]-10, coors[1]-10); 310 font.drawString(ofToString(k+1), coors[0]-10, coors[1]-10);
307 draw_rect(coors[3],coors[4],coors[5],coors[6]); 311 draw_rect(coors[3],coors[4],coors[5],coors[6]);
308 // ofRect(coors[0]+IMGWIDTH, (IMGHEIGHT*coors[2])/max_depth, 10, 10); 312 // ofRect(coors[0]+IMGWIDTH, (IMGHEIGHT*coors[2])/max_depth, 10, 10);
309 } 313 }
310 } 314 }
311 if (!got_floor) { //ofSetColor(0,200,0); 315 if (!got_floor) {
312 ofSetColor(255,0,0); 316 ofSetColor(255,0,0);
313 ofRect(16,16,16,16); 317 ofRect(16,16,16,16);
314 } 318 }
315 } 319 }
316 320
321 printf("floor plane: (%f,%f,%f), <%f,%f,%f>\n", 325 printf("floor plane: (%f,%f,%f), <%f,%f,%f>\n",
322 floor_pie.ptPoint.X, floor_pie.ptPoint.Y, floor_pie.ptPoint.Z, 326 floor_pie.ptPoint.X, floor_pie.ptPoint.Y, floor_pie.ptPoint.Z,
323 floor_pie.vNormal.X, floor_pie.vNormal.Y, floor_pie.vNormal.Z); 327 floor_pie.vNormal.X, floor_pie.vNormal.Y, floor_pie.vNormal.Z);
324 break; 328 break;
325 case 't': draw_time = !draw_time; break; 329 case 't': draw_time = !draw_time; break;
330 case 'F': ofToggleFullscreen(); break;
326 } 331 }
327 } 332 }
328 333
329 void testApp::keyReleased(int key) {} 334 void testApp::keyReleased(int key) {}
330 void testApp::mouseMoved(int x, int y ) {} 335 void testApp::mouseMoved(int x, int y ) {}