我昨天更新了我的問題,希望有人澄清這個問題!opengl相機的執行是正確的?
當應用俯仰偏航輥(假設我們選擇這個順序)角度來實現空氣的相機,我想我們可以計算這樣的觀點矩陣:
而且還有點支持這種觀點如Using a camera and simple user input 和OpenGL Transformation,他們的代碼風格是這樣的:
// First, transform the camera (viewing matrix) from world space to eye space
// Notice all values are negated, because we move the whole scene with the
// inverse of camera transform
glRotatef(-roll, 0, 0, 1); // roll
glRotatef(-yaw, 0, 1, 0); //yaw
glRotatef(-pitch, 1, 0, 0); // pitch
glTranslatef(-cameraPosition[0], -cameraPosition[1], -cameraPosition[2]);
我相信這是正確的。
而Red book pilotView(7th edition),A C++ Camera Class for Simple OpenGL FPS Controls ,First Person Camera Control with LWJGL,Modern OpenGL 04 - Cameras, Vectors & Input 這樣的代碼風格:
glRotatef(roll, 0, 0, 1); // roll
glRotatef(yaw, 0, 1, 0); //yaw
glRotatef(pitch, 1, 0, 0); // pitch
glTranslatef(-cameraPosition[0], -cameraPosition[1], -cameraPosition[2]);
它將工作,並沒有影響多少用戶交互,但是從數學的角度來看,它是不是正確的。
爲什麼書和其他人選擇第二種代碼風格?請幫助澄清這個問題!
感謝您抽出時間來調查我的參考頁,減輕我的初學者的謎.Lloyd古道爾碼的glTranslatef異常別人,但他也做不同的東西在walkForward/walkBackwards方法來計算相機位置以使其工作。我更喜歡選擇第一種編碼風格。 – wangdq 2014-10-08 06:30:24