【发布时间】:2016-07-21 17:25:21
【问题描述】:
我在使用 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);
}
【问题讨论】:
-
你的着色器真的在使用投影矩阵吗?