-
Notifications
You must be signed in to change notification settings - Fork 0
/
mouseFunc.cpp
47 lines (32 loc) · 1.17 KB
/
mouseFunc.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <stdio.h>
#include <vector>
#include <GL/gl.h>
#include <GL/glut.h>
#include "globals_lib.h"
#include "graphics_lib.h"
#include "intersections_lib.h"
//Gets the clicks of the user to create the lines.
void mouseFunc(int button, int state, int x, int y) {
if(button == GLUT_LEFT_BUTTON && state == GLUT_DOWN){
if(!firstClick){ //If it's the first click, create a new segment, set the first point as the current mouse coordinates.
firstClick = true;
LineSegment newSeg; //Make new segment
newSeg.p1.x = x;
newSeg.p1.y = (500-y);
seg = newSeg;
} else {
//If it's the second click, stores the segment in the vector of segments.
seg.p2.x = x;
seg.p2.y = (500-y);
firstClick = false;
segmentVector.insert(segmentVector.end(), seg); //Insert segment into segment vectors
/* //For Sweep Line
//Add the new points to the struct used in Sweep Line Algorithm.
addToSweepStruct();
//We need at least two lines to catch an intersection.
if(sweepVector.size() > 2) sweepLine(); */
checkIntersectionsNaive(); //Checks intersection for every new line.
renderScene(); //Draws the new lines and nes intersections.
}
}
}