理解 glm::lookAt()

Understanding glm::lookAt()(理解 glm::lookAt())
本文介绍了理解 glm::lookAt()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在按照 教程 学习 OpenGL,他们在其中使用了 glm::lookAt() 函数来构建视图,但我无法理解 glm::lookAt() 的工作原理,而且显然没有 GLM 的详细文档.任何人都可以帮我了解 glm::lookAt() 的参数和工作吗?

I am following a tutorial to learn OpenGL in which they used glm::lookAt() function to build a view but I cannot understand the working of glm::lookAt() and apparently, there is no detailed documentation of GLM. Can anyone help me understand the parameters and working of glm::lookAt() please?

GLM 文档说:

detail::tmat4x4<T> glm::gtc::matrix_transform::lookAt   
(   
    detail::tvec3< T > const &  eye,
    detail::tvec3< T > const &  center,
    detail::tvec3< T > const &  up 
)

我目前的理解是摄像头位于eye,面向center.(而且我不知道 up 是什么)

My current understanding is that camera is located at eye and is faced towards center. (And I don't know what the up is)

推荐答案

up 向量基本上是一个定义世界向上"方向的向量.在几乎所有正常情况下,这将是向量 (0, 1, 0) 即朝向正 Y.eye 是相机视点的位置,center 是您正在查看的位置(一个位置).如果你想使用方向向量D代替中心位置,你可以简单地使用eye + D作为中心位置,其中D例如可以是单位向量.

The up vector is basically a vector defining your world's "upwards" direction. In almost all normal cases, this will be the vector (0, 1, 0) i.e. towards positive Y. eye is the position of the camera's viewpoint, and center is where you are looking at (a position). If you want to use a direction vector D instead of a center position, you can simply use eye + D as the center position, where D can be a unit vector for example.

至于内部工作原理,或者更多细节,这是构建视图矩阵的常见基本功能.尝试阅读 gluLookAt() 的文档,它在功能上是等效的.

As for the inner workings, or more details, this is a common basic function for building a view matrix. Try reading the docs for gluLookAt() which is functionally equivalent.

这篇关于理解 glm::lookAt()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Prevent class inheritance in C++(防止 C++ 中的类继承)
Why should I declare a virtual destructor for an abstract class in C++?(为什么要在 C++ 中为抽象类声明虚拟析构函数?)
Why is Default constructor called in virtual inheritance?(为什么在虚拟继承中调用默认构造函数?)
C++ cast to derived class(C++ 转换为派生类)
C++ virtual function return type(C++虚函数返回类型)
Is there any real risk to deriving from the C++ STL containers?(从 C++ STL 容器派生是否有任何真正的风险?)