+ else if (event->buttons() & Qt::RightButton)
+ {
+ center = transform_matrix().inverted() *
+ view_matrix().inverted() *
+ QVector3D(-d.x() / (0.5*width()),
+ d.y() / (0.5*height()), 0);
+ update();
+ }
+ mouse_pos = p;
+}
+
+void Canvas::wheelEvent(QWheelEvent *event)
+{
+ // Find GL position before the zoom operation
+ // (to zoom about mouse cursor)
+ auto p = event->pos();
+ QVector3D v(1 - p.x() / (0.5*width()),
+ p.y() / (0.5*height()) - 1, 0);
+ QVector3D a = transform_matrix().inverted() *
+ view_matrix().inverted() * v;
+
+ if (event->delta() < 0)
+ {
+ for (int i=0; i > event->delta(); --i)
+ zoom *= 1.001;
+ }
+ else if (event->delta() > 0)
+ {
+ for (int i=0; i < event->delta(); ++i)
+ zoom /= 1.001;
+ }
+
+ // Then find the cursor's GL position post-zoom and adjust center.
+ QVector3D b = transform_matrix().inverted() *
+ view_matrix().inverted() * v;
+ center += b - a;
+ update();