【发布时间】:2012-11-24 23:18:38
【问题描述】:
我有以下代码:
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);
}
旋转向量持有旋转轴,
translate 用于将所有内容移动到正确的位置。
问题是,我使用glMultMatrixf 是为了使用最后保存的矩阵,
先旋转再平移,然后用glGetFloatv再次保存矩阵。
这个函数经常被定时器调用,但是出于某种原因
我想不通,矩阵不会保存任何东西,总是一遍又一遍地初始化,
意思是旋转总是用小角度(因为矩阵没有保存)。
保存的矩阵没有在代码中的其他任何地方使用。
有什么想法吗?
【问题讨论】:
-
你不想使用 glLoadMatrix 而不是 multmatrix 吗?另外,展示如何构造 GLfloat 数组。另外你为什么要做getFloat之类的?你为什么不使用数学库来处理矩阵乘法?像这样从 OpenGL 推送和获取东西会导致速度变慢。甚至使用 GLpush/pop。
-
使用glGetFloatv后第一次初始化,之后
first布尔变量为true,可以加载并乘以矩阵