Advertisement
Guest User

Untitled

a guest
Jul 28th, 2017
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. void onMouseEvent(int button, int state, int x, int y) {
  2. //important to convert the coordinates from window coordinates to world coordinates
  3. int width = glutGet(GLUT_WINDOW_WIDTH);
  4. int height = glutGet(GLUT_WINDOW_HEIGHT);
  5. Vector3 last_point;
  6. last_point.x = x - width / 2;
  7. last_point.y = height - y - (height / 2);
  8.  
  9. if (button == GLUT_LEFT_BUTTON) {
  10. if (state == GLUT_DOWN) {
  11.  
  12. pressed_points.push_back(last_point);
  13.  
  14. if (pressed_points.size() < 5)
  15. last_point.z = randomizar() * 200;
  16. spline.addPoint(last_point);
  17.  
  18. if (pressed_points.size() == 4)
  19. //per a la proxima practica s'implementarà una altra cosa diferent
  20. pintar = true;
  21.  
  22. } else if (button == GLUT_RIGHT_BUTTON) {
  23.  
  24. if (state == GLUT_DOWN) {
  25. std::cout << "hey" << std::endl;
  26. //find closer pressed point to the mouse pos and changes its pos to the new pos
  27. int id_closer = -1;
  28.  
  29. float min_distance = 100000; //max value possible
  30. for (unsigned int i = 0; i < pressed_points.size(); ++i)
  31. if (pressed_points[i].distance(last_point) < min_distance) {
  32. id_closer = i;
  33. min_distance = pressed_points[i].distance(last_point);
  34.  
  35. }
  36. if (id_closer != -1)
  37. pressed_points[id_closer] = last_point;
  38. if (id_closer < 4) {
  39. spline.splinePoints[id_closer] = last_point;
  40. }
  41. }
  42. }
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement