I am working on a Qt/GPU/OpenCL code with OpenGL rendering. It performs an animation of a 3D scene and I succeed in rotating this 3D scene with mouse while the animation. But the rotation doesn’t work when I do a pause of the animation, i.e when the 3D scene is “fixed”.
here’s the two functions for the rotation with mouse :
void GLWidget::mousePressEvent(QMouseEvent *event)
{
lastPos = event->pos();
}
void GLWidget::mouseMoveEvent(QMouseEvent *event)
{
float dx = (event->y() - lastPos.y()) / 10.0f;
float dy = (event->x() - lastPos.x()) / 10.0f;
float dz = 0.0f;
float angle = sqrtf((event->x() - lastPos.x()) + (event->y() - lastPos.y()));
if (event->buttons() & Qt::LeftButton) {
angle = sqrtf(dx*dx + dy*dy);
glRotatef(0.1*angle, dx, dy, dz);
}
}
When the animation is on “pause”, I would like to be able to rotate the fixed scene and when I push the “restart” button, I would like the animation restarts with the last modified image done by the rotation of the scene.
So, this should be, before to do “pause”, like a snapshot of the last animation, then the possiblity to rotate, and finally, restart the animation from the last 3D rotated scene.
Here’s my main display function “processCurrent()” called by a QTimer and where "draw()" contains OpenGL functions and animation is set to false when I do a pause :
void GLWidget::processCurrent()
{
if (Galaxy->isFirstLaunch)
{
draw();
printStats();
//Calling kernel for calculatig subsequent positions
Galaxy->runCLKernels();
Galaxy->isFirstLaunch = false;
glFlush();
swapBuffers();
}
if (animation)
{
clWaitForEvents(1, &Galaxy->glEvent);
draw();
printStats();
//Calling kernel for calculatig subsequent positions
Galaxy->runCLKernels();
glFlush();
swapBuffers();
}
}
Could you explain me why this rotation doesn’t work with a fixed scene ?
you still need to draw the scene, if
draw()only does draw operations and no animation operations andrunCLKernelsdoes animation this should work: