OpenGL改变坐标系的测量单位

发布于 2024-12-04 04:49:25 字数 293 浏览 1 评论 0原文

我正在使用最新的蓝皮书学习 OpenGL,我希望得到澄清。书中说您可以使用任何测量系统作为坐标系,但是在进行 3D 透视编程时,世界坐标为 +1/-1。

我想我有点困惑的地方是,我想用英尺和英寸来表示我的世界,并且我想建造我房子的内部。我是否只使用翻译(x(英尺),y(英尺),z(英尺)),额外,或者是否有一些函数可以改变你的x,y世界坐标(即将默认值从-1/+1更改为让比如说(-20/20)。我知道 openGl 会转换剩下的所有单位。

所以我想我最大的知识差距是如何对现实世界的对象(长度)进行建模以使其在 OPenGL 中有意义?

I'm learning OpenGL using the newest blue book, and I was hoping to get a point of clarification. The book says you can use any system of measurement for the coordinate system, however when doing 3d perspective programming, the world coordinates are +1/-1.

I guess where I am a little confused is lets say I want to use feet and inches for my world, and I want to build the interior of my house. Would I just use translates (x(feet), y(feet), z(feet)), extra, or is there some function to change you x,y world coordinates (i.e change the default from -1/+1 to lets say (-20/20). I know openGl converts everything unit left.

So i guess My biggest gap of knowledge is how to I model real world objects (lengths) to make sense in OPenGL?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

不弃不离 2024-12-11 04:49:25

我认为作者指的是透视分割之后出现的标准化坐标(设备坐标)。

通常,当您实际在 OpenGL 中操作对象时,您使用标准世界坐标,该坐标不限于 -1/+1。这些世界坐标可以是您喜欢的任何坐标,并通过乘以模型视图和投影矩阵然后除以齐次坐标“w”来转换为标准化坐标。

OpenGL 将为您完成所有这些工作(直到您进入着色器),因此不必真正担心标准化坐标。

I think the author is referring to normalized coordinates (device coordinates) that appear after the perspective divide.

Typically when you actually manipulate objects in OpenGL you use standard world coordinates which are not limited to -1/+1. These world coordinates can be anything you like and are translated into normalized coordinates by multiplying by the modelview and projection matrices then dividing by the homogeneous coordinate 'w'.

OpenGL will do all this for you (until you get into shaders) so don't really worry about normalized coordinates.

绝不服输 2024-12-11 04:49:25

好吧,这都是相对的。如果您将 1 个 OpenGL 单位设置为 1 米,然后在此基础上完美地按比例构建所有内容,那么您就拥有了所需的比例(即 10 米将是 10 个 openGL 单位,1 毫米将是 0.001 个 OpenGL 单位。

但是,如果您然后我们要引入一个模型,该模型的设计使得 1 OpenGL 单位 = 1 英尺,那么对象最终会变得大约 3 倍大,

当然您可以在各种方法之间进行更改,但到目前为止这是最好的方法。这是为了在将模型加载到引擎之前重新缩放模型。

Well its all relative. If you set 1 OpenGL unit to be 1 meter and then build everything perfectly to scale on that basis then you have the scale you want (ie 10 meters would be 10 openGL units and 1 millimeter would be 0.001 OpenGL units.

If, however, you were to then introduce a model that was designed such that 1 OpenGL unit = 1 foot then the object is going to end up being ~3 times too large.

Sure you can change between the various methods but by far the best way to do this is to re-scale your model before loading it into your engine.

池木 2024-12-11 04:49:25

...但是在进行 3D 透视编程时,世界坐标为 +1/-1。

说谁?也许您指的是剪辑空间,但这只是一个特殊的空间,其中所有坐标都是投影后的。

你的世界单位可以是任何东西。相关部分是如何预测这些内容。假设您有 90°FOV 的透视投影,近剪裁平面为 0.01,远剪裁平面为 10.0,二次方(为了简单起见)。然后,您进入世界的视图体积将解析为一个边长为 0.01 的矩形,并且靠近观察者的距离为 0.01,并在远处拉伸为 10.0,边长为 0.02。减小FOV,横向长度也会相应缩小。

然而,大约 0.01 到 10 范围内的坐标被投影到 +/-1 剪辑空间中。

因此,您可以选择与您的场景和所选单位相匹配的投影限制。

…however when doing 3d perspective programming, the world coordinates are +1/-1.

Says who? Maybe you are referring to clip space, however this is just one special space in which all coordinates are after projection.

You world units may be anything. The relevant part is, how those are projected. Say you have a perspective projection of 90°FOV, near clip plane at 0.01, far clip plane at 10.0, quadratic aspect (for simplicity). Then your view volume into the world will resolve a rectangle with side lengths 0.01 and 0.01 distance close to the viewer, and stretch to 10.0 in the distant with the 0.02 side lengths. Reduce the FOV and the lateral lenghts shrink accordingly.

Nevertheless, coordinates in about the range 0.01 to 10. are projected into the +/-1 clip space.

So it's up to you to choose the projection limits to match your scene and units of choice.

北方的韩爷 2024-12-11 04:49:25

标准化窗口坐标范围始终为 -1 到 +1。但它可以随心所欲地使用。
假设我们想要一个范围 -100 到 +100,然后将实际坐标除以 100。在这种情况下使用
仅限函数 glVertex2f 或 glVertex3f。
例如glVertex2f(10/100,10/100)。

Normalized window coordinate range is always -1 to +1. But it can be used as you wish.
Suppose we want a range -100 to +100 then divide actual coordinate with 100. In this case use
the function glVertex2f or glVertex3f only.
e.g. glVertex2f(10/100,10/100).

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