Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void onMouseEvent(int button, int state, int x, int y) {
- //important to convert the coordinates from window coordinates to world coordinates
- int width = glutGet(GLUT_WINDOW_WIDTH);
- int height = glutGet(GLUT_WINDOW_HEIGHT);
- Vector3 last_point;
- last_point.x = x - width / 2;
- last_point.y = height - y - (height / 2);
- if (button == GLUT_LEFT_BUTTON) {
- if (state == GLUT_DOWN) {
- pressed_points.push_back(last_point);
- if (pressed_points.size() < 5)
- last_point.z = randomizar() * 200;
- spline.addPoint(last_point);
- if (pressed_points.size() == 4)
- //per a la proxima practica s'implementarà una altra cosa diferent
- pintar = true;
- } else if (button == GLUT_RIGHT_BUTTON) {
- if (state == GLUT_DOWN) {
- std::cout << "hey" << std::endl;
- //find closer pressed point to the mouse pos and changes its pos to the new pos
- int id_closer = -1;
- float min_distance = 100000; //max value possible
- for (unsigned int i = 0; i < pressed_points.size(); ++i)
- if (pressed_points[i].distance(last_point) < min_distance) {
- id_closer = i;
- min_distance = pressed_points[i].distance(last_point);
- }
- if (id_closer != -1)
- pressed_points[id_closer] = last_point;
- if (id_closer < 4) {
- spline.splinePoints[id_closer] = last_point;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement