C++ (Qt)#include <QApplication>#include <QGLWidget>#include <QWheelEvent>#include <QMouseEvent>#include <QDebug> class Magnifier : public QGLWidget{public: Magnifier(QWidget* parent = 0) : QGLWidget(parent) { for (int i = 0; i < 5; i++) for (int j = 0; j < 10; j++) { points[(i * 10 + j) * 3] = -0.8f + (i % 2) * 0.2f + j * 1.6f / 10.0f; points[(i * 10 + j) * 3 + 1] = -0.8f + i * 1.6f / 5.0f; points[(i * 10 + j) * 3 + 2] = 0.0f; } top = left = -1.0; mag = 1.0; countMagWindow(0, 0); setMouseTracking(true); } void initializeGL() { glClearColor(0.0f, 0.0f, 0.1f, 1.0f); glPointSize(3.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glMatrixMode(GL_PROJECTION); } void resizeGL(int w, int h) { glViewport(0, 0, w, h); } void paintGL() { glLoadIdentity(); glOrtho(left, left + 2.0 / mag, top + 2.0 / mag, top, -1.0, 1.0); glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0f, 0.0f, 0.0f); glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(3, GL_FLOAT, 0, points); glDrawArrays(GL_POINTS, 0, 50); glDisable(GL_VERTEX_ARRAY); glColor3f(0.0f, 1.0f, 0.0f); glBegin(GL_LINES); glVertex2d(magLeft, magTop); glVertex2d(magLeft, magTop + 2.0 / mag / 1.1); glVertex2d(magLeft, magTop + 2.0 / mag / 1.1); glVertex2d(magLeft + 2.0 / mag / 1.1, magTop + 2.0 / mag / 1.1); glVertex2d(magLeft + 2.0 / mag / 1.1, magTop + 2.0 / mag / 1.1); glVertex2d(magLeft + 2.0 / mag / 1.1, magTop); glVertex2d(magLeft + 2.0 / mag / 1.1, magTop); glVertex2d(magLeft, magTop); glEnd(); } void mouseMoveEvent(QMouseEvent *event) { qDebug() << QString("x: %1, y: %2").arg(event->x()).arg(event->y()); countMagWindow(event->x(), event->y()); updateGL(); } void wheelEvent(QWheelEvent *event) { if (event->delta() > 0) //от себя { left = magLeft; top = magTop; mag *= 1.1; } else { countUnMagWindow(event->x(), event->y()); left = magLeft; top = magTop; mag /= 1.1; } countMagWindow(event->x(), event->y()); updateGL(); } void countMagWindow(int x, int y) { double futureMag = mag * 1.1; double right = left + 2.0 / futureMag, bottom = top + 2.0 / futureMag; magLeft = (right - left) * x / width() * (1.0 / 11.0) + left; magTop = (bottom - top) * y / height() * (1.0 / 11.0) + top; } void countUnMagWindow(int x, int y) { double futureMag = mag / 1.1; double right = left + 2.0 / futureMag, bottom = top + 2.0 / futureMag; magLeft = (right - left) * x / width() * (-0.1) + left; magTop = (bottom - top) * y / height() * (-0.1) + top; } private: float points[50 * 3]; double top, left, mag, magTop, magLeft;}; int main(int argc, char *argv[]){ QApplication a(argc, argv); Magnifier w; w.show(); return a.exec();}