/** * GLUT callback to handle mouse. */ void oth_mouse(int button, int state, int x, int y) { int r, f; GLint hits; GLuint name_stack[100]; // [FIXME] unnecesserily big ? GLint viewport[4]; Board* board = current_board; Camera* camera = current_camera; if (button != GLUT_LEFT_BUTTON || state != GLUT_DOWN) return; glGetIntegerv(GL_VIEWPORT, viewport); /* Set up viewing for selection mode */ glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); gluPickMatrix(x, viewport[3] - (y - viewport[1] * 2), 2, 2, viewport); gluPerspective(camera->frustum.fov, 1.0, camera->frustum.close, camera->frustum.distant); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); /* Initialize name stack and enter selection mode */ glInitNames(); glSelectBuffer(100, name_stack); // [FIXME] glRenderMode(GL_SELECT); /* Force redraw */ oth_display(); /* Restore viewing conditions */ glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); glFlush(); /* Validate choice */ hits = glRenderMode(GL_RENDER); if (hits != 1) return; r = rank(board, name_stack[3]); f = file(board, name_stack[3]); if (!oth_shift_valid(board, r, f)) { r = f = -1; /* invalid choice */ return; } /* Process valid choice */ oth_shift_update(board, r, f); glutPostRedisplay(); }
/** * Very simple function to get computer play Othello. */ void oth_comp(void) { int rank, file; Board* board = current_board; /* Who Am I ? */ if (shift == DARK) { rank = rank(board, board->best_dark->name); file = file(board, board->best_dark->name); } else { /* LIGHT */ rank = rank(board, board->best_light->name); file = file(board, board->best_light->name); } oth_shift_update(board, rank, file); }