├── csv-eeg-data ├── eegs.csv ├── readcsvfile.py └── discreteFT.py ├── README.rst ├── EmokeyDemo └── main.cpp ├── motionMindState └── motionMindState.cpp ├── Tic-Tac-Toe └── main.cpp ├── cogMain.cpp └── Cognitive-TicTacToe └── main.cpp /csv-eeg-data/eegs.csv: -------------------------------------------------------------------------------- 1 | Engagement,Frustration,Meditation,Excitement 2 | 0.641123,0,0.316708,0.00186492 3 | 0.641123,0,0.316708,0.00186492 4 | 0.641123,0,0.316708,0.00186492 5 | 0.720896,0,0.301749,0.00577296 6 | 0.720896,0,0.301749,0.00577296 7 | 0.720896,0,0.301749,0.00577296 8 | 0.720896,0,0.301749,0.00577296 9 | 0.720896,0,0.301749,0.00577296 10 | 0.747991,0,0.296636,0.0114218 11 | 0.747991,0,0.296636,0.0114218 12 | 0.747991,0,0.296636,0.0114218 13 | 0.747991,0,0.296636,0.0114218 14 | 0.75829,0,0.299419,0.0180803 15 | 0.75829,0,0.299419,0.0180803 16 | 0.767428,0,0.302485,0.0411644 17 | 0.767428,0,0.302485,0.0411644 18 | 0.767428,0,0.302485,0.0411644 19 | 0.768346,0,0.305284,0.0733166 20 | -------------------------------------------------------------------------------- /csv-eeg-data/readcsvfile.py: -------------------------------------------------------------------------------- 1 | # Root Mean Square value of the received data. 2 | # this file produces one centralised value of the data. 3 | 4 | import csv 5 | import math 6 | #reading the csv file 7 | with open('eegs.csv', 'rt') as csvfile: 8 | spamreader = csv.reader(csvfile, delimiter=' ', quotechar='|') 9 | a_list = [] 10 | 11 | row_count = 0 12 | for row in spamreader: 13 | a_list.append( row[0].split(',')) 14 | row_count += 1 15 | #change value of m to number of columns in csv file 16 | m = 4 17 | n = row_count 18 | x = [0]*m 19 | 20 | print ("RMS Corresponding to Engagement, Frustration, Meditation, Excitation are:") 21 | for j in range(0,m): 22 | for i in range(1,n): 23 | x[j] = x[j] + float(a_list[i][j]) * float(a_list[i][j]) 24 | #square root ox x1 25 | x[j] = math.sqrt(x[j]/n) 26 | print(x[j]) 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /csv-eeg-data/discreteFT.py: -------------------------------------------------------------------------------- 1 | ##utility file to process the eeg data received in the form of csv format 2 | ## This file calculated discrete fourier transform of the data 3 | 4 | import csv 5 | import math 6 | import cmath 7 | 8 | a_list = [] 9 | 10 | #reading the csv file 11 | file_name = 'EEG_Data.csv' 12 | with open(file_name, 'rt') as cfile: 13 | spamreader = csv.reader(cfile, delimiter=' ', quotechar='|') 14 | 15 | row_count = 0 16 | for row in spamreader: 17 | a_list.append( row[0].split(',')) 18 | row_count += 1 19 | 20 | #define the value of 'm' as the number of columns in the csv file 21 | m = 22 22 | n = row_count 23 | 24 | x = [0]*m 25 | k = -1 26 | # K : deviation factor, by default equal to -1 27 | print ("Discrete Fourier transform in the order of colums:") 28 | for j in range(0,m): 29 | for i in range(1,n): 30 | x[j] = x[j] + float(a_list[i][j])*cmath.exp(complex(0.0,-2*math.pi*i*k/n)) 31 | print(x[j]/n) 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | EPOC EMOTIV Programming 2 | ======================= 3 | Intro 4 | ----- 5 | A revolutionary personal interface for brain computer interacton.The Emotiv EPOC headset uses a total of 16 sensors, 6 | 14 for EEG data, 2 for gyro motions to tune into electrical signals produced by the brain to detect user thoughts, 7 | feelings, expressions and their mental state. 8 | 9 | Requirements 10 | ------------ 11 | 12 | #. OS: Windows 7/8 13 | #. Programming Tool: Visual Basic C++ (tested with express 2010) 14 | #. EMOTIV SDK: Tested with education version. 15 | 16 | Installation 17 | ------------ 18 | Those who spent bucks for the device, get ready with your Emotiv-SDK. SDK installation is fairly easier, 19 | you just have to follow the steps as mentioned in the installation guide. 20 | 21 | 22 | Getting Started 23 | --------------- 24 | 25 | First, wear the headset on your head, try to connect all the 16 sensors with the sdk control panel so that you get a 26 | good connection. 27 | 28 | Second, make sure you set up your applications to be 32 bit x86 in VB, otherwise they won't link to edk.dll 29 | which is 32 bit (unless you have SDK v2.0.0.20 or later which also has 64 bit versions). 30 | Make sure edk.dll and edk_utils.dll are in your project directory or search path. Then you should be 31 | able to build any of the examples in the SDK installation folder. 32 | The SDK manual has fairly comprehensive instructions on how to program for EPOC. 33 | 34 | Programming with glut(a library of utilities for OpenGL programs) 35 | ----------------------------------------------------------------- 36 | `Configuring Visual C++ and GLUT `_ 37 | 38 | Building & Running 39 | ------------------ 40 | 41 | #. F7 for building (succeed without errors) 42 | #. F5 for running your app. 43 | 44 | Patches are welcomed 45 | -------------------- 46 | 47 | .. code-block:: bash 48 | 49 | $ git clone https://github.com/codehunks/emotiv.git "emotiv" 50 | $ cd emotiv 51 | 52 | 53 | References 54 | -------------------- 55 | 56 | [1] `EPOC EMOTIV `_ 57 | 58 | [2] `OpenGL `_ 59 | -------------------------------------------------------------------------------- /EmokeyDemo/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | using namespace std; 14 | char output[100]; 15 | 16 | int x=0,y=0,z=1,ctr=0,check=0; 17 | 18 | void blinkCursor() { 19 | if(z==1) 20 | glColor3f(1.0,0.0,0.0); 21 | else 22 | glColor3f(0.0,0.0,0.0); 23 | 24 | glBegin(GL_POLYGON); 25 | glVertex2d(0+x,0+y); 26 | glVertex2d(200+x,0+y); 27 | glVertex2d(200+x,200+y); 28 | glVertex2d(0+x,200+y); 29 | glEnd(); 30 | glFlush(); 31 | 32 | } 33 | 34 | void display(void){ 35 | 36 | /*glClearColor(0.0,0.0,0.0,0.0); 37 | glClear(GL_COLOR_BUFFER_BIT); 38 | 39 | glLineWidth(2); 40 | 41 | glMatrixMode(GL_PROJECTION); 42 | glLoadIdentity(); 43 | 44 | glOrtho(0, 600, 0, 600, -1, 1); 45 | 46 | glColor3f(1.0,0.0,0.0); 47 | 48 | glBegin(GL_POLYGON); 49 | glVertex2d(100,100); 50 | glVertex2d(200,100); 51 | glVertex2d(200,200); 52 | glVertex2d(100,200); 53 | glEnd(); 54 | glFlush();*/ 55 | glClearColor(0.0,0.0,0.0,0.0); 56 | glClear(GL_COLOR_BUFFER_BIT); 57 | 58 | glLineWidth(2); 59 | 60 | glMatrixMode(GL_PROJECTION); 61 | glLoadIdentity(); 62 | 63 | glOrtho(0, 600, 0, 600, -1, 1); 64 | 65 | blinkCursor(); 66 | 67 | } 68 | 69 | 70 | void updateScreen(void) 71 | { 72 | char c; 73 | ctr++; 74 | if(ctr%150==0){ 75 | ctr=0; 76 | z*=-1; 77 | } 78 | if(_kbhit()) 79 | { 80 | c = getch(); 81 | cout< 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include "edk.h" 12 | #include "edkErrorCode.h" 13 | #include "EmoStateDLL.h" 14 | 15 | #pragma comment(lib, "edk.lib") 16 | #pragma comment(lib, "glut32.lib") 17 | 18 | #define PI 3.1418 19 | 20 | EmoStateHandle eState; 21 | DataHandle hData; 22 | EmoEngineEventHandle eEvent; 23 | 24 | bool oneTime = true; 25 | bool outOfBound = false; 26 | float currX = 0,currY = 0; 27 | double maxRadius = 10000; 28 | float xmax = 0, ymax = 0; 29 | float preX = 0, preY = 0; 30 | int incOrDec = 10; 31 | float oldXVal =0, oldYVal = 0; 32 | unsigned long pass = 0,globalElapsed = 0; 33 | int count = 0; 34 | float x; 35 | 36 | bool readytocollect = false; 37 | 38 | float affEngegement=0.0, affFrus=0.0, affMed=0.0, affExcitement=0.0, affSmile=0.0; 39 | 40 | GLsizei MOUSEx=0, MOUSEy=0; 41 | GLfloat SIDE=50; 42 | float COLOR[][3] = { 43 | {1,0,0}, 44 | {0,1,0}, 45 | {0,0,1}, 46 | {1,1,1}, 47 | {1,1,0.2} 48 | 49 | }; 50 | GLfloat color1[3]; 51 | 52 | EE_DataChannel_t targetChannelList[] = { 53 | ED_COUNTER, 54 | ED_AF3, ED_F7, ED_F3, ED_FC5, ED_T7, 55 | ED_P7, ED_O1, ED_O2, ED_P8, ED_T8, 56 | ED_FC6, ED_F4, ED_F8, ED_AF4, ED_GYROX, ED_GYROY, ED_TIMESTAMP, 57 | ED_FUNC_ID, ED_FUNC_VALUE, ED_MARKER, ED_SYNC_SIGNAL 58 | }; 59 | 60 | 61 | void affective(void) 62 | { unsigned int userID = 0; 63 | const unsigned short composerPort = 1726; 64 | 65 | unsigned int datarate = 0; 66 | 67 | int option = 0; 68 | int state = 0; 69 | 70 | 71 | state = EE_EngineGetNextEvent(eEvent); 72 | EE_Event_t eventType; 73 | 74 | if (state == EDK_OK) { 75 | 76 | eventType = EE_EmoEngineEventGetType(eEvent); 77 | EE_EmoEngineEventGetUserId(eEvent, &userID); 78 | EE_EmoEngineEventGetEmoState(eEvent, eState); 79 | 80 | // Log the EmoState if it has been updated 81 | if (eventType == EE_UserAdded) { 82 | std::cout << "User added"; 83 | EE_DataAcquisitionEnable(userID,true); 84 | readytocollect = true; 85 | } 86 | 87 | //std::cout<<"recollect & event is "< 0.5) 128 | { 129 | std::cout <<" You're smiling "; 130 | glColor3fv(COLOR[4]); 131 | //glColor3fv(color1); 132 | glBegin(GL_POLYGON); 133 | glVertex3f(MOUSEx, MOUSEy,0); 134 | glVertex3f(MOUSEx+SIDE, MOUSEy,0); 135 | glVertex3f(MOUSEx+SIDE, MOUSEy+SIDE,0); 136 | glVertex3f(MOUSEx, MOUSEy+SIDE,0); 137 | } 138 | else { 139 | /*if(affExcitement > 0.7 ) 140 | glColor3fv(COLOR[2]); //GLfloat COLOR[3] = {0,0,1}; //blue for excitement 141 | else if(affFrus >0.7) 142 | glColor3fv(COLOR[0]); //GLfloat COLOR[3] = {1,0,0}; //red for frustration 143 | else if(affEngegement > 0.5) 144 | glColor3fv(COLOR[1]); //GLfloat COLOR[3] = {0,1,0}; //green for engagement/meditation 145 | else 146 | glColor3fv(COLOR[3]); //GLfloat COLOR[3] = {1,0,1}; //white 147 | */ 148 | color1[0]=affFrus; 149 | color1[1]=affEngegement; 150 | color1[2]=affExcitement; 151 | glColor3fv(color1); 152 | 153 | 154 | glBegin(GL_POINTS); 155 | glVertex2i(MOUSEx, MOUSEy);} 156 | 157 | //printf("this is %d %d", MOUSEx, MOUSEy); 158 | glEnd(); 159 | glFlush(); 160 | } 161 | 162 | void display(void) 163 | { 164 | //glClearColor (0.0,0.0,0.0,1.0); 165 | //glClear (GL_COLOR_BUFFER_BIT); 166 | glLoadIdentity(); 167 | drawSquare1(); 168 | glFlush(); 169 | } 170 | 171 | void updateScreen(void) 172 | { affective(); 173 | int gyroX = 0,gyroY = 0; 174 | EE_HeadsetGetGyroDelta(0,&gyroX,&gyroY); 175 | MOUSEx += gyroX; 176 | MOUSEy += gyroY; 177 | 178 | //printf ("gyrox is %d gyroy is %d ",gyroX, gyroY); 179 | glutPostRedisplay(); 180 | } 181 | 182 | /*void updateDisplay(void) 183 | { 184 | int gyroX = 0,gyroY = 0; 185 | EE_HeadsetGetGyroDelta(0,&gyroX,&gyroY); 186 | xmax += gyroX; 187 | ymax += gyroY; 188 | 189 | if( outOfBound ) 190 | { 191 | if( preX != gyroX && preY != gyroY ) 192 | { 193 | xmax = currX; 194 | ymax = currY; 195 | } 196 | } 197 | 198 | double val = sqrt((float)(xmax*xmax + ymax*ymax)); 199 | 200 | std::cout <<"xmax : " << xmax <<" ; ymax : " << ymax << std::endl; 201 | 202 | 203 | if( val >= maxRadius ) 204 | { 205 | changeXY(1); 206 | outOfBound = true; 207 | preX = gyroX; 208 | preY = gyroY; 209 | } 210 | else 211 | { 212 | outOfBound = false; 213 | if(oldXVal == gyroX && oldYVal == gyroY) 214 | { 215 | ++count; 216 | if( count > 10 ) 217 | { 218 | changeXY(0); 219 | } 220 | } 221 | else 222 | { 223 | count = 0; 224 | currX = xmax; 225 | currY = ymax; 226 | oldXVal = gyroX; 227 | oldYVal = gyroY; 228 | } 229 | } 230 | Sleep(15); 231 | glutPostRedisplay(); 232 | }*/ 233 | void reshape(int w, int h) 234 | { 235 | glViewport(0,0,(GLsizei)w,(GLsizei)h); 236 | glMatrixMode(GL_PROJECTION); 237 | glLoadIdentity(); 238 | //gluPerspective (60, (GLfloat)w / (GLfloat)h, 1.0, 100.0); 239 | glOrtho(0.0,800,800,0,-1.0,1.0); 240 | glMatrixMode(GL_MODELVIEW); 241 | glLoadIdentity(); 242 | } 243 | void setX(int x) 244 | { 245 | MOUSEx=x; 246 | } 247 | 248 | void setY(int y) 249 | { 250 | MOUSEy=y; 251 | } 252 | 253 | void motion (int x, int y) 254 | { 255 | // Print the mouse drag position 256 | //printf ("Mouse Drag Position: %d, %d.\n", x, y); 257 | setX(x); 258 | setY(y); 259 | glutPostRedisplay(); 260 | } 261 | /* 262 | * Request double buffer display mode. 263 | * Register mouse input callback functions 264 | */ 265 | int main(int argc, char** argv) 266 | { 267 | eEvent = EE_EmoEngineEventCreate(); 268 | eState = EE_EmoStateCreate(); 269 | unsigned int userID = -1; 270 | float secs = 1; 271 | 272 | EE_EngineConnect(); 273 | 274 | hData = EE_DataCreate(); 275 | EE_DataSetBufferSizeInSec(secs); 276 | 277 | glutInit(&argc,argv); 278 | glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); 279 | glutInitWindowSize(800,800); 280 | glutInitWindowPosition(0,0); 281 | glutCreateWindow("Moving squares"); 282 | glutDisplayFunc(display); 283 | glutReshapeFunc(reshape); 284 | glutMotionFunc(motion); 285 | glutIdleFunc(updateScreen); 286 | glutMainLoop(); 287 | 288 | EE_EngineDisconnect(); 289 | EE_EmoStateFree(eState); 290 | EE_EmoEngineEventFree(eEvent); 291 | 292 | return 0; 293 | } 294 | -------------------------------------------------------------------------------- /Tic-Tac-Toe/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include "edk.h" 13 | #include "edkErrorCode.h" 14 | #include "EmoStateDLL.h" 15 | 16 | #pragma comment(lib, "edk.lib") 17 | #pragma comment(lib, "glut32.lib") 18 | 19 | #define PI 3.1418 20 | 21 | EmoStateHandle eState; 22 | DataHandle hData; 23 | EmoEngineEventHandle eEvent; 24 | 25 | bool oneTime = true; 26 | bool outOfBound = false; 27 | float currX = 0,currY = 0; 28 | double maxRadius = 10000; 29 | float xmax = 0, ymax = 0; 30 | float preX = 0, preY = 0; 31 | int incOrDec = 10; 32 | float oldXVal =0, oldYVal = 0; 33 | unsigned long pass = 0,globalElapsed = 0; 34 | int count = 0; 35 | float x; 36 | int visited[10]={0,0,0,0,0,0,0,0,0,0},turn=1, flagvar=-1,ctr=0,flagwin=1; 37 | int drawn[10]={0,0,0,0,0,0,0,0,0,0}; 38 | 39 | int startX,startY,endX,endY,row,col; 40 | 41 | 42 | bool readytocollect = false; 43 | 44 | float affEngegement=0.0, affFrus=0.0, affMed=0.0, affExcitement=0.0, affSmile=0.0; 45 | 46 | GLsizei MOUSEx=0, MOUSEy=0; 47 | GLfloat SIDE=50; 48 | float COLOR[][3] = { 49 | {1,0,0}, 50 | {0,1,0}, 51 | {0,0,1}, 52 | {1,1,1}, 53 | {1,1,0.2} 54 | 55 | }; 56 | GLfloat color1[3]; 57 | 58 | EE_DataChannel_t targetChannelList[] = { 59 | ED_COUNTER, 60 | ED_AF3, ED_F7, ED_F3, ED_FC5, ED_T7, 61 | ED_P7, ED_O1, ED_O2, ED_P8, ED_T8, 62 | ED_FC6, ED_F4, ED_F8, ED_AF4, ED_GYROX, ED_GYROY, ED_TIMESTAMP, 63 | ED_FUNC_ID, ED_FUNC_VALUE, ED_MARKER, ED_SYNC_SIGNAL 64 | }; 65 | 66 | 67 | void affective(void) 68 | { unsigned int userID = 0; 69 | const unsigned short composerPort = 1726; 70 | 71 | unsigned int datarate = 0; 72 | 73 | int option = 0; 74 | int state = 0; 75 | 76 | 77 | state = EE_EngineGetNextEvent(eEvent); 78 | EE_Event_t eventType; 79 | 80 | if (state == EDK_OK) { 81 | 82 | eventType = EE_EmoEngineEventGetType(eEvent); 83 | EE_EmoEngineEventGetUserId(eEvent, &userID); 84 | EE_EmoEngineEventGetEmoState(eEvent, eState); 85 | 86 | // Log the EmoState if it has been updated 87 | if (eventType == EE_UserAdded) { 88 | std::cout << "User added"; 89 | EE_DataAcquisitionEnable(userID,true); 90 | readytocollect = true; 91 | } 92 | 93 | //std::cout<<"recollect & event is "< 0 && MOUSEx < 200) 159 | { 160 | col_num = 1; 161 | } 162 | else if (MOUSEx > 200 && MOUSEx < 400) 163 | { 164 | col_num = 2; 165 | } 166 | else if (MOUSEx > 400 && MOUSEx < 600) 167 | { 168 | col_num = 3; 169 | } 170 | if(MOUSEy > 0 && MOUSEy < 200) 171 | { 172 | row_num = 1; 173 | } 174 | else if(MOUSEy > 200 && MOUSEy < 400) 175 | { 176 | row_num = 4; 177 | } 178 | else if(MOUSEy > 400 && MOUSEy < 600) 179 | { 180 | row_num = 7; 181 | } 182 | 183 | int box_num = col_num+row_num-1; 184 | 185 | row = ceil(box_num/3.0); 186 | col = box_num-((row-1)*3); 187 | 188 | startX = (row-1)*200; 189 | startY = (col-1)*200; 190 | endX = (startX+200); 191 | endY = (startY+200); 192 | 193 | if(visited[box_num]!=1) { 194 | if(turn==1) { 195 | //drawCrossMark(startY, startX, endY,endX); 196 | turn*= -1; 197 | visited[box_num]=1; 198 | } 199 | else{ 200 | //drawBigO(endX,endY); 201 | turn*= -1; 202 | visited[box_num]=1; 203 | } 204 | drawn[box_num] = turn; 205 | } 206 | if(drawn[1]==drawn[4] && drawn[4]==drawn[7] && drawn[1]!=0) 207 | flagvar = 1; 208 | else if(drawn[2]==drawn[5] && drawn[5]==drawn[8] && drawn[2]!=0) 209 | flagvar = 1; 210 | else if(drawn[3]==drawn[6] && drawn[6]==drawn[9] && drawn[3]!=0) 211 | flagvar = 1; 212 | else if(drawn[1]==drawn[2] && drawn[2]==drawn[3] && drawn[1]!=0) 213 | flagvar = 1; 214 | else if(drawn[4]==drawn[5] && drawn[5]==drawn[6] && drawn[4]!=0) 215 | flagvar = 1; 216 | else if(drawn[7]==drawn[8] && drawn[8]==drawn[9] && drawn[7]!=0) 217 | flagvar = 1; 218 | else if(drawn[1]==drawn[5] && drawn[5]==drawn[9] && drawn[5]!=0) 219 | flagvar = 1; 220 | else if(drawn[3]==drawn[5] && drawn[5]==drawn[7] && drawn[7]!=0) 221 | flagvar = 1; 222 | for(int i=1;i<10;i++){ 223 | if(visited[i]!=1){ 224 | ctr=0; 225 | break;} 226 | else 227 | ctr++; 228 | } 229 | if(ctr==9) 230 | flagvar=1; 231 | } 232 | 233 | void drawnState() { 234 | for(int i=1;i<10;i++) { 235 | row = ceil(i/3.0); 236 | col = i-((row-1)*3); 237 | 238 | startX = (row-1)*200; 239 | startY = (col-1)*200; 240 | endX = (startX+200); 241 | endY = (startY+200); 242 | if(drawn[i]<0) 243 | drawBigO(endY,endX); 244 | if(drawn[i]>0) 245 | drawCrossMark(startY, startX, endY,endX); 246 | } 247 | } 248 | 249 | void drawSquare1() 250 | { if (affSmile > 0.06) 251 | { 252 | //std::cout <<" You're smiling "; 253 | glColor3fv(COLOR[4]); 254 | checkBoxNumber(); 255 | } 256 | 257 | 258 | color1[0]=affFrus; 259 | color1[1]=affEngegement; 260 | color1[2]=affExcitement; 261 | glColor3fv(color1); 262 | 263 | 264 | glBegin(GL_POLYGON); 265 | glVertex3f(MOUSEx-10,MOUSEy-10,0); 266 | glVertex3f(MOUSEx+10,MOUSEy-10,0); 267 | glVertex3f(MOUSEx+10,MOUSEy+10,0); 268 | glVertex3f(MOUSEx-10,MOUSEy+10,0); 269 | 270 | glEnd(); 271 | //glFlush(); 272 | 273 | } 274 | 275 | 276 | 277 | void drawBoard() { 278 | glClearColor(0.0,0.0,0.0,0.0); 279 | glClear(GL_COLOR_BUFFER_BIT); 280 | 281 | glLineWidth(2); 282 | 283 | glMatrixMode(GL_PROJECTION); 284 | glLoadIdentity(); 285 | 286 | glOrtho(0, 600, 0, 600, -1, 1); 287 | 288 | glColor3f(0.0,0.0,0.0); 289 | 290 | glBegin(GL_POLYGON); 291 | glVertex3f(0,0,0); 292 | glVertex3f(600,0,0); 293 | glVertex3f(600,600,0); 294 | glVertex3f(0,600,0); 295 | glEnd(); 296 | 297 | glColor3f(0.0,0.0,1.0); 298 | 299 | glBegin(GL_LINES); 300 | glVertex2d(200,0.0); 301 | glVertex2d(200,600.0); 302 | glEnd(); 303 | 304 | glBegin(GL_LINES); 305 | glVertex2d(400,0.0); 306 | glVertex2d(400,600.0); 307 | glEnd(); 308 | 309 | glBegin(GL_LINES); 310 | glVertex2d(0,200.0); 311 | glVertex2d(600,200.0); 312 | glEnd(); 313 | 314 | glBegin(GL_LINES); 315 | glVertex2d(0,400.0); 316 | glVertex2d(600,400.0); 317 | glEnd(); 318 | 319 | //drawCrossMark(200,200,400,0); 320 | //drawBigO(400,400); 321 | } 322 | void drawText(const char *msg){ 323 | glRasterPos2f(-1,-1); 324 | while(*msg){ 325 | glutBitmapCharacter(GLUT_BITMAP_HELVETICA_10,*msg); 326 | glutStrokeCharacter(GLUT_STROKE_ROMAN,*msg++); 327 | } 328 | //glutBitmapString(GLUT_BITMAP_HELVETICA_12,msg); 329 | } 330 | void youwin(){ 331 | glColor3f(0.4,0.6,0.8); 332 | if(ctr==9){ 333 | drawText("Match Drawn"); 334 | if (flagwin == 1){ 335 | 336 | std::cout<<"\nMatch Drawn"; 337 | 338 | flagwin = 2; 339 | } 340 | } 341 | else{ 342 | if (flagwin == 1){ 343 | std::cout<<"\nYou Win !"; 344 | flagwin = 2; 345 | } 346 | drawText("You Win ! "); 347 | 348 | } 349 | drawnState(); 350 | glFlush(); 351 | //getch(); 352 | //exit(0); 353 | } 354 | 355 | void display(void) 356 | { 357 | //glClearColor (0.0,0.0,0.0,1.0); 358 | //glClear (GL_COLOR_BUFFER_BIT); 359 | if(flagvar==-1){ 360 | glClear(GL_COLOR_BUFFER_BIT); 361 | glLoadIdentity(); 362 | drawBoard(); 363 | drawnState(); 364 | drawSquare1(); 365 | glFlush(); 366 | glutPostRedisplay(); 367 | glutSwapBuffers(); 368 | } 369 | if(flagvar==1){ 370 | glLoadIdentity(); 371 | drawBoard(); 372 | drawnState(); 373 | youwin(); 374 | glFlush(); 375 | 376 | } 377 | } 378 | 379 | void updateScreen(void) 380 | { affective(); 381 | int gyroX = 0,gyroY = 0; 382 | EE_HeadsetGetGyroDelta(0,&gyroX,&gyroY); 383 | MOUSEx += gyroX/20; 384 | MOUSEy += gyroY/20; 385 | if(MOUSEx<10) 386 | MOUSEx=10; 387 | if(MOUSEx>590) 388 | MOUSEx=590; 389 | if(MOUSEy<10) 390 | MOUSEy=10; 391 | if(MOUSEy>590) 392 | MOUSEy=590; 393 | 394 | //printf ("gyrox is %d gyroy is %d ",gyroX, gyroY); 395 | glutPostRedisplay(); 396 | } 397 | 398 | void reshape(int w, int h) 399 | { 400 | glViewport(0,0,(GLsizei)w,(GLsizei)h); 401 | glMatrixMode(GL_PROJECTION); 402 | glLoadIdentity(); 403 | //gluPerspective (60, (GLfloat)w / (GLfloat)h, 1.0, 100.0); 404 | glOrtho(0.0,800,800,0,-1.0,1.0); 405 | glMatrixMode(GL_MODELVIEW); 406 | glLoadIdentity(); 407 | } 408 | void setX(int x) 409 | { 410 | MOUSEx=x; 411 | } 412 | 413 | void setY(int y) 414 | { 415 | MOUSEy=y; 416 | } 417 | 418 | void motion (int x, int y) 419 | { 420 | // Print the mouse drag position 421 | //printf ("Mouse Drag Position: %d, %d.\n", x, y); 422 | setX(x); 423 | setY(y); 424 | glutPostRedisplay(); 425 | } 426 | /* 427 | * Request double buffer display mode. 428 | * Register mouse input callback functions 429 | */ 430 | int main(int argc, char** argv) 431 | { 432 | eEvent = EE_EmoEngineEventCreate(); 433 | eState = EE_EmoStateCreate(); 434 | unsigned int userID = -1; 435 | float secs = 1; 436 | 437 | EE_EngineConnect(); 438 | 439 | hData = EE_DataCreate(); 440 | EE_DataSetBufferSizeInSec(secs); 441 | 442 | glutInit(&argc,argv); 443 | glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); 444 | glutInitWindowSize(600,600); 445 | glutInitWindowPosition(0,0); 446 | glutCreateWindow("Tic Tac Toe"); 447 | glutDisplayFunc(display); 448 | glutMotionFunc(motion); 449 | glutIdleFunc(updateScreen); 450 | glutReshapeFunc(reshape); 451 | glutMainLoop(); 452 | /*INPUT input; 453 | input.type = INPUT_MOUSE; 454 | input.mi.dx=0; 455 | input.mi.dy=0; 456 | input.mi.dwFlags=(MOUSEEVENTF_ABSOLUTE|MOUSEEVENTF_MOVE|MOUSEEVENTF_RIGHTDOWN|MOUSEEVENTF_RIGHTUP); 457 | input.mi.mouseData=0; 458 | input.mi.dwExtraInfo=NULL; 459 | SendInput(1,&input,sizeof(INPUT)); 460 | */ 461 | 462 | /*HWND h = (hwnd of window); 463 | WORD mouseX = 10; 464 | WORD mouseY = 10; 465 | PostMessage(hwnd,WM_LBUTTONDOWN,0,MAKELPARAM(mouseX,mouseY)); 466 | */ 467 | EE_EngineDisconnect(); 468 | EE_EmoStateFree(eState); 469 | EE_EmoEngineEventFree(eEvent); 470 | 471 | return 0; 472 | } 473 | -------------------------------------------------------------------------------- /cogMain.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | using namespace std; 13 | 14 | #include "edk.h" 15 | #include "edkErrorCode.h" 16 | #include "EmoStateDLL.h" 17 | 18 | #pragma comment(lib, "edk.lib") 19 | #pragma comment(lib, "glut32.lib") 20 | 21 | #define PI 3.1418 22 | 23 | EmoStateHandle eState; 24 | DataHandle hData; 25 | EmoEngineEventHandle eEvent; 26 | 27 | bool oneTime = true; 28 | bool outOfBound = false; 29 | float currX = 0,currY = 0; 30 | double maxRadius = 10000; 31 | float xmax = 0, ymax = 0; 32 | float preX = 0, preY = 0; 33 | int incOrDec = 10; 34 | float oldXVal =0, oldYVal = 0; 35 | unsigned long pass = 0,globalElapsed = 0; 36 | int count = 0, z=1; 37 | float x; 38 | int visited[10]={0,0,0,0,0,0,0,0,0,0},turn=1, flagvar=-1,ctr=0,cntr=0,flagwin=1; 39 | int drawn[10]={0,0,0,0,0,0,0,0,0,0}; 40 | 41 | int startX,startY,endX,endY,row,col; 42 | 43 | 44 | bool readytocollect = false; 45 | 46 | float affEngegement=0.0, affFrus=0.0, affMed=0.0, affExcitement=0.0, affSmile=0.0; 47 | 48 | GLsizei MOUSEx=0, MOUSEy=0; 49 | GLfloat SIDE=50; 50 | float COLOR[][3] = { 51 | {1,0,0}, 52 | {0,1,0}, 53 | {0,0,1}, 54 | {1,1,1}, 55 | {1,1,0.2} 56 | 57 | }; 58 | GLfloat color1[3]; 59 | 60 | EE_DataChannel_t targetChannelList[] = { 61 | ED_COUNTER, 62 | ED_AF3, ED_F7, ED_F3, ED_FC5, ED_T7, 63 | ED_P7, ED_O1, ED_O2, ED_P8, ED_T8, 64 | ED_FC6, ED_F4, ED_F8, ED_AF4, ED_GYROX, ED_GYROY, ED_TIMESTAMP, 65 | ED_FUNC_ID, ED_FUNC_VALUE, ED_MARKER, ED_SYNC_SIGNAL 66 | }; 67 | 68 | 69 | void affective(void) 70 | { unsigned int userID = 0; 71 | const unsigned short composerPort = 1726; 72 | 73 | unsigned int datarate = 0; 74 | 75 | int option = 0; 76 | int state = 0; 77 | 78 | 79 | state = EE_EngineGetNextEvent(eEvent); 80 | EE_Event_t eventType; 81 | 82 | if (state == EDK_OK) { 83 | 84 | eventType = EE_EmoEngineEventGetType(eEvent); 85 | EE_EmoEngineEventGetUserId(eEvent, &userID); 86 | EE_EmoEngineEventGetEmoState(eEvent, eState); 87 | 88 | // Log the EmoState if it has been updated 89 | if (eventType == EE_UserAdded) { 90 | std::cout << "User added"; 91 | EE_DataAcquisitionEnable(userID,true); 92 | readytocollect = true; 93 | } 94 | 95 | //std::cout<<"recollect & event is "< 0 && MOUSEx < 200) 182 | { 183 | col_num = 1; 184 | } 185 | else if (MOUSEx > 200 && MOUSEx < 400) 186 | { 187 | col_num = 2; 188 | } 189 | else if (MOUSEx > 400 && MOUSEx < 600) 190 | { 191 | col_num = 3; 192 | } 193 | if(MOUSEy > 0 && MOUSEy < 200) 194 | { 195 | row_num = 1; 196 | } 197 | else if(MOUSEy > 200 && MOUSEy < 400) 198 | { 199 | row_num = 4; 200 | } 201 | else if(MOUSEy > 400 && MOUSEy < 600) 202 | { 203 | row_num = 7; 204 | } 205 | 206 | int box_num = col_num+row_num-1; 207 | 208 | row = ceil(box_num/3.0); 209 | col = box_num-((row-1)*3); 210 | 211 | startX = (row-1)*200; 212 | startY = (col-1)*200; 213 | endX = (startX+200); 214 | endY = (startY+200); 215 | 216 | if(visited[box_num]!=1) { 217 | if(turn==1) { 218 | drawCrossMark(startY, startX, endY,endX); 219 | glFlush(); 220 | turn*= -1; 221 | visited[box_num]=1; 222 | } 223 | else{ 224 | drawBigO(endX,endY); 225 | glFlush(); 226 | turn*= -1; 227 | visited[box_num]=1; 228 | } 229 | drawn[box_num] = turn; 230 | } 231 | if(drawn[1]==drawn[4] && drawn[4]==drawn[7] && drawn[1]!=0) 232 | flagvar = 1; 233 | else if(drawn[2]==drawn[5] && drawn[5]==drawn[8] && drawn[2]!=0) 234 | flagvar = 1; 235 | else if(drawn[3]==drawn[6] && drawn[6]==drawn[9] && drawn[3]!=0) 236 | flagvar = 1; 237 | else if(drawn[1]==drawn[2] && drawn[2]==drawn[3] && drawn[1]!=0) 238 | flagvar = 1; 239 | else if(drawn[4]==drawn[5] && drawn[5]==drawn[6] && drawn[4]!=0) 240 | flagvar = 1; 241 | else if(drawn[7]==drawn[8] && drawn[8]==drawn[9] && drawn[7]!=0) 242 | flagvar = 1; 243 | else if(drawn[1]==drawn[5] && drawn[5]==drawn[9] && drawn[5]!=0) 244 | flagvar = 1; 245 | else if(drawn[3]==drawn[5] && drawn[5]==drawn[7] && drawn[7]!=0) 246 | flagvar = 1; 247 | for(int i=1;i<10;i++){ 248 | if(visited[i]!=1){ 249 | ctr=0; 250 | break;} 251 | else 252 | ctr++; 253 | } 254 | if(ctr==9) 255 | flagvar=1; 256 | } 257 | 258 | void drawnState() { 259 | for(int i=1;i<10;i++) { 260 | row = ceil(i/3.0); 261 | col = i-((row-1)*3); 262 | 263 | startX = (row-1)*200; 264 | startY = (col-1)*200; 265 | endX = (startX+200); 266 | endY = (startY+200); 267 | 268 | if(drawn[i]<0) 269 | drawBigO(endY,endX); 270 | if(drawn[i]>0) 271 | drawCrossMark(startY, startX, endY,endX); 272 | 273 | } 274 | } 275 | 276 | void smile(){ 277 | std::cout <<" You're smiling "; 278 | //z=0; 279 | glColor3fv(COLOR[4]); 280 | checkBoxNumber(); 281 | } 282 | 283 | void drawSquare1() 284 | { if (affSmile > 0.06) 285 | { 286 | std::cout <<" You're smiling "; 287 | z=0; 288 | glColor3fv(COLOR[4]); 289 | checkBoxNumber(); 290 | } 291 | 292 | 293 | color1[0]=affFrus; 294 | color1[1]=affEngegement; 295 | color1[2]=affExcitement; 296 | 297 | color1[0]=0.0; 298 | color1[1]=1.0; 299 | color1[2]=0.0; 300 | glColor3fv(color1); 301 | 302 | 303 | /*glBegin(GL_POLYGON); 304 | glVertex3f(MOUSEx-10,MOUSEy-10,0); 305 | glVertex3f(MOUSEx+10,MOUSEy-10,0); 306 | glVertex3f(MOUSEx+10,MOUSEy+10,0); 307 | glVertex3f(MOUSEx-10,MOUSEy+10,0); 308 | 309 | glEnd();*/ 310 | 311 | //glFlush(); 312 | 313 | } 314 | 315 | 316 | 317 | void drawBoard() { 318 | glClearColor(0.0,0.0,0.0,0.0); 319 | glClear(GL_COLOR_BUFFER_BIT); 320 | 321 | glLineWidth(2); 322 | 323 | glMatrixMode(GL_PROJECTION); 324 | glLoadIdentity(); 325 | 326 | glOrtho(0, 600, 0, 600, -1, 1); 327 | 328 | glColor3f(0.0,0.0,0.0); 329 | 330 | glBegin(GL_POLYGON); 331 | glVertex3f(0,0,0); 332 | glVertex3f(600,0,0); 333 | glVertex3f(600,600,0); 334 | glVertex3f(0,600,0); 335 | glEnd(); 336 | 337 | glColor3f(0.0,0.0,1.0); 338 | 339 | glBegin(GL_LINES); 340 | glVertex2d(200,0.0); 341 | glVertex2d(200,600.0); 342 | glEnd(); 343 | 344 | glBegin(GL_LINES); 345 | glVertex2d(400,0.0); 346 | glVertex2d(400,600.0); 347 | glEnd(); 348 | 349 | glBegin(GL_LINES); 350 | glVertex2d(0,200.0); 351 | glVertex2d(600,200.0); 352 | glEnd(); 353 | 354 | glBegin(GL_LINES); 355 | glVertex2d(0,400.0); 356 | glVertex2d(600,400.0); 357 | glEnd(); 358 | 359 | //drawCrossMark(200,200,400,0); 360 | //drawBigO(400,400); 361 | } 362 | void drawText(const char *msg){ 363 | glRasterPos2f(-1,-1); 364 | while(*msg){ 365 | glutBitmapCharacter(GLUT_BITMAP_HELVETICA_10,*msg); 366 | glutStrokeCharacter(GLUT_STROKE_ROMAN,*msg++); 367 | } 368 | //glutBitmapString(GLUT_BITMAP_HELVETICA_12,msg); 369 | } 370 | void youwin(){ 371 | glColor3f(0.4,0.6,0.8); 372 | if(ctr==9){ 373 | drawText("Match Drawn"); 374 | if (flagwin == 1){ 375 | 376 | std::cout<<"\nMatch Drawn"; 377 | 378 | flagwin = 2; 379 | } 380 | } 381 | else{ 382 | if (flagwin == 1){ 383 | std::cout<<"\nYou Win !"; 384 | flagwin = 2; 385 | } 386 | drawText("You Win ! "); 387 | 388 | } 389 | drawnState(); 390 | glFlush(); 391 | //getch(); 392 | //exit(0); 393 | } 394 | 395 | void display(void) 396 | { 397 | //glClearColor (0.0,0.0,0.0,1.0); 398 | //glClear (GL_COLOR_BUFFER_BIT); 399 | if(flagvar==-1){ 400 | //glClear(GL_COLOR_BUFFER_BIT); 401 | glLoadIdentity(); 402 | drawBoard(); 403 | drawnState(); 404 | drawSquare1(); 405 | blinkCursor(); 406 | glFlush(); 407 | glutPostRedisplay(); 408 | //glutSwapBuffers(); 409 | } 410 | if(flagvar==1){ 411 | glLoadIdentity(); 412 | drawBoard(); 413 | drawnState(); 414 | youwin(); 415 | blinkCursor(); 416 | glFlush(); 417 | 418 | } 419 | } 420 | 421 | 422 | void updateScreen(void) 423 | { //affective(); 424 | /* 425 | int gyroX = 0,gyroY = 0; 426 | EE_HeadsetGetGyroDelta(0,&gyroX,&gyroY); 427 | MOUSEx += gyroX/20; 428 | MOUSEy += gyroY/20; 429 | if(MOUSEx<10) 430 | MOUSEx=10; 431 | if(MOUSEx>590) 432 | MOUSEx=590; 433 | if(MOUSEy<10) 434 | MOUSEy=10; 435 | if(MOUSEy>590) 436 | MOUSEy=590; 437 | */ 438 | //printf ("gyrox is %d gyroy is %d ",gyroX, gyroY); 439 | char c; 440 | cntr++; 441 | if(cntr%150==0){ 442 | cntr=0; 443 | z*=-1; 444 | } 445 | 446 | if(_kbhit()) 447 | { 448 | c = getch(); 449 | cout< 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | using namespace std; 13 | 14 | #include "edk.h" 15 | #include "edkErrorCode.h" 16 | #include "EmoStateDLL.h" 17 | 18 | #pragma comment(lib, "edk.lib") 19 | #pragma comment(lib, "glut32.lib") 20 | 21 | #define PI 3.1418 22 | 23 | EmoStateHandle eState; 24 | DataHandle hData; 25 | EmoEngineEventHandle eEvent; 26 | 27 | bool oneTime = true; 28 | bool outOfBound = false; 29 | float currX = 0,currY = 0; 30 | double maxRadius = 10000; 31 | float xmax = 0, ymax = 0; 32 | float preX = 0, preY = 0; 33 | int incOrDec = 10; 34 | float oldXVal =0, oldYVal = 0; 35 | unsigned long pass = 0,globalElapsed = 0; 36 | int count = 0, z=1; 37 | float x; 38 | int visited[10]={0,0,0,0,0,0,0,0,0,0},turn=1, flagvar=-1,ctr=0,cntr=0,flagwin=1; 39 | int drawn[10]={0,0,0,0,0,0,0,0,0,0}; 40 | 41 | int startX,startY,endX,endY,row,col; 42 | 43 | int lastTurn=0; 44 | 45 | bool readytocollect = false; 46 | 47 | float affEngegement=0.0, affFrus=0.0, affMed=0.0, affExcitement=0.0, affSmile=0.0; 48 | 49 | GLsizei MOUSEx=0, MOUSEy=0; 50 | GLfloat SIDE=50; 51 | float COLOR[][3] = { 52 | {1,0,0}, 53 | {0,1,0}, 54 | {0,0,1}, 55 | {1,1,1}, 56 | {1,1,0.2} 57 | 58 | }; 59 | GLfloat color1[3]; 60 | 61 | EE_DataChannel_t targetChannelList[] = { 62 | ED_COUNTER, 63 | ED_AF3, ED_F7, ED_F3, ED_FC5, ED_T7, 64 | ED_P7, ED_O1, ED_O2, ED_P8, ED_T8, 65 | ED_FC6, ED_F4, ED_F8, ED_AF4, ED_GYROX, ED_GYROY, ED_TIMESTAMP, 66 | ED_FUNC_ID, ED_FUNC_VALUE, ED_MARKER, ED_SYNC_SIGNAL 67 | }; 68 | 69 | 70 | void affective(void) 71 | { unsigned int userID = 0; 72 | const unsigned short composerPort = 1726; 73 | 74 | unsigned int datarate = 0; 75 | 76 | int option = 0; 77 | int state = 0; 78 | 79 | 80 | state = EE_EngineGetNextEvent(eEvent); 81 | EE_Event_t eventType; 82 | 83 | if (state == EDK_OK) { 84 | 85 | eventType = EE_EmoEngineEventGetType(eEvent); 86 | EE_EmoEngineEventGetUserId(eEvent, &userID); 87 | EE_EmoEngineEventGetEmoState(eEvent, eState); 88 | 89 | // Log the EmoState if it has been updated 90 | if (eventType == EE_UserAdded) { 91 | std::cout << "User added"; 92 | EE_DataAcquisitionEnable(userID,true); 93 | readytocollect = true; 94 | } 95 | 96 | //std::cout<<"recollect & event is "< 0 && MOUSEx < 200) 183 | { 184 | col_num = 1; 185 | } 186 | else if (MOUSEx > 200 && MOUSEx < 400) 187 | { 188 | col_num = 2; 189 | } 190 | else if (MOUSEx > 400 && MOUSEx < 600) 191 | { 192 | col_num = 3; 193 | } 194 | if(MOUSEy > 0 && MOUSEy < 200) 195 | { 196 | row_num = 1; 197 | } 198 | else if(MOUSEy > 200 && MOUSEy < 400) 199 | { 200 | row_num = 4; 201 | } 202 | else if(MOUSEy > 400 && MOUSEy < 600) 203 | { 204 | row_num = 7; 205 | } 206 | 207 | int box_num = col_num+row_num-1; 208 | 209 | row = ceil(box_num/3.0); 210 | col = box_num-((row-1)*3); 211 | 212 | startX = (row-1)*200; 213 | startY = (col-1)*200; 214 | endX = (startX+200); 215 | endY = (startY+200); 216 | 217 | if(visited[box_num]!=1) { 218 | if(turn==1) { 219 | //std::cout<<"vis"; 220 | drawCrossMark(startY, startX, endY,endX); 221 | lastTurn++; 222 | glFlush(); 223 | turn*= -1; 224 | visited[box_num]=1; 225 | } 226 | else{ 227 | //std::cout<<"non-vis"; 228 | drawBigO(endX,endY); 229 | lastTurn++; 230 | glFlush(); 231 | turn*= -1; 232 | visited[box_num]=1; 233 | } 234 | //cout<<"Box num is:"<0) 277 | drawCrossMark(startY, startX, endY,endX); 278 | 279 | } 280 | } 281 | 282 | void smile(){ 283 | //std::cout <<" You're smiling "; 284 | //z=0; 285 | glColor3fv(COLOR[4]); 286 | checkBoxNumber(); 287 | } 288 | 289 | void drawSquare1() 290 | { if (affSmile > 0.06) 291 | { 292 | //std::cout <<" You're smiling "; 293 | z=0; 294 | glColor3fv(COLOR[4]); 295 | checkBoxNumber(); 296 | } 297 | 298 | 299 | color1[0]=affFrus; 300 | color1[1]=affEngegement; 301 | color1[2]=affExcitement; 302 | 303 | color1[0]=0.0; 304 | color1[1]=1.0; 305 | color1[2]=0.0; 306 | glColor3fv(color1); 307 | 308 | 309 | /*glBegin(GL_POLYGON); 310 | glVertex3f(MOUSEx-10,MOUSEy-10,0); 311 | glVertex3f(MOUSEx+10,MOUSEy-10,0); 312 | glVertex3f(MOUSEx+10,MOUSEy+10,0); 313 | glVertex3f(MOUSEx-10,MOUSEy+10,0); 314 | 315 | glEnd();*/ 316 | 317 | //glFlush(); 318 | 319 | } 320 | 321 | 322 | 323 | void drawBoard() { 324 | glClearColor(0.0,0.0,0.0,0.0); 325 | glClear(GL_COLOR_BUFFER_BIT); 326 | 327 | glLineWidth(2); 328 | 329 | glMatrixMode(GL_PROJECTION); 330 | glLoadIdentity(); 331 | 332 | glOrtho(0, 600, 0, 600, -1, 1); 333 | 334 | glColor3f(0.0,0.0,0.0); 335 | 336 | glBegin(GL_POLYGON); 337 | glVertex3f(0,0,0); 338 | glVertex3f(600,0,0); 339 | glVertex3f(600,600,0); 340 | glVertex3f(0,600,0); 341 | glEnd(); 342 | 343 | glColor3f(0.0,0.0,1.0); 344 | 345 | glBegin(GL_LINES); 346 | glVertex2d(200,0.0); 347 | glVertex2d(200,600.0); 348 | glEnd(); 349 | 350 | glBegin(GL_LINES); 351 | glVertex2d(400,0.0); 352 | glVertex2d(400,600.0); 353 | glEnd(); 354 | 355 | glBegin(GL_LINES); 356 | glVertex2d(0,200.0); 357 | glVertex2d(600,200.0); 358 | glEnd(); 359 | 360 | glBegin(GL_LINES); 361 | glVertex2d(0,400.0); 362 | glVertex2d(600,400.0); 363 | glEnd(); 364 | 365 | //drawCrossMark(200,200,400,0); 366 | //drawBigO(400,400); 367 | } 368 | void drawText(const char *msg){ 369 | glRasterPos2f(-1,-1); 370 | while(*msg){ 371 | glutBitmapCharacter(GLUT_BITMAP_HELVETICA_10,*msg); 372 | glutStrokeCharacter(GLUT_STROKE_ROMAN,*msg++); 373 | } 374 | //glutBitmapString(GLUT_BITMAP_HELVETICA_12,msg); 375 | } 376 | void youwin(){ 377 | glColor3f(0.4,0.6,0.8); 378 | if(ctr==9){ 379 | drawText("Match Drawn"); 380 | if (flagwin == 1){ 381 | 382 | std::cout<<"\nMatch Drawn"; 383 | 384 | flagwin = 2; 385 | } 386 | } 387 | else{ 388 | if(lastTurn%2!=0){ 389 | drawText("Player 1 Wins!"); 390 | } 391 | else{ 392 | drawText("Player 2 Wins!"); 393 | } 394 | if (flagwin == 1){ 395 | if(lastTurn%2!=0){ 396 | std::cout<<"Player 1 Wins"; 397 | } 398 | else{ 399 | std::cout<<"Player 2 Wins"; 400 | } 401 | flagwin = 2; 402 | } 403 | 404 | 405 | } 406 | drawnState(); 407 | glFlush(); 408 | //getch(); 409 | //exit(0); 410 | } 411 | 412 | void display(void) 413 | { 414 | //glClearColor (0.0,0.0,0.0,1.0); 415 | //glClear (GL_COLOR_BUFFER_BIT); 416 | if(flagvar==-1){ 417 | //glClear(GL_COLOR_BUFFER_BIT); 418 | glLoadIdentity(); 419 | drawBoard(); 420 | drawnState(); 421 | drawSquare1(); 422 | blinkCursor(); 423 | glFlush(); 424 | glutPostRedisplay(); 425 | //glutSwapBuffers(); 426 | } 427 | if(flagvar==1){ 428 | glLoadIdentity(); 429 | drawBoard(); 430 | drawnState(); 431 | youwin(); 432 | blinkCursor(); 433 | glFlush(); 434 | 435 | } 436 | } 437 | 438 | 439 | void updateScreen(void) 440 | { //affective(); 441 | /* 442 | int gyroX = 0,gyroY = 0; 443 | EE_HeadsetGetGyroDelta(0,&gyroX,&gyroY); 444 | MOUSEx += gyroX/20; 445 | MOUSEy += gyroY/20;*/ 446 | if(MOUSEx<=0) 447 | MOUSEx=10; 448 | if(MOUSEx>=420) 449 | MOUSEx=410; 450 | if(MOUSEy<=0) 451 | MOUSEy=10; 452 | if(MOUSEy>=420) 453 | MOUSEy=410; 454 | 455 | //printf ("gyrox is %d gyroy is %d ",gyroX, gyroY); 456 | char c; 457 | cntr++; 458 | if(cntr%150==0){ 459 | cntr=0; 460 | z*=-1; 461 | } 462 | 463 | if(_kbhit()) 464 | { 465 | c = getch(); 466 | cout<