void TPinterface::processMouse(int button, int state, int x, int y) { CGFinterface::processMouse(button,state, x, y); // do picking on mouse press (GLUT_DOWN) // this could be more elaborate, e.g. only performing picking when there is a click (DOWN followed by UP) on the same place if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) performPicking(x,y); }
void PickingInterface::processMouse(int button, int state, int x, int y) { CGFinterface::processMouse(button,state, x, y); // do picking on mouse press (GLUT_DOWN) // this could be more elaborate, e.g. only performing picking when there is a click (DOWN followed by UP) on the same place if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) performPicking(x,y); if (button == GLUT_LEFT_BUTTON && state == GLUT_UP){ performPicking(x,y); if(test[0] == picked[0] && test[1] == picked[1]){ printf("Picked ID's: "); cout << test[0] << " " << picked[0] << " " << test[1] << " " << picked[1] << " "; printf("\n"); //send picking data if(test[1] != -1) { std::string data; char datac[10]; std::ostringstream ss; ss << picked[1]; data = ss.str(); strcpy(datac, data.c_str()); strcat(datac, ".\n"); connection.sendData(datac, strlen(datac)); std::cout << "Sent: " << datac << std::endl; std::cout << "Size: " << strlen(datac) << std::endl; xene->row=picked[0]; xene->column=picked[1]; } if(test[0] != -1) { std::string data; char datac[10]; std::ostringstream ss; ss << picked[0]; data = ss.str(); strcpy(datac, data.c_str()); strcat(datac, ".\n"); connection.sendData(datac, strlen(datac)); std::cout << "Sent: " << datac << std::endl; std::cout << "Size: " << strlen(datac) << std::endl; } //receive confirmation if(test[0] != -1) { char ans[10]; connection.receiveData(ans); if(ans[0] == '1') { std::cout << "Switching." << std::endl; if(mode == "origin") { originX = picked[1]; originY = picked[0]; mode = "destination"; } else { destX = picked[1]; destY = picked[0]; if(destX == originX && destY == originY) { xene->row=20; xene->column=20; } for(int i = 0; i < xene->pieces.size(); i++) { if(xene->pieces[i].checkName(destX, destY)){ xene->pieces.erase(xene->pieces.begin() + i); } } for(int i = 0; i < xene->pieces.size(); i++) { if(xene->pieces[i].checkName(originX, originY)) { xene->pieces[i].setName(destX, destY); } } mode = "origin"; } } } test[0] = -1; test[1] = -1; picked[0] = -1; picked[1] = -1; } else { test[0] = -1; test[1] = -1; picked[0] = -1; picked[1] = -1; } } }