summaryrefslogtreecommitdiffstats
authorDon Pellegrino <don@drexel.edu>2009-06-18 21:14:12 (GMT)
committer Don Pellegrino <don@drexel.edu>2009-06-18 21:14:12 (GMT)
commite12911ab4f43b83aa86d92723ebe59231dd16d6b (patch) (unidiff)
tree92945423a31e18b121e4c6a916f573d0b8858a0e
parentae6ce70b96395c1a73c5b1e2be498a18628c44e1 (diff)
downloadexp005-e12911ab4f43b83aa86d92723ebe59231dd16d6b.zip
exp005-e12911ab4f43b83aa86d92723ebe59231dd16d6b.tar.gz
exp005-e12911ab4f43b83aa86d92723ebe59231dd16d6b.tar.bz2
Implemented zooming.
-rw-r--r--src/controller/exp004mouse.c80
1 files changed, 59 insertions, 21 deletions
diff --git a/src/controller/exp004mouse.c b/src/controller/exp004mouse.c
index 72791d5..fb753d6 100644
--- a/src/controller/exp004mouse.c
+++ b/src/controller/exp004mouse.c
@@ -1,12 +1,14 @@
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 "set_ortho.h"
4#include "../view/exp004geometry.h"5#include "../view/exp004geometry.h"
5#include "../view/exp004state0.h"6#include "../view/exp004state0.h"
6#include "../util/check_error.h"7#include "../util/check_error.h"
7#include "../util/pick_convert.h"8#include "../util/pick_convert.h"
8#include <GL/glut.h>9#include <GL/glut.h>
9#include <stdio.h>10#include <stdio.h>
11#include <math.h>
1012
11/*13/*
12 * A simple alias to make the code more readable.14 * A simple alias to make the code more readable.
@@ -18,31 +20,70 @@ exp004mouse (int button, int state, int x, int y)
18{20{
19 if (button == GLUT_LEFT_BUTTON && state == GLUT_UP)21 if (button == GLUT_LEFT_BUTTON && state == GLUT_UP)
20 {22 {
21 if (S.selecting == true && S.zoom == true)23 if (S.selection.active && S.selection.purpose == ZOOM)
22 {24 {
23 GLint viewport[4];25 /*
24 glGetIntegerv (GL_VIEWPORT, viewport);26 * NOOP if the mouse was not moved.
2527 */
26 glMatrixMode (GL_PROJECTION);28 if (x == S.selection.x || y == S.selection.y)
27 glLoadIdentity ();29 return;
2830
29 /*31 /*
30 * Convert the selection boundary from window coordinates to32 * Convert the selection boundary from window coordinates to
31 * world coordinates.33 * world coordinates.
32 */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];
42 glGetIntegerv (GL_VIEWPORT, viewport);
3343
34 gluOrtho2D(-20.0,44 check_error (__FILE__, __LINE__);
35 20.0,45
36 -20.0,46 GLdouble start_position[3];
37 20.0); 47 gluUnProject (S.selection.x,
48 viewport[3] - S.selection.y,
49 0,
50 model,
51 projection,
52 viewport,
53 &start_position[0],
54 &start_position[1],
55 &start_position[2]);
56
57 check_error (__FILE__, __LINE__);
58
59 GLdouble end_position[3];
60 gluUnProject (x,
61 viewport[3] - y,
62 0,
63 model,
64 projection,
65 viewport,
66 &end_position[0],
67 &end_position[1],
68 &end_position[2]);
3869
70 check_error (__FILE__, __LINE__);
71
72 S.zoom.active = true;
73 S.zoom.coords[0] = fmin (start_position[0], end_position[0]);
74 S.zoom.coords[1] = fmax (start_position[0], end_position[0]);
75 S.zoom.coords[2] = fmin (start_position[1], end_position[1]);
76 S.zoom.coords[3] = fmax (start_position[1], end_position[1]);
77
78 exp004reshape (S.viewport.w, S.viewport.h);
79
39 glutPostRedisplay ();80 glutPostRedisplay ();
40 }81 }
4182
42 /*83 /*
43 * Complete a selection if one was started and not cancelled.84 * Complete a selection if one was started and not cancelled.
44 */85 */
45 if (S.selecting == true && S.zoom == false)86 if (S.selection.active && S.selection.purpose == SET)
46 {87 {
47 88
48 /*89 /*
@@ -83,7 +124,7 @@ exp004mouse (int button, int state, int x, int y)
83 double c_y = 0.0;124 double c_y = 0.0;
84 double w = 0.0;125 double w = 0.0;
85 double h = 0.0;126 double h = 0.0;
86 pick_convert (S.select_x, S.select_y, x, y,127 pick_convert (S.selection.x, S.selection.y, x, y,
87 &c_x, &c_y, &w, &h);128 &c_x, &c_y, &w, &h);
88129
89 gluPickMatrix (c_x,130 gluPickMatrix (c_x,
@@ -91,12 +132,9 @@ exp004mouse (int button, int state, int x, int y)
91 w,132 w,
92 h,133 h,
93 viewport); 134 viewport);
94 135
95 gluOrtho2D(S.ortho.min_x,136 set_ortho ();
96 S.ortho.max_x,137
97 S.ortho.min_y,
98 S.ortho.max_y);
99
100 /*138 /*
101 * "Alternately issue primitive drawing commands and commands to139 * "Alternately issue primitive drawing commands and commands to
102 * manipulate the name stack so that each primitive of interest140 * manipulate the name stack so that each primitive of interest
@@ -126,9 +164,9 @@ exp004mouse (int button, int state, int x, int y)
126164
127 if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)165 if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
128 {166 {
129 S.selecting = true;167 S.selection.active = true;
130 S.select_x = x;168 S.selection.x = x;
131 S.select_y = y;169 S.selection.y = y;
132 }170 }
133171
134 return;172 return;

Valid XHTML 1.0 Strict

Copyright © 2009 Don Pellegrino All Rights Reserved.