This Tutorial/Example shows a very simply implementation of the QGLWidget with the possibility to interact with the GLWidget by using the keyboard and the mouse.
The use of this application is very straightforward:
Keys:
[W] or [Arrow Up] = Move the triangle up
[S] or [Arrow Down] = Move the triangle down
[A] or [Arrow Left] = Move the triangle left
[D] or [Arrow Right] = Move the triangle right
[R] = Reset all values back to the standard value
Mouse
[Left mouse button] = Rotate the triangle on the “X-Axis” & “Y-Axis”
[Right mouse button] = Rotate the triangle on the “X-Axis” & “Z-Axis”
[Scroll wheel] = Move the triangle in and out
Methods
In addition to the necessary OpenGL methods (initializeGL, resizeGL, paintGL) the following methods are also needed to interact with the scene:
mousePressEvent << will be called when a button will be pressed
mouseMoveEvent << will be called when an active (button pressed) mouse will be moved
wheelEvent << will be called when the mouse scroll wheel will be used
keyPressEvent << will be called when a key will be pressed
and a helper method to save the result of the input:
setRotation << saves the rotation result
Parameters
The only things that this methods doo is changing the following parameters:
fRotationX >> set the rotation at the X-Axis
fRotationY >> set the rotation at the Y-Axis
fRotationZ >> set the rotation at the Z-Axis
fMoveLeftRight >> set the movement at the X-Axis
fMoveUpDown >> set the movement at the Y-Axis
fMoveInOut >> set the movement at the Z-Axis
sourececode: gl_mouse.zip
Much appreciated for the information and share!
Perfect information! I have been browsing for everything like that for a while these days. Thank you!