我在使用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);
}
您的着色器實際上是否使用投影矩陣? –