OpenGL 模型视图混乱
我正在使用 opengl 2.0 和固定功能管道。好像在opengl 2.0中 他们将顶点推入模型视图堆栈,这基本上是(视图矩阵 * 模型矩阵),其中模型矩阵不提供任何转换,实际上它带来了一个对象,比如一个以 (0,0,0 )如果模型视图矩阵加载了单位矩阵。相机本身也将位于(0,0,0),向下看负 z 轴。
因此,如果我对立方体使用翻译调用,我真的会在眼睛空间中移动立方体吗?
据我所知,广义的查看管道是
“顶点”->“顶点”。建模矩阵->世界空间,世界空间中的对象 ->查看矩阵->眼睛空间、眼睛空间物体 ->投影矩阵->剪切空间,然后标准化等
所以如果我切换到 模型视图矩阵 stack() 加载身份 () gltranslate(在负 z 方向向上 5 个单位) gldrawcube()
它会根据平移将立方体从眼睛空间的中心移动?
我认为我的困惑是,我不知道程序启动时加载到模型视图矩阵堆栈中的内容是什么,我认为它是一个单位矩阵,它将所有内容带到眼睛空间的中心。
I am using opengl 2.0 with the fixed function pipeline. It seems that in opengl 2.0
they push the vertices through the model-view stack which is basically (view matrix * model matrix), in which the model matrix doesn't provide any transformation really it brings an object say a cube to be centered at (0,0,0) if the model view matrix has a identity matrix loaded.Also the camera it self would be located at (0,0,0) looking down the negative z axis.
So if I use a translate call with the cube I am I really moving the cube in Eye space ?
From what I learned the generalized viewing pipeline is
Vertices -> Modelling Matrix -> World Space, Objects in World Space -> Viewing Matrix -> Eye Space, Eye Space Objects -> Projection Matrix -> Clipping Space , Then normalization ect
So If I switch to the
model view matrix stack()
loadidentity ()
gltranslate ( up 5 units in the negative z direction)
gldrawcube()
it would move the cube from center of the eye space according to the translation ?
I think my confusion is that I don't know what is loaded into the model view matrix stack when the program starts, I assume it is an identity matrix that brings everything to the centre of the eye space.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在新创建的 OpenGL 上下文中,所有矩阵都是恒等的,即向量未经变换。在固定函数中,OpenGL 顶点变换跳过“世界”步骤,将对象→世界和世界→眼睛折叠为单个变换。不过,这没什么大不了的。无论如何,照明计算在眼睛空间中是最简单的。由于固定函数 OpenGL 不知道着色器(除了作为扩展),因此无需在世界空间中执行操作。
glTranslate、glRotate、glScale 不变换对象。他们操纵堆栈顶部的矩阵进行活动。因此最终它们对变换做出了贡献,但不是在对象上,而是在顶点(位置)级别上。
确实如此,但“移动”(实际上是变换)的是立方体的顶点;它可能不仅仅是翻译。
根据评论进行编辑
要理解的关键是转换组合。首先也是最重要的,变换是映射。
变换有一个子集,即可以用矩阵乘法表示的线性变换:
可以连接变换,即 v = v |-> T'○T (v) 再次表示线性变换的子集,以矩阵形式编写,您可以将其扩展为
现在让
V
表示查看变换,W
表示> 世界发生转变。所以总的变换是矩阵乘法的顺序很重要(即矩阵乘法不可交换):
视图变换 V 是整个世界的变换,以便它以某种方式移动,即相机世界最终位于原点,从负 Z 轴往下看。因此,让
V'
为将“相机”从其在世界中的位置的原点移动的变换,该运动的逆过程以相机静止在原点的方式移动世界。 ,最后但并非最不重要的一点是,给出一些矩阵 A、B、C,它们成立
即
运算顺序相反。因此,如果您使用逆 OpenGL 矩阵运算“定位”“相机”,则必须颠倒运算顺序。由于操作的整体顺序很重要,因此视图转换必须在模型转换之前发生。
In a newly created OpenGL context all matrices are identity, i.e. vectors go through untransformed. In fixed function OpenGL vertex transformation skips the "world" step, collapsing object→world and world→eye into a single transformation. This is no big deal however. Lighting calculations are easiest in eye space anyway. And since fixed function OpenGL doesn't know shaders (except as extension), there's no need to do things in world space.
glTranslate, glRotate, glScale don't transform objects. They manipulate the matrix on top of the stack active for manipulation. So ultimately they contribute to the transformation, but not on the object, but the vertex (position) level.
Indeed, but what's "moved" (actually transformed) are the cube's vertices; and it may be not just a translation.
EDIT due to comment
The key thing to understand is transformation composition. First and foremost a transformation is a mapping
There's a subset of transformation, namely the linear transformations which can be represented by matrix multiplication:
one can concatenate transformations, i.e.
v = v |-> T'○T (v)
again for the subset of linear transformations, written in matrix form you can expand this toNow let
V
denote the viewing transform andW
the world transform. So the total transform isThe order of matrix multiplication matters (i.e. matrix multiplication is not commutative):
The view transform
V
is the transform of the whole world so that it is moved in a way, that the camera in the world ends up being at the origin, viewing down the negative Z axis. So letV'
be the transform that moves "the camera" from the origin at it's place in the world, the inverse of that movement moves the world in a way that the camera comes to rest at the origin. SoLast but not least given some matrices A, B, C for which holds
then
i.e. the order of operations reversed. So if you "position" your "camera" using inverse OpenGL matrix operations, the order of the operations must be reversed. And since the overall order of operation matters the viewing transformations must happen before the model transformations.