#include "zoom.h" #include "../callbacks/reshape.h" #include "../../util/check_error.h" #include "../../view/state0.h" #include #include /* * A simple alias to make the code more readable. */ #define S state0 void 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; /* * 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. */ 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); reshape (viewport[2], viewport[3]); glutPostRedisplay (); return; }