我不明白这个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和glTranslatef。
经过一些搜索后,它似乎存在一种制造这种东西的方法:
glRotatef();
glRotatef();
glTranslatef(5.0,15.0,2.0);
glRotatef();
glRotatef();
glTranslatef(5.0,0.0,5.0);所以只用两次旋转和一次转换。但是我不明白我怎么能找到这些旋转的角度和轴。
发布于 2015-02-28 18:46:55
我试着解释了下面这些函数是如何工作的。希望它能让你理解这个概念。对于旋转和平移,您可以检查此链接是如何处理的。
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
}https://stackoverflow.com/questions/28781948
复制相似问题