我在使用glOrtho移动摄像头时遇到问题。我在中心有一个小四边形,我想尝试用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);
}
您的着色器实际上是否使用投影矩阵? –