Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
QOpenGLWidget - Rotation and Zoom in and Out
Lays147 last edited by
I managed to create a cube in 3D with the widget, but now I need to do their rotation and zoom. I've read the examples hellogl2 and cube, but did not help me much. Like that with the right and left mouse buttons to rotate power projection and scroll to zoom in and out.
The examples I have seen on the internet are with glut, but the qt is supported so I do not use this library.
Can anyone give me a hand?
For example, i already try do this, but not change.
void GLWidget::mousePressEvent(QMouseEvent *event)
if(event->button() == Qt::RightButton)
camera.translate(0, 0, -1);
timday last edited by
@Lays147 How much do you know about vectors, matrices and basic linear algebra type things? In my day, everyone learned computer graphics geometry, homogeneous coordinates etc from a book called Foley & van Damme; but it's probably a bit out of date now and been replaced by something else as the standard undergrad graphics text. If your program has a vertex shader, and you can pass a transform matrix to it, and the shader multiplies vertex coordinates by the matrix... then you can just multiply the transforms you want together and pass them as a single transform.
The earlier bits of ftp://ftp.informatik.hu-berlin.de/pub/Linux/Qt/QT/developerguides/qtopengltutorial/OpenGLTutorial.pdf is pretty good QMatrix4x4-friendly intro, even if the OpenGL (and the Qt) is old-school (although it does use shaders, and VBOs later on).
stephane78 last edited by
for the rotation, you should look at this example :http://doc.qt.io/qt-5/qtgui-openglwindow-example.html.
and for the knowledge of modern Opengl(>=3.3) you should read http://learnopengl.com/ and you can read http://learnopengl.com/#!Getting-started/Hello-Triangle to understand VAO and VBO...