00001 #include "drawBO.H"
00002 #include "defineBO.H"
00003
00004 int target_Pt3[2] = {4,6};
00005 int target_Pt2[4] = {1,2,3,5};
00006 int BO_L[2][2] = {{1,3},{0,2}};
00007 int BO_Sq[2][2] = {{0,2},{1,3}};
00008 int BO_Pt2[2][2] = {{0,2},{1,3}};
00009 int BO_Shapes[2][12] = {{0,1,2,3,7,8,9,10,15,16,19,20},
00010 {4,5,6,11,12,13,14,17,18,21,22,23}};
00011 int target_dir;
00012
00013 int msleep(int ms)
00014 {
00015 struct timeval timeout;
00016
00017 timeout.tv_sec = ms / 1000;
00018 timeout.tv_usec = (ms % 1000) * 1000;
00019 if (select(0, (fd_set *) 0, (fd_set *) 0, (fd_set *) 0, &timeout) < 0) {
00020 perror("usleep");
00021 return -1;
00022 }
00023 return 0;
00024 }
00025
00026
00027 int selection(int tar)
00028 {
00029 if(tar >= 0 && tar < 4)return 0;
00030 else if(tar >=4 && tar < 8)return 1;
00031 else return 2;
00032 }
00033
00034 void shuffle (int array[],int count)
00035 {
00036 int i,tmp,change,array2[400];
00037
00038 srand((unsigned int)time(NULL));
00039
00040 for (i = 0; i < count; ++i)
00041 array2[i]=array[i];
00042
00043 for (i = 0; i < count; ++i) {
00044 change = rand() % count;
00045 tmp = array2[i];
00046 array2[i] = array2[change];
00047 array2[change] = tmp;
00048
00049 }
00050
00051 for( i = 0; i < count; i++ ){
00052 array[i]=array2[i];
00053 }
00054 }
00055
00056 void fragStimuliBO(int stimuli[],int target_stim,int target_BO)
00057 {
00058 int i;
00059
00060 if (target_stim==0){
00061 for (i=0;i<STIM;i++){
00062 if(i!=1 && i!=3 && i!=9)stimuli[i]=3;
00063 }
00064 }else if (target_stim==1){
00065 for (i=0;i<STIM;i++){
00066 if(i!=0 && i!=2 && i!=8)stimuli[i]=3;
00067 }
00068 }else if (target_stim==2){
00069 for (i=0;i<STIM;i++){
00070 if(i!=1 && i!=3 && i!=11)stimuli[i]=3;
00071 }
00072 }else if (target_stim==3){
00073 for (i=0;i<STIM;i++){
00074 if(i!=0 && i!=2 && i!=10)stimuli[i]=3;
00075 }
00076 }else if (target_stim==4){
00077 for (i=0;i<STIM;i++){
00078 if(i!=9)stimuli[i]=3;
00079 }
00080 }else if (target_stim==5){
00081 for (i=0;i<STIM;i++){
00082 if(i!=8)stimuli[i]=3;
00083 }
00084 }else if (target_stim==6){
00085 for (i=0;i<STIM;i++){
00086 if(i!=11)stimuli[i]=3;
00087 }
00088 }else if (target_stim==7){
00089 for (i=0;i<STIM;i++){
00090 if(i!=10)stimuli[i]=3;
00091 }
00092 }else if (target_stim==8){
00093 for (i=0;i<STIM;i++){
00094 if(i!=1 && i!=5)stimuli[i]=3;
00095 }
00096 }else if (target_stim==9){
00097 for (i=0;i<STIM;i++){
00098 if(i!=0 && i!=4)stimuli[i]=3;
00099 }
00100 }else if (target_stim==10){
00101 for (i=0;i<STIM;i++){
00102 if(i!=3 && i!=7)stimuli[i]=3;
00103 }
00104 }else if (target_stim==11){
00105 for (i=0;i<STIM;i++){
00106 if(i!=2 && i!=6)stimuli[i]=3;
00107 }
00108 }
00109
00110 stimuli[target_stim] = 1;
00111 }
00112
00113 void SelectStimuliBO(int stimuli, float Lcolor, float x, float y, float times)
00114 {
00115 float Newcolor;
00116
00117 if(Lcolor ==1.0) Newcolor = 0.0;
00118 else Newcolor = 1.0;
00119
00120 switch (stimuli){
00121 case 0:
00122 {
00123 draw_dist(1,x,y,Newcolor,times);
00124 }break;
00125 case 1:
00126 {
00127 draw_dist(0,x,y,Newcolor,times);
00128 }break;
00129 case 2:
00130 {
00131 draw_dist(3,x,y,Newcolor,times);
00132 }break;
00133 case 3:
00134 {
00135 draw_dist(2,x,y,Newcolor,times);
00136 }break;
00137 case 4:
00138 {
00139 draw_L1(1,x,y,Newcolor,times);
00140 draw_New1(1,x,y,Lcolor,times);
00141 }break;
00142 case 5:
00143 {
00144 draw_L1(0,x,y,Newcolor,times);
00145 draw_New1(0,x,y,Lcolor,times);
00146 }break;
00147 case 6:
00148 {
00149 draw_L1(3,x,y,Newcolor,times);
00150 draw_New1(3,x,y,Lcolor,times);
00151 }break;
00152 case 7:
00153 {
00154 draw_L1(2,x,y,Newcolor,times);
00155 draw_New1(2,x,y,Lcolor,times);
00156 }break;
00157 case 8:
00158 {
00159 draw_Square1(0,x,y,Newcolor,times);
00160 draw_L1(0,x,y,Lcolor,times);
00161 }break;
00162 case 9:
00163 {
00164 draw_Square1(1,x,y,Newcolor,times);
00165 draw_L1(1,x,y,Lcolor,times);
00166 }break;
00167 case 10:
00168 {
00169 draw_Square1(2,x,y,Newcolor,times);
00170 draw_L1(2,x,y,Lcolor,times);
00171 }break;
00172 case 11:
00173 {
00174 draw_Square1(3,x,y,Newcolor,times);
00175 draw_L1(3,x,y,Lcolor,times);
00176 }break;
00177 case 12:
00178 {
00179 draw_dist(1,x,y,Newcolor,times);
00180 }break;
00181 case 13:
00182 {
00183 draw_dist(0,x,y,Newcolor,times);
00184 }break;
00185 case 14:
00186 {
00187 draw_dist(3,x,y,Newcolor,times);
00188 }break;
00189 case 15:
00190 {
00191 draw_dist(2,x,y,Newcolor,times);
00192 }break;
00193 case 16:
00194 {
00195 draw_L1(1,x,y,Newcolor,times);
00196 draw_New1(1,x,y,Lcolor,times);
00197 }break;
00198 case 17:
00199 {
00200 draw_L1(0,x,y,Newcolor,times);
00201 draw_New1(0,x,y,Lcolor,times);
00202 }break;
00203 case 18:
00204 {
00205 draw_L1(3,x,y,Newcolor,times);
00206 draw_New1(3,x,y,Lcolor,times);
00207 }break;
00208 case 19:
00209 {
00210 draw_L1(2,x,y,Newcolor,times);
00211 draw_New1(2,x,y,Lcolor,times);
00212 }break;
00213 case 20:
00214 {
00215 draw_Square1(0,x,y,Newcolor,times);
00216 draw_L1(0,x,y,Lcolor,times);
00217 }break;
00218 case 21:
00219 {
00220 draw_Square1(1,x,y,Newcolor,times);
00221 draw_L1(1,x,y,Lcolor,times);
00222 }break;
00223 case 22:
00224 {
00225 draw_Square1(2,x,y,Newcolor,times);
00226 draw_L1(2,x,y,Lcolor,times);
00227 }break;
00228 case 23:
00229 {
00230 draw_Square1(3,x,y,Newcolor,times);
00231 draw_L1(3,x,y,Lcolor,times);
00232 }break;
00233 default:
00234 {
00235 }break;
00236 }
00237 }
00238
00239 void Display_Blank(void)
00240 {
00241 glPushMatrix();
00242
00243 glPopMatrix();
00244 }
00245
00246 void Display_BORight(int target_BO,int target_stim,int target_location,int stimuli[],
00247 int array[], int place[][16], int trial, float hor[],float ver[],float color[])
00248
00249 {
00250 time_t timer;
00251 struct tm *t_st;
00252 int x;
00253 float noise_x,noise_y;
00254 int wait;
00255 int dist_location,dist_stim,anti_BO;
00256
00257
00258 time(&timer);
00259 t_st = localtime(&timer);
00260
00261 if(target_BO == 0)anti_BO = 1;
00262 else anti_BO = 0;
00263
00264
00265 glClearColor(BGC, BGC, BGC, 0);
00266 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00267 Display_FixationBlue();
00268 glutSwapBuffers();
00269
00270
00271 for(wait = 0 ; wait < 5 ; wait++){
00272 glClearColor(BGC, BGC, BGC, 0);
00273 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00274 Display_FixationBlue();
00275 glutSwapBuffers();
00276 msleep(H_SLEEP);
00277 glClearColor(BGC, BGC, BGC, 0);
00278 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00279 Display_Blank();
00280 glutSwapBuffers();
00281 msleep(H_SLEEP);
00282 }
00283
00284
00285 noise_x = ((t_st->tm_sec+rand())%11-5.0)/100.0;
00286 noise_y = ((t_st->tm_sec+rand())%11-5.0)/100.0;
00287
00288 glClearColor(BGC, BGC, BGC, 0);
00289 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00290 SelectStimuliBO(target_stim,color[target_location],hor[target_location]+noise_x,ver[target_location]+noise_y,2.0/(4.0*4.0));
00291
00292
00293 for(x=0;x<15;x++){
00294 for(;;){
00295 dist_location = (t_st->tm_sec+rand())%16;
00296 dist_stim = ((t_st->tm_sec+rand())%STIM);
00297
00298 if(array[dist_location]==0 && stimuli[dist_stim]==0){
00299 noise_x = (((t_st->tm_sec+rand())%11)-5.0)/100.0;
00300 noise_y = (((t_st->tm_sec+rand())%11)-5.0)/100.0;
00301 SelectStimuliBO(dist_stim,color[dist_location],hor[dist_location]+noise_x,ver[dist_location]+noise_y,2.0/(4.0*4.0));
00302 array[dist_location]=2;
00303 place[trial][dist_location]=dist_stim;
00304 break;
00305 }
00306 }
00307 }
00308
00309
00310
00311 glutSwapBuffers();
00312 }
00313
00314 void Display_BOLeft(int target_BO,int target_stim,int target_location, int stimuli[],
00315 int array[], int place[][16],int trial,float hor[],float ver[],float color[])
00316
00317 {
00318 time_t timer;
00319 struct tm *t_st;
00320 int x;
00321 float noise_x,noise_y;
00322 int wait;
00323 int dist_location,dist_stim,anti_BO;
00324
00325
00326 time(&timer);
00327 t_st = localtime(&timer);
00328
00329 if(target_BO == 0)anti_BO = 1;
00330 else anti_BO = 0;
00331
00332
00333 glClearColor(BGC, BGC, BGC, 0);
00334 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00335 Display_FixationRed();
00336 glutSwapBuffers();
00337
00338
00339 for(wait = 0 ; wait < 5 ; wait++){
00340 glClearColor(BGC, BGC, BGC, 0);
00341 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00342 Display_FixationRed();
00343 glutSwapBuffers();
00344 msleep(H_SLEEP);
00345 glClearColor(BGC, BGC, BGC, 0);
00346 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00347 Display_Blank();
00348 glutSwapBuffers();
00349 msleep(H_SLEEP);
00350 }
00351
00352
00353 noise_x = ((t_st->tm_sec+rand())%11-5.0)/100.0;
00354 noise_y = ((t_st->tm_sec+rand())%11-5.0)/100.0;
00355
00356 glClearColor(BGC, BGC, BGC, 0);
00357 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00358 SelectStimuliBO(target_stim,color[target_location],hor[target_location]+noise_x,ver[target_location]+noise_y,2.0/(4.0*4.0));
00359
00360 for(x=0;x<15;x++){
00361 for(;;){
00362 dist_location = (t_st->tm_sec+rand())%16;
00363 dist_stim = ((t_st->tm_sec+rand())%STIM);
00364
00365 if(array[dist_location]==0 && stimuli[dist_stim]==0){
00366 noise_x = (((t_st->tm_sec+rand())%11)-5.0)/100.0;
00367 noise_y = (((t_st->tm_sec+rand())%11)-5.0)/100.0;
00368 SelectStimuliBO(dist_stim,color[dist_location],hor[dist_location]+noise_x,ver[dist_location]+noise_y,2.0/(4.0*4.0));
00369 array[dist_location]=2;
00370 place[trial][dist_location]=dist_stim;
00371 break;
00372 }
00373 }
00374 }
00375
00376
00377 glutSwapBuffers();
00378 }
00379
00380
00381
00382 void Display_BO(int target_BO,int target_stim,int target_type,int target_location,
00383 int stimuli[], int array[], int place[][16],int trial,float hor[],float ver[],float color[])
00384 {
00385 if(target_BO == 0){
00386 Display_BORight(target_BO,target_stim,target_location,stimuli,array,place,trial,hor,ver,color);
00387 }else if(target_BO == 1){
00388 Display_BOLeft(target_BO,target_stim,target_location,stimuli,array,place,trial,hor,ver,color);
00389 }
00390 }
00391
00392 void Display_Calibration(int state_calib, int calib[9])
00393 {
00394 int i,check;
00395 time_t timer;
00396 struct tm *t_st;
00397
00398 time(&timer);
00399 t_st = localtime(&timer);
00400
00401 if(state_calib == 0 || state_calib == 2){
00402 glClearColor(BGC, BGC, BGC, 0);
00403 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00404 Display_Fixation();
00405 glutSwapBuffers();
00406 }
00407 else if(state_calib == 1){
00408 glClearColor(BGC, BGC, BGC, 0);
00409 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00410
00411 Display_Fixation();
00412 glutSwapBuffers();
00413 msleep(F_SLEEP);
00414 glClearColor(BGC, BGC, BGC, 0);
00415 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00416 Display_CalibPoints();
00417 glutSwapBuffers();
00418 }else if(state_calib >= 3 && state_calib <= 11){
00419 for(;;){
00420 check = ((t_st->tm_sec+rand())%9);
00421 if(calib[check]==0){
00422 calib[check]=1;
00423 break;
00424 }
00425 }
00426
00427 for(i=0;i<5;i++){
00428 msleep(CALIB);
00429 glClearColor(BGC, BGC, BGC, 0);
00430 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00431 Display_Blank();
00432 glutSwapBuffers();
00433 msleep(CALIB);
00434 glClearColor(BGC, BGC, BGC, 0);
00435 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00436 Display_Fixation();
00437 glutSwapBuffers();
00438 }
00439
00440 switch (check){
00441 case 0:{
00442 for(i=0;i<5;i++){
00443
00444 glClearColor(BGC, BGC, BGC, 0);
00445 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00446
00447 Display_Calib1();
00448 glutSwapBuffers();
00449 msleep(CALIB);
00450 glClearColor(BGC, BGC, BGC, 0);
00451 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00452 Display_Blank();
00453
00454 glutSwapBuffers();
00455 msleep(CALIB);
00456 }
00457 break;
00458 }
00459 case 1:{
00460 for(i=0;i<5;i++){
00461
00462 glClearColor(BGC, BGC, BGC, 0);
00463 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00464 Display_Calib2();
00465
00466 glutSwapBuffers();
00467 msleep(CALIB);
00468 glClearColor(BGC, BGC, BGC, 0);
00469 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00470 Display_Blank();
00471
00472 glutSwapBuffers();
00473 msleep(CALIB);
00474 }
00475 break;
00476 }
00477 case 2:{
00478 for(i=0;i<5;i++){
00479
00480 glClearColor(BGC, BGC, BGC, 0);
00481 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00482 Display_Calib3();
00483
00484 glutSwapBuffers();
00485 msleep(CALIB);
00486 glClearColor(BGC, BGC, BGC, 0);
00487 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00488 Display_Blank();
00489
00490 glutSwapBuffers();
00491 msleep(CALIB);
00492 }
00493 break;
00494 }
00495 case 3:{
00496 for(i=0;i<5;i++){
00497
00498 glClearColor(BGC, BGC, BGC, 0);
00499 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00500 Display_Calib4();
00501
00502 glutSwapBuffers();
00503 msleep(CALIB);
00504 glClearColor(BGC, BGC, BGC, 0);
00505 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00506 Display_Blank();
00507
00508 glutSwapBuffers();
00509 msleep(CALIB);
00510 }
00511 break;
00512 }
00513 case 4:{
00514 for(i=0;i<5;i++){
00515
00516 glClearColor(BGC, BGC, BGC, 0);
00517 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00518 Display_Calib5();
00519
00520 glutSwapBuffers();
00521 msleep(CALIB);
00522 glClearColor(BGC, BGC, BGC, 0);
00523 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00524 Display_Blank();
00525
00526 glutSwapBuffers();
00527 msleep(CALIB);
00528 }
00529 break;
00530 }
00531 case 5:{
00532 for(i=0;i<5;i++){
00533
00534 glClearColor(BGC, BGC, BGC, 0);
00535 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00536 Display_Calib6();
00537
00538 glutSwapBuffers();
00539 msleep(CALIB);
00540 glClearColor(BGC, BGC, BGC, 0);
00541 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00542 Display_Blank();
00543
00544 glutSwapBuffers();
00545 msleep(CALIB);
00546 }
00547 break;
00548 }
00549 case 6:{
00550 for(i=0;i<5;i++){
00551
00552 glClearColor(BGC, BGC, BGC, 0);
00553 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00554 Display_Calib7();
00555
00556 glutSwapBuffers();
00557 msleep(CALIB);
00558 glClearColor(BGC, BGC, BGC, 0);
00559 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00560 Display_Blank();
00561
00562 glutSwapBuffers();
00563 msleep(CALIB);
00564 }
00565 break;
00566 }
00567 case 7:{
00568 for(i=0;i<5;i++){
00569
00570 glClearColor(BGC, BGC, BGC, 0);
00571 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00572 Display_Calib8();
00573
00574 glutSwapBuffers();
00575 msleep(CALIB);
00576 glClearColor(BGC, BGC, BGC, 0);
00577 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00578 Display_Blank();
00579
00580 glutSwapBuffers();
00581 msleep(CALIB);
00582 }
00583 break;
00584 }
00585 case 8:{
00586 for(i=0;i<5;i++){
00587
00588 glClearColor(BGC, BGC, BGC, 0);
00589 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00590 Display_Calib9();
00591
00592 glutSwapBuffers();
00593 msleep(CALIB);
00594 glClearColor(BGC, BGC, BGC, 0);
00595 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00596 Display_Blank();
00597
00598 glutSwapBuffers();
00599 msleep(CALIB);
00600 }
00601 break;
00602 }
00603 default:break;
00604 }
00605 glClearColor(BGC, BGC, BGC, 0);
00606 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00607
00608 Display_Fixation();
00609 glutSwapBuffers();
00610 }else if(state_calib == 12){
00611 glClearColor(BGC, BGC, BGC, 0);
00612 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00613
00614 Display_Fixation();
00615 glutSwapBuffers();
00616 msleep(F_SLEEP);
00617 glClearColor(BGC, BGC, BGC, 0);
00618 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00619 Display_PointsF();
00620 glutSwapBuffers();
00621 }
00622 }