【发布时间】:2019-02-12 13:15:20
【问题描述】:
当窗口的resize事件被调用时,对象被移出视口/屏幕。
下面的链接是一个视频,展示了正在发生的事情: https://drive.google.com/file/d/1dBnOqBDUBNCQrwr7ChFlpS8vbBQ6wfKh/view?usp=sharing
我刚刚发现它只是在使用 QT Windowing 时发生。 GLFW 并没有发生这种情况... wooow
我使用以下代码:
void Renderer::resize(int width, int height) {
RendererSettings* settings = RendererSettings::getInstance();
settings->setSize(width, height);
glViewport(0, 0, width, height);
if (camera != nullptr)
{
float aspectRatio = float(width) / float(height);
camera->updateProjectionPerspectiveAspect(aspectRatio);
}
}
我不再更换相机了。
updateProjectionPerspectiveAspect 与 glFrustum(FoV, aspect, near, far) 相同。但其他参数的数据保持不变。
void Camera::setProjectionPerspective(float fieldOfView, float aspectRatio, float near, float far) {
this->fieldOfView = fieldOfView;
this->aspectRatio = aspectRatio;
this->nearFrustum = near;
this->farFrustum = far;
float xmin, xmax, ymin, ymax; // Dimensions of near clipping plane
float xFmin, xFmax, yFmin, yFmax; // Dimensions of far clipping plane
// Do the Math for the near clipping plane
ymax = near * tanf(float(fieldOfView * PI_DIV_360));
ymin = -ymax;
xmin = ymin * aspectRatio;
xmax = -xmin;
// Construct the projection matrix
projectionMatrix = Mat4f::identity();
projectionMatrix[0] = (2.0f * near) / (xmax - xmin);
projectionMatrix[5] = (2.0f * near) / (ymax - ymin);
projectionMatrix[8] = (xmax + xmin) / (xmax - xmin);
projectionMatrix[9] = (ymax + ymin) / (ymax - ymin);
projectionMatrix[10] = -((far + near) / (far - near));
projectionMatrix[11] = -1.0f;
projectionMatrix[14] = -((2.0f * far * near) / (far - near));
projectionMatrix[15] = 0.0f; }
- Camera 参数不为空,并且在调整大小期间会调用此事件“resize”。参数宽度和高度是正确的。
【问题讨论】:
-
您好,您使用的不是普通的 OpenGL,您有某种额外的 API 覆盖它。请指定您的工具,或者如果您不知道,请向我们展示您的工具
-
嗨,您记录了
width和height的值吗?他们是正确的吗?此外是cameranull还是ifbranch 被执行? -
@tomerzeitune updateProjectionPerspectiveAspect 与 glFrustum 相同。在OpenGL ES中没有用到,所以上面的代码是OpenGL。
-
@bitflip-at 参数正确,摄像头不为空。我只更新投影矩阵相机。
-
@Bruno 这是 openGL ES 吗?我不明白这个相机类是什么。
标签: opengl