-rw-r--r-- | src/controller/actions/set_ortho.c | 13 | ||||
-rw-r--r-- | src/controller/actions/zoom.c | 70 | ||||
-rw-r--r-- | src/controller/actions/zoom.h | 4 | ||||
-rw-r--r-- | src/controller/callbacks/display.c | 6 | ||||
-rw-r--r-- | src/controller/callbacks/keyboard.c | 7 | ||||
-rw-r--r-- | src/controller/callbacks/mouse.c | 49 | ||||
-rw-r--r-- | src/controller/callbacks/mouse_wheel.c | 66 | ||||
-rw-r--r-- | src/controller/callbacks/reshape.c | 68 | ||||
-rw-r--r-- | src/model/geometry/density_legend_geometry.c | 18 | ||||
-rw-r--r-- | src/model/state/zoom_info.h | 1 | ||||
-rw-r--r-- | src/model/state/zoom_info_init.c | 6 |
11 files changed, 197 insertions, 111 deletions
diff --git a/src/controller/actions/zoom.c b/src/controller/actions/zoom.c index b8e54cc..7209e85 100644 --- a/src/controller/actions/zoom.c +++ b/src/controller/actions/zoom.c @@ -11,52 +11,40 @@ #define S state0 void -zoom (int x1, int y1, int x2, int y2) +zoom (double x1, double y1, double x2, double y2) { + S.zoom.active = true; + + S.zoom.coords[0] = x1; + S.zoom.coords[1] = x2; + S.zoom.coords[2] = y1; + S.zoom.coords[3] = y2; + /* - * Convert the selection boundary from window coordinates to - * world coordinates. + * Preserve the aspect ratio. First convert the selection to the + * aspect ratio of the original geometry. The world is a square so + * convert the zoom region to a square. The reshape callback + * performs step two of converting the squarified zoom region to the + * aspect ratio of the window. This is done in reshape as the window + * may change while the zoom region is held the same. */ - glMatrixMode (GL_MODELVIEW); - glLoadIdentity (); - GLdouble model[16]; - glGetDoublev (GL_MODELVIEW_MATRIX, model); - GLdouble projection[16]; - glGetDoublev (GL_PROJECTION_MATRIX, projection); + double width = S.zoom.coords[1] - S.zoom.coords[0]; + double height = S.zoom.coords[3] - S.zoom.coords[2]; + double difference = fabs(width - height); + + if (width > height) + { + S.zoom.coords[2] -= 0.5 * difference; + S.zoom.coords[3] += 0.5 * difference; + } + else + { + S.zoom.coords[0] -= 0.5 * difference; + S.zoom.coords[1] += 0.5 * difference; + } + GLint viewport[4]; glGetIntegerv (GL_VIEWPORT, viewport); - - check_error (__FILE__, __LINE__); - - GLdouble start_position[3]; - gluUnProject (x1, - y1, - 0, - model, - projection, - viewport, - &start_position[0], - &start_position[1], &start_position[2]); - - check_error (__FILE__, __LINE__); - - GLdouble end_position[3]; - gluUnProject (x2, - y2, - 0, - model, - projection, - viewport, - &end_position[0], &end_position[1], &end_position[2]); - - check_error (__FILE__, __LINE__); - - S.zoom.active = true; - S.zoom.coords[0] = fmin (start_position[0], end_position[0]); - S.zoom.coords[1] = fmax (start_position[0], end_position[0]); - S.zoom.coords[2] = fmin (start_position[1], end_position[1]); - S.zoom.coords[3] = fmax (start_position[1], end_position[1]); - reshape (viewport[2], viewport[3]); glutPostRedisplay (); |