gpt4 book ai didi

c++ - 使用 glOrtho 移动相机

转载 作者:行者123 更新时间:2023-11-28 05:35:06 24 4
gpt4 key购买 nike

我在使用 glOrtho 移动相机时遇到问题。我在中心有一个小四边形,我想尝试使用 glOrtho 移动相机,但它似乎不起作用。四边形根本不动,所以我猜相机也没有移动。也许我想念 glOrtho 的工作原理?到目前为止,这是我的代码。

void Camera::updateCamera(float x, float y, float zoom)
{
camX = x;
camY = y;
this->zoom = zoom;
viewWidth = 320;
viewHeight = 240;
//viewWidth = tan(60) * this->zoom;
//viewHeight = tan(45) * this->zoom;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(camX - viewWidth,
camX + viewWidth,
camY - viewHeight,
camY + viewHeight,
-1,
1);
glMatrixMode(GL_MODELVIEW);
}

这是我应用它的地方。我试图将它沿 x 轴移动 25 个点。

void Engine::renderAll()
{
x += 25;
glClear(GL_COLOR_BUFFER_BIT);
shader->use();
camera.updateCamera(x, y, 1.0);
//shader->setUniform4fv("view", camera.getView());
batchManager->renderBatches();
SDL_GL_SwapWindow(window);
}

最佳答案

是的,我想您误解了 glOrtho 的工作原理。 glOrtho 的作用是使用正交投影将 3D View 转换为 2D View 。

如果您想在 3D 空间中定位相机,正确的函数通常称为 LookAt。有一次,我觉得你使用的是旧的 OpenGL,你可以试试 glu 函数 gluLookAt

附言。在现代 openGL 中,此功能现已弃用。我建议你尝试学习现代的方式。

关于c++ - 使用 glOrtho 移动相机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38510658/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com