我有以下代碼:廣東話加載和保存矩陣的Opengl
void setupCamera() {
// Clear the screen buffer
glClear(GL_COLOR_BUFFER_BIT);
// reset the projection matrix //
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
// and set the perspective with the current field of view,
// and the current height and width
gluPerspective(fov, ratio, objDepth - objRadius * 2,
objDepth + objRadius * 2);
glViewport(0, 0, WINDOW_SIZE, WINDOW_SIZE);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
if(first){
glMultMatrixf(rotMatrix);
}
first = true;
//translate everything to be in objDepth//
glTranslatef(initX * 0.01, initY * 0.01, (-1) * objDepth);
glRotatef(200 * angle, rotationVector[0], rotationVector[1],
rotationVector[2]);
glutWireTeapot(1.5);
glGetFloatv (GL_MODELVIEW_MATRIX, rotMatrix);
}
旋轉矢量保持旋轉軸,
翻譯用於所有移動到正確的位置。
的事情是,我爲了使用上次保存的矩陣現在用glMultMatrixf
,
做旋轉,然後平移,然後用glGetFloatv
再次保存矩陣。
這個功能不斷呼籲與計時器,但由於某些原因
我想不通,矩陣不會保存任何東西,總是被初始化一遍又一遍,
意味着旋轉總是與使用小角度(因爲矩陣沒有保存)。
保存的矩陣未在代碼中的其他任何地方使用。
任何想法的?
難道你不想使用glLoadMatrix而不是多矩陣嗎?另外,顯示如何構建GLfloat數組。另外你爲什麼要做getFloat等?你爲什麼不使用數學庫來處理矩陣乘法?像這樣從OpenGL推動和獲取東西會導致速度放慢。甚至使用GLpush/pop。 – zero298
它使用glGetFloatv, 後第一次初始化,然後'first'布爾變量是'true',並可以加載和乘以矩陣 – Itzik984