我昨天更新了我的问题,希望有人澄清这个问题!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