简体   繁体   English

OpenGL glLookAt用于任意视点

[英]OpenGL glLookAt for an arbitrary viewpoint

I am computing a model centroid using the min max vertex values, for all objects in the scene and now I want to rotate and look at it from an arbitrary viewpoint looking at the centroid. 我正在针对场景中的所有对象使用最小最大顶点值来计算模型质心,现在我想旋转并从任意角度查看质心来对其进行查看。

Has someone does this with glLookAt() ? 有人用glLookAt()做这个吗? I am using Perspective mode. 我正在使用透视模式。

Look at the docs for gluLookAt(). 查看有关gluLookAt()的文档。 What you want to do is exactly what this function does. 您要执行的操作正是此功能执行的操作。 gluLookat creates the View matrix, so it should be: gluLookat创建视图矩阵,因此应为:

glMatrixMode(GL_MODELVIEW); 
glLoadIdentity();
gluLookAt(eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ);

The projection matrix sets the clipping planes: 投影矩阵设置裁剪平面:

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(left, right, bottom, top, near, far);

or 要么

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(fovDegrees, aspectRatio, near, far);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM