[英]Qt OpengL - Rotation of a 3D fixed scene
I am working on a Qt/GPU/OpenCL code with OpenGL rendering. 我正在使用OpenGL渲染处理Qt / GPU / OpenCL代码。 It performs an animation of a 3D scene and I succeed in rotating this 3D scene with mouse while the animation. 它执行3D场景的动画,并且在动画时我成功地用鼠标旋转了3D场景。 But the rotation doesn't work when I do a pause of the animation, ie when the 3D scene is "fixed". 但是,当我暂停动画时,即3D场景“固定”时,旋转不起作用。
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. 因此,在执行“暂停”之前,应该像最后动画的快照一样,然后旋转,最后从最后一个3D旋转的场景重新开始动画。
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 : 这是QTimer调用的主要显示函数“ processCurrent()
”,其中"draw()"
包含OpenGL函数,当我暂停时animation
设置为false
:
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 and runCLKernels
does animation this should work: 您仍然需要绘制场景,如果draw()
仅执行绘制操作而没有动画操作,并且runCLKernels
动画,则这应该起作用:
if(animation)
{
//same as before...
}
else
{
// I don't know whether or not you would still call WaitForEvents...
draw();
printStats();
// Do NOT calculate subsequent positions, just use what was calculated last time.
glFlush();
swapBuffers();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.