Rotating the scene in OpenGL using the mouse (Qt)

To study the material of the article "Rotating a Scene in OpenGL Using the Mouse", you first need to study the material of this article.

The idea is very simple - intercept the mouse event, determine the mouse pointer movement speed, and based on this, calculate the scene rotation angle. Essentially the same as in the previous example, but the rotation is not done by a timer, but by a mouse event (mouse movement with a pressed button).

Rotation of a scene in OpenGL (QT)

So, we already know how to initialize an OpenGL window in QT. (/podklyuchenie-opengl-v-qt/) Now let's learn how to rotate the scene. In short, to rotate the scene in OpenGL, you need to call the function void glRotated(GLdouble angle, GLdouble x, GLdouble y, GLdouble z). The angle parameter sets the rotation angle from the current position; x, y, z describe the rotation vector, in other words, they determine the direction of rotation. You can also change the position of the vector's origin.

Connecting OpenGL in QT

Let's consider an example of connecting the OpenGL graphics library to a QT project. I will try to provide the most accessible information for a quick start. Here we will only consider the example of connection and rendering of a simple scene. In the following notes, we will add camera rotation and so on.