OpenGL 模型视图混乱

发布于 2024-12-08 05:20:45 字数 510 浏览 0 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

じ违心 2024-12-15 05:20:45

在新创建的 OpenGL 上下文中,所有矩阵都是恒等的,即向量未经变换。在固定函数中,OpenGL 顶点变换跳过“世界”步骤,将对象→世界和世界→眼睛折叠为单个变换。不过,这没什么大不了的。无论如何,照明计算在眼睛空间中是最简单的。由于固定函数 OpenGL 不知道着色器(除了作为扩展),因此无需在世界空间中执行操作。

glTranslate、glRotate、glScale 不变换对象。他们操纵堆栈顶部的矩阵进行活动。因此最终它们对变换做出了贡献,但不是在对象上,而是在顶点(位置)级别上。

它会根据平移将立方体从眼睛空间的中心移动?

确实如此,但“移动”(实际上是变换)的是立方体的顶点;它可能不仅仅是翻译。

根据评论进行编辑

要理解的关键是转换组合。首先也是最重要的,变换是映射。

T: R^4 -> R^4, v' = v |-> T(v)

变换有一个子集,即可以用矩阵乘法表示的线性变换:

v' = T * v

可以连接变换,即 v = v |-> T'○T (v) 再次表示线性变换的子集,以矩阵形式编写,您可以将其扩展为

v' = T * v
v'' = T' * v'

=>

v'' = T' * T * v

现在让 V 表示查看变换,W 表示> 世界发生转变。所以总的变换是

M = V * W

矩阵乘法的顺序很重要(即矩阵乘法不可交换):

∃ M, N ∊ {Matrices}: M * N ≠ N * M

视图变换 V 是整个世界的变换,以便它以某种方式移动,即相机世界最终位于原点,从负 Z 轴往下看。因此,让 V' 为将“相机”从其在世界中的位置的原点移动的变换,该运动的逆过程以相机静止在原点的方式移动世界。 ,

V = inv(V')

最后但并非最不重要的一点是,给出一些矩阵 A、B、C,它们成立

A = B * C

inv(A) = inv(C) * inv(B)

运算顺序相反。因此,如果您使用逆 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.

it would move the cube from center of the eye space according to the translation?

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

T: R^4 -> R^4, v' = v |-> T(v)

There's a subset of transformation, namely the linear transformations which can be represented by matrix multiplication:

v' = T * v

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 to

v' = T * v
v'' = T' * v'

=>

v'' = T' * T * v

Now let V denote the viewing transform and W the world transform. So the total transform is

M = V * W

The order of matrix multiplication matters (i.e. matrix multiplication is not commutative):

∃ M, N ∊ {Matrices}: M * N ≠ N * M

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 let V' 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. So

V = inv(V')

Last but not least given some matrices A, B, C for which holds

A = B * C

then

inv(A) = inv(C) * inv(B)

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文