-rw-r--r-- | src/Makefile.am | 4 | ||||
-rw-r--r-- | src/controller/exp004mouse.c | 55 | ||||
-rw-r--r-- | src/controller/mousewheel.c | 45 | ||||
-rw-r--r-- | src/controller/mousewheel.h | 11 | ||||
-rw-r--r-- | src/controller/performzoom.c | 65 | ||||
-rw-r--r-- | src/controller/performzoom.h | 9 | ||||
-rw-r--r-- | src/view/exp004view.c | 4 |
7 files changed, 149 insertions, 44 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 38626c7..3bb95ee 100644 --- a/src/Makefile.am +++ b/src/Makefile.am | |||
@@ -7,6 +7,8 @@ exp004viz_SOURCES = \ | |||
7 | controller/exp004processhits.c \ | 7 | controller/exp004processhits.c \ |
8 | controller/exp004reshape.c \ | 8 | controller/exp004reshape.c \ |
9 | controller/keyboard.c \ | 9 | controller/keyboard.c \ |
10 | controller/mousewheel.c \ | ||
11 | controller/performzoom.c \ | ||
10 | controller/selection_from_db.c \ | 12 | controller/selection_from_db.c \ |
11 | controller/selsave.c \ | 13 | controller/selsave.c \ |
12 | controller/set_ortho.c \ | 14 | controller/set_ortho.c \ |
@@ -36,6 +38,8 @@ noinst_HEADERS = \ | |||
36 | controller/exp004processhits.h \ | 38 | controller/exp004processhits.h \ |
37 | controller/exp004reshape.h \ | 39 | controller/exp004reshape.h \ |
38 | controller/keyboard.h \ | 40 | controller/keyboard.h \ |
41 | controller/mousewheel.h \ | ||
42 | controller/performzoom.h \ | ||
39 | controller/selection_from_db.h \ | 43 | controller/selection_from_db.h \ |
40 | controller/selsave.h \ | 44 | controller/selsave.h \ |
41 | controller/set_ortho.h \ | 45 | controller/set_ortho.h \ |
diff --git a/src/controller/exp004mouse.c b/src/controller/exp004mouse.c index 17ff19c..cf09bef 100644 --- a/src/controller/exp004mouse.c +++ b/src/controller/exp004mouse.c | |||
@@ -1,6 +1,7 @@ | |||
1 | #include "exp004mouse.h" | 1 | #include "exp004mouse.h" |
2 | #include "exp004processhits.h" | 2 | #include "exp004processhits.h" |
3 | #include "exp004reshape.h" | 3 | #include "exp004reshape.h" |
4 | #include "performzoom.h" | ||
4 | #include "set_ortho.h" | 5 | #include "set_ortho.h" |
5 | #include "../view/exp004geometry.h" | 6 | #include "../view/exp004geometry.h" |
6 | #include "../view/exp004state0.h" | 7 | #include "../view/exp004state0.h" |
@@ -28,53 +29,19 @@ exp004mouse (int button, int state, int x, int y) | |||
28 | if (x == S.selection.x || y == S.selection.y) | 29 | if (x == S.selection.x || y == S.selection.y) |
29 | return; | 30 | return; |
30 | 31 | ||
31 | /* | ||
32 | * Convert the selection boundary from window coordinates to | ||
33 | * world coordinates. | ||
34 | */ | ||
35 | glMatrixMode (GL_MODELVIEW); | ||
36 | glLoadIdentity (); | ||
37 | GLdouble model[16]; | ||
38 | glGetDoublev (GL_MODELVIEW_MATRIX, model); | ||
39 | GLdouble projection[16]; | ||
40 | glGetDoublev (GL_PROJECTION_MATRIX, projection); | ||
41 | GLint viewport[4]; | 32 | GLint viewport[4]; |
42 | glGetIntegerv (GL_VIEWPORT, viewport); | 33 | glGetIntegerv (GL_VIEWPORT, viewport); |
43 | 34 | ||
44 | check_error (__FILE__, __LINE__); | 35 | printf ("Zooming to: %i, %i, %i, %i\n", |
45 | 36 | S.selection.x, | |
46 | GLdouble start_position[3]; | 37 | viewport[3] - S.selection.y, |
47 | gluUnProject (S.selection.x, | 38 | x, |
48 | viewport[3] - S.selection.y, | 39 | viewport[3] - y); |
49 | 0, | 40 | |
50 | model, | 41 | performzoom (S.selection.x, |
51 | projection, | 42 | viewport[3] - S.selection.y, |
52 | viewport, | 43 | x, |
53 | &start_position[0], | 44 | viewport[3] - y); |
54 | &start_position[1], &start_position[2]); | ||
55 | |||
56 | check_error (__FILE__, __LINE__); | ||
57 | |||
58 | GLdouble end_position[3]; | ||
59 | gluUnProject (x, | ||
60 | viewport[3] - y, | ||
61 | 0, | ||
62 | model, | ||
63 | projection, | ||
64 | viewport, | ||
65 | &end_position[0], &end_position[1], &end_position[2]); | ||
66 | |||
67 | check_error (__FILE__, __LINE__); | ||
68 | |||
69 | S.zoom.active = true; | ||
70 | S.zoom.coords[0] = fmin (start_position[0], end_position[0]); | ||
71 | S.zoom.coords[1] = fmax (start_position[0], end_position[0]); | ||
72 | S.zoom.coords[2] = fmin (start_position[1], end_position[1]); | ||
73 | S.zoom.coords[3] = fmax (start_position[1], end_position[1]); | ||
74 | |||
75 | exp004reshape (S.viewport.w, S.viewport.h); | ||
76 | |||
77 | glutPostRedisplay (); | ||
78 | } | 45 | } |
79 | 46 | ||
80 | /* | 47 | /* |
diff --git a/src/controller/mousewheel.c b/src/controller/mousewheel.c new file mode 100644 index 0000000..c9ac742 --- a/dev/null +++ b/src/controller/mousewheel.c | |||
@@ -0,0 +1,45 @@ | |||
1 | #include "mousewheel.h" | ||
2 | #include "performzoom.h" | ||
3 | #include <GL/glut.h> | ||
4 | |||
5 | void | ||
6 | mousewheel (int button, int dir, int x, int y) | ||
7 | { | ||
8 | /* | ||
9 | * Get the current coordinates, substract some fixed amount and | ||
10 | * then perform the zoom. | ||
11 | */ | ||
12 | GLint viewport[4]; | ||
13 | glGetIntegerv (GL_VIEWPORT, viewport); | ||
14 | |||
15 | /* | ||
16 | * The step size could be either a fixed number of pixels or a percentage. | ||
17 | */ | ||
18 | // int step = 5; | ||
19 | int step = (viewport[3] - viewport[1]) * 0.10; | ||
20 | |||
21 | /* | ||
22 | * Not that the focus of the zoom is currently the center of the | ||
23 | * window but could alternatively be the mouse pointer's position. | ||
24 | */ | ||
25 | |||
26 | // Zoom in | ||
27 | if (dir > 0) | ||
28 | { | ||
29 | performzoom (step, | ||
30 | step, | ||
31 | viewport[3] - step, | ||
32 | viewport[3] - step); | ||
33 | } | ||
34 | |||
35 | // Zoom out | ||
36 | else | ||
37 | { | ||
38 | performzoom (-step, | ||
39 | -step, | ||
40 | viewport[3] + step, | ||
41 | viewport[3] + step); | ||
42 | } | ||
43 | |||
44 | return; | ||
45 | } | ||
diff --git a/src/controller/mousewheel.h b/src/controller/mousewheel.h new file mode 100644 index 0000000..a3944d0 --- a/dev/null +++ b/src/controller/mousewheel.h | |||
@@ -0,0 +1,11 @@ | |||
1 | #ifndef MOUSEWHEEL_H | ||
2 | #define MOUSEWHEEL_H | ||
3 | |||
4 | /* | ||
5 | * GLUT callback to be called whenever the scroll wheel is scrolled. | ||
6 | * Based on code from Ashwin at | ||
7 | * http://stackoverflow.com/questions/14378/using-the-mouse-scrollwheel-in-glut/14444. | ||
8 | */ | ||
9 | void mousewheel (int, int, int, int); | ||
10 | |||
11 | #endif // MOUSEWHEEL_H | ||
diff --git a/src/controller/performzoom.c b/src/controller/performzoom.c new file mode 100644 index 0000000..2fed1d2 --- a/dev/null +++ b/src/controller/performzoom.c | |||
@@ -0,0 +1,65 @@ | |||
1 | #include "performzoom.h" | ||
2 | #include "exp004reshape.h" | ||
3 | #include "../util/check_error.h" | ||
4 | #include "../view/exp004state0.h" | ||
5 | #include <GL/glut.h> | ||
6 | #include <math.h> | ||
7 | |||
8 | /* | ||
9 | * A simple alias to make the code more readable. | ||
10 | */ | ||
11 | #define S exp004state0 | ||
12 | |||
13 | void | ||
14 | performzoom (int x1, int y1, int x2, int y2) | ||
15 | { | ||
16 | /* | ||
17 | * Convert the selection boundary from window coordinates to | ||
18 | * world coordinates. | ||
19 | */ | ||
20 | glMatrixMode (GL_MODELVIEW); | ||
21 | glLoadIdentity (); | ||
22 | GLdouble model[16]; | ||
23 | glGetDoublev (GL_MODELVIEW_MATRIX, model); | ||
24 | GLdouble projection[16]; | ||
25 | glGetDoublev (GL_PROJECTION_MATRIX, projection); | ||
26 | GLint viewport[4]; | ||
27 | glGetIntegerv (GL_VIEWPORT, viewport); | ||
28 | |||
29 | check_error (__FILE__, __LINE__); | ||
30 | |||
31 | GLdouble start_position[3]; | ||
32 | gluUnProject (x1, | ||
33 | y1, | ||
34 | 0, | ||
35 | model, | ||
36 | projection, | ||
37 | viewport, | ||
38 | &start_position[0], | ||
39 | &start_position[1], &start_position[2]); | ||
40 | |||
41 | check_error (__FILE__, __LINE__); | ||
42 | |||
43 | GLdouble end_position[3]; | ||
44 | gluUnProject (x2, | ||
45 | y2, | ||
46 | 0, | ||
47 | model, | ||
48 | projection, | ||
49 | viewport, | ||
50 | &end_position[0], &end_position[1], &end_position[2]); | ||
51 | |||
52 | check_error (__FILE__, __LINE__); | ||
53 | |||
54 | S.zoom.active = true; | ||
55 | S.zoom.coords[0] = fmin (start_position[0], end_position[0]); | ||
56 | S.zoom.coords[1] = fmax (start_position[0], end_position[0]); | ||
57 | S.zoom.coords[2] = fmin (start_position[1], end_position[1]); | ||
58 | S.zoom.coords[3] = fmax (start_position[1], end_position[1]); | ||
59 | |||
60 | exp004reshape (S.viewport.w, S.viewport.h); | ||
61 | |||
62 | glutPostRedisplay (); | ||
63 | |||
64 | return; | ||
65 | } | ||
diff --git a/src/controller/performzoom.h b/src/controller/performzoom.h new file mode 100644 index 0000000..323cc20 --- a/dev/null +++ b/src/controller/performzoom.h | |||
@@ -0,0 +1,9 @@ | |||
1 | #ifndef PERFORMZOOM_H | ||
2 | #define PERFORMZOOM_H | ||
3 | |||
4 | /* | ||
5 | * Perform a zoom operation. | ||
6 | */ | ||
7 | void performzoom (int x1, int y1, int x2, int y2); | ||
8 | |||
9 | #endif // PERFORMZOOM_H | ||
diff --git a/src/view/exp004view.c b/src/view/exp004view.c index 92cb56e..434c016 100644 --- a/src/view/exp004view.c +++ b/src/view/exp004view.c | |||
@@ -2,10 +2,13 @@ | |||
2 | #include "../controller/exp004mouse.h" | 2 | #include "../controller/exp004mouse.h" |
3 | #include "../controller/exp004reshape.h" | 3 | #include "../controller/exp004reshape.h" |
4 | #include "../controller/keyboard.h" | 4 | #include "../controller/keyboard.h" |
5 | #include "../controller/mousewheel.h" | ||
5 | #include "../db/dbconnect.h" | 6 | #include "../db/dbconnect.h" |
6 | #include "exp004init.h" | 7 | #include "exp004init.h" |
7 | #include "exp004state0.h" | 8 | #include "exp004state0.h" |
8 | #include "exp004view.h" | 9 | #include "exp004view.h" |
10 | #include <GL/freeglut.h> | ||
11 | #include <GL/freeglut_ext.h> | ||
9 | #include <GL/glut.h> | 12 | #include <GL/glut.h> |
10 | 13 | ||
11 | void | 14 | void |
@@ -45,6 +48,7 @@ exp004view (void) | |||
45 | glutDisplayFunc (exp004display); | 48 | glutDisplayFunc (exp004display); |
46 | glutKeyboardFunc (keyboard); | 49 | glutKeyboardFunc (keyboard); |
47 | glutMouseFunc (exp004mouse); | 50 | glutMouseFunc (exp004mouse); |
51 | glutMouseWheelFunc (mousewheel); | ||
48 | glutReshapeFunc (exp004reshape); | 52 | glutReshapeFunc (exp004reshape); |
49 | 53 | ||
50 | return; | 54 | return; |