简体   繁体   English

在OpenGL中glRotate旋转相机或旋转世界轴还是旋转模型对象?

[英]does glRotate in OpenGL rotate the camera or rotate the world axis or rotate the model object?

I want to know whether glRotate rotates the camera, the world axis, or the object. 我想知道glRotate旋转相机,世界轴还是物体。 Explain how they are different with examples. 解释它们与示例的不同之处。

the camera 相机

There is no camera in OpenGL. OpenGL中没有摄像头。

the world axis 世界轴

There is no world in OpenGL. OpenGL中没有世界。

or the object. 或对象。

There are no objects in OpenGL. OpenGL中没有对象。

Confused? 困惑?


OpenGL is a drawing system, that operates with points, lines and triangles. OpenGL是一个绘图系统,使用点,线和三角形操作。 There is no concept of a scene or a world in OpenGL. OpenGL中没有场景或世界的概念。 All there is are vertices of which each has a set of attributes and there is the state of OpenGL which determines how vertices are turned into pixels. 所有的顶点都有一组属性,OpenGL的状态决定了顶点如何变成像素。

The very first stage of this process is getting the vertex positions within the viewport. 此过程的第一个阶段是获取视口中的顶点位置。 In the fixed function pipeline (ie without shaders), to get those, each vertex position if first multiplied with the so called "modelview" matrix, the intermediary result is used for lighting calculations and then multiplied with the "projection" matrix. 在固定功能管道(即没有着色器)中,为了获得这些,每个顶点位置如果首先乘以所谓的“模型视图”矩阵,则中间结果用于照明计算,然后乘以“投影”矩阵。 After that clipping and then normalization into viewport coordinates are applied. 在剪切之后,然后应用归一化到视口坐标。

Those two matrices I mentioned save two purposes. 我提到的那两个矩阵有两个目的。 The first one "modelview" is used to apply some transformation on the incoming vertices so that those end up in the desired spot relative to the origin. 第一个“模型视图”用于对输入顶点应用一些变换,以使它们最终位于相对于原点的所需位置。 There is no difference in first moving geometry to some place in the world, and then moving the viewpoint within the world. 第一个移动几何体与世界某个地方没有区别,然后在世界范围内移动视点。 Or keeping the viewpoint at the origin and move the whole world in the opposite. 或者将观点保持在原点并使整个世界相反。 All this can be described by the modelview matrix. 所有这些都可以通过modelview矩阵来描述。

The second one "projection" works together with the normalization process to behave like a kind of "lens", so to speak. 第二个“投影”与标准化过程一起工作,表现得像一种“镜头”,可以这么说。 With this you set the field of view (and a few other parameters, like shift, which you need for certain applications – don't worry about it). 通过这种方式,您可以设置视野(以及一些其他参数,例如shift,您需要某些应用程序 - 不必担心它)。

The interesting thing about matrices is, that they're non-commutative, ie for two given matrices N, M 关于矩阵的有趣之处在于,它们是非交换的,即对于两个给定矩阵N,M

M * N =/= N * M ; for most M, N

This ultimately means, that you can compose a series of transformations A, B, C, D... into one single compound transformation matrix T by multiplying the primitive transformations onto each other in the right order. 这最终意味着,您可以通过将原始变换以正确的顺序相互相乘,将一系列变换A,B,C,D ...组合成单个复合变换矩阵T.

The OpenGL matrix manipulation functions (they're obsolete BTW), do just that. OpenGL矩阵操作函数(它们已经过时BTW)就是这样做的。 You have a matrix selected for manipulation (the matrix mode) for example the modelview M. Then glRotate effectively does this: 你有一个选择用于操作的矩阵(矩阵模式),例如modelview M.然后glRotate有效地执行此操作:

M *= R(angle,axis)

ie the active matrix gets multiplied on a rotation matrix constructed from the given parameters. 即,有源矩阵在由给定参数构造的旋转矩阵上相乘。 Similar for scale and translate. 类似于规模和翻译。

If this happens to appear to behave like a camera or placing a object depends entirely on how and in which order those manipulations are combined. 如果这似乎表现得像一个相机或放置一个对象完全取决于这些操作的组合方式和顺序。

But for OpenGL there are just numbers/vectors (vertex attributes), which somehow translate into 2-dimensional viewport coordinates, that get drawn as points for filled inbetween as line or a triangle. 但是对于OpenGL,只有数字/矢量(顶点属性),它们以某种方式转换为2维视口坐标,它们被绘制为填充在线之间的点或三角形。

glRotate works on the current matrix. glRotate适用于当前矩阵。 So it depend if the matrix is the camera one or a world trasformation one. 因此,它取决于矩阵是相机还是世界变形。 To know more about the current matrix have a look at glMatrixMode() . 要了解有关当前矩阵的更多信息,请查看glMatrixMode() Finding example is just googling: I found this one that in order to me should help you to figure out what's happening. 寻找例子只是谷歌搜索: 我发现这个 ,为了我应该帮助你弄清楚发生了什么。

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

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