QOpenGLWidget - Rotation and Zoom in and Out



  • Hello guys!
    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?
    thanks!

    For example, i already try do this, but not change.
    QMatrix4x4 camera;
    void GLWidget::mousePressEvent(QMouseEvent *event)
    {
    if(event->button() == Qt::RightButton)
    {
    qDebug() <<"HERE!";
    camera.translate(0, 0, -1);
    update();

    }


  • @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).



  • Hi,
    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...
    regards


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.