OpenGl GluLookAt到GluRotated和GluTranslated
我不明白这个GluLookAt在OpenGl中是如何工作的 我想知道如何转换这两行:OpenGl GluLookAt到GluRotated和GluTranslated,opengl,Opengl,我不明白这个GluLookAt在OpenGl中是如何工作的 我想知道如何转换这两行: gluLookAt(5.0, 15.0, 2.0, 0.0, 0.0, 0.0, 1.0, 0.0, -1.0); gluLookAt(5.0, 0.0, 5.0, 0.0, 0.0, 0.0, 1.0, -1.0, 0.0); 使用glRotatef和gltranslateef 经过一些搜索,似乎存在一种制作这种东西的方法: glRotatef(); glRotatef(); glTranslatef(5.
gluLookAt(5.0, 15.0, 2.0, 0.0, 0.0, 0.0, 1.0, 0.0, -1.0);
gluLookAt(5.0, 0.0, 5.0, 0.0, 0.0, 0.0, 1.0, -1.0, 0.0);
使用glRotatef和gltranslateef
经过一些搜索,似乎存在一种制作这种东西的方法:
glRotatef();
glRotatef();
glTranslatef(5.0,15.0,2.0);
glRotatef();
glRotatef();
glTranslatef(5.0,0.0,5.0);
所以只需使用两个旋转和一个平移。
但是我不明白如何才能找到这些旋转的角度和轴。我想避开glRotate和GLTRANSTATE,而是使用glLoadMatrix(如果要乘法,glLoadMatrix将替换堆栈上的当前矩阵使用glMultMatrix):然后,您将使用一个浮点数组,其中包含按列主顺序排列的矩阵:
xaxis.x yaxis.x zaxis.x 0
xaxis.y yaxis.y zaxis.y 0
xaxis.z yaxis.z zaxis.z 0
-dot(xaxis, camP) -dot(yaxis, camP) -dot(zaxis, camP) 1
在哪里
zaxis = normal(At - camP)
xaxis = normal(cross(Up, zaxis))
yaxis = cross(zaxis, xaxis)
然后将相机的位置放在相机所观察的点上,然后向上移动矢量。我试图解释下面的函数是如何工作的。希望它能让你理解这个概念。对于旋转和平移,可以检查其处理方式
struct Triple
{
float x,y,z;
}
//CameraPosition
Triple Cp(a,b,c); //initialise your camera position
//LookatPosition
Triple Lp(e,f,g); //initialise your lookat position
//Up vector
Triple Up(k,l,m); //initialise your up vector
UpdateCamera()
{
//Update Cp, Lp here
//if you move your camera use translatef to update camera position
//if you want to change looking direction use correct rotation and translation to update your lookat position
//if you need to change up vector simply change it to
Up = Triple(knew,lnew,mnew);
}
display()
{
gluLookAt(Cp.x,Cp.y,Cp.z,Lp.x,Lp.y,Lp.z,Up.x,Up.y,Up.z);
//Your object drawings Here
}
谢谢你的回答hakononakani,但我必须用glRotate和glTranslate做这件事。我不能使用其他任何东西:/它就像一个我无法打破的条件:(但下一次我必须做同样的事情时,我认为你的解决方案是好的。然而,这不是我想要的。我只能使用glRotate和glTranslate来完成这项工作。我不认为有理由这样做,除了锻炼任务,我不会为你做作业:)。如果你仍然坚持要看一看opengl崇敬页面(),那么其中的代码非常接近可复制粘贴。