From e12911ab4f43b83aa86d92723ebe59231dd16d6b Mon Sep 17 00:00:00 2001 From: Don Pellegrino Date: Thu, 18 Jun 2009 21:14:12 +0000 Subject: Implemented zooming. --- 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 @@ #include "exp004mouse.h" #include "exp004processhits.h" #include "exp004reshape.h" +#include "set_ortho.h" #include "../view/exp004geometry.h" #include "../view/exp004state0.h" #include "../util/check_error.h" #include "../util/pick_convert.h" #include #include +#include /* * A simple alias to make the code more readable. @@ -18,31 +20,70 @@ exp004mouse (int button, int state, int x, int y) { if (button == GLUT_LEFT_BUTTON && state == GLUT_UP) { - if (S.selecting == true && S.zoom == true) + if (S.selection.active && S.selection.purpose == ZOOM) { - GLint viewport[4]; - glGetIntegerv (GL_VIEWPORT, viewport); - - glMatrixMode (GL_PROJECTION); - glLoadIdentity (); + /* + * NOOP if the mouse was not moved. + */ + if (x == S.selection.x || y == S.selection.y) + return; /* * Convert the selection boundary from window coordinates to * world coordinates. */ + glMatrixMode (GL_MODELVIEW); + glLoadIdentity (); + GLdouble model[16]; + glGetDoublev (GL_MODELVIEW_MATRIX, model); + GLdouble projection[16]; + glGetDoublev (GL_PROJECTION_MATRIX, projection); + GLint viewport[4]; + glGetIntegerv (GL_VIEWPORT, viewport); - gluOrtho2D(-20.0, - 20.0, - -20.0, - 20.0); + check_error (__FILE__, __LINE__); + + GLdouble start_position[3]; + gluUnProject (S.selection.x, + viewport[3] - S.selection.y, + 0, + model, + projection, + viewport, + &start_position[0], + &start_position[1], + &start_position[2]); + + check_error (__FILE__, __LINE__); + + GLdouble end_position[3]; + gluUnProject (x, + viewport[3] - y, + 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]); + + exp004reshape (S.viewport.w, S.viewport.h); + glutPostRedisplay (); } /* * Complete a selection if one was started and not cancelled. */ - if (S.selecting == true && S.zoom == false) + if (S.selection.active && S.selection.purpose == SET) { /* @@ -83,7 +124,7 @@ exp004mouse (int button, int state, int x, int y) double c_y = 0.0; double w = 0.0; double h = 0.0; - pick_convert (S.select_x, S.select_y, x, y, + pick_convert (S.selection.x, S.selection.y, x, y, &c_x, &c_y, &w, &h); gluPickMatrix (c_x, @@ -91,12 +132,9 @@ exp004mouse (int button, int state, int x, int y) w, h, viewport); - - gluOrtho2D(S.ortho.min_x, - S.ortho.max_x, - S.ortho.min_y, - S.ortho.max_y); - + + set_ortho (); + /* * "Alternately issue primitive drawing commands and commands to * manipulate the name stack so that each primitive of interest @@ -126,9 +164,9 @@ exp004mouse (int button, int state, int x, int y) if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) { - S.selecting = true; - S.select_x = x; - S.select_y = y; + S.selection.active = true; + S.selection.x = x; + S.selection.y = y; } return; -- cgit v0.8.3.1-22-g547a