gluOrtho2D 和 glViewport

发布于 2024-08-18 15:22:55 字数 223 浏览 3 评论 0原文

我有一个在世界坐标中定义的对象,比如说一个以 (2,3) 为中心、半径为 4 的圆。如果我希望圆不变形,在视口中完全可见,并且在视口内尽可能大,我如何制定 gluOrtho2D 命令来根据上述规格创建世界窗口,因为:

glViewport(20, 30, 1000, 500)?

我对整个视口与世界与屏幕等坐标感到困惑。有人可以引导我完成它吗?我真的很想掌握这个。

I have an object defined in world coordinates, say a circle centered at (2,3) with radius 4. If I want the circle to not be distorted, to be entirely visible in the viewport and to be as big as possible within the viewport, how can I formulate a gluOrtho2D command to create a world window based on the aforementioned specs given that:

glViewport(20, 30, 1000, 500)?

I am getting confused with the whole viewport vs world vs screen, etc coordinates. Can someone walk me through it? I really want to get the hang of this.

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

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

发布评论

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

评论(1

仅冇旳回忆 2024-08-25 15:22:55

在您的示例中,视口的宽度为 1000 像素,高度为 500 像素。因此,您需要指定具有相同纵横比 (2:1) 的 glOrtho 坐标。

您的圆的半径为 4 个单位,因此您需要至少 8 个单位高、8 个单位宽的视图。考虑到 2:1 的长宽比,我们将其设置为 16 个单位宽 x 8 个单位高。

中心位于 (2, 3)。因此,将这些 16 x 8 围绕您应该得到的中心:

glOrtho2D (2 - 8, 2 + 8, 3 - 4, 3 + 4);

即:

glOrtho2D (-6, 10, -1, 7);

这有效地将 -6 的 X 坐标映射到视口的左边缘。然后 glViewport 映射将其映射到屏幕上的实际位置。随着屏幕尺寸的变化,必须调整glOrtho2D坐标来补偿宽高比,但只要视口为2:1,这些glOrtho2D调用就不需要改变。

In your example, the viewport is 1000 pixels across by 500 pixels high. So you need to specify glOrtho coordinates that have the same aspect ratio (2:1).

Your circle is 4 units in radius, so you need a view that is 8 units high by 8 units wide atleast. Considering the 2:1 aspect ratio, let's make that 16 units wide by 8 units high.

The center is at (2, 3). So centering these 16 x 8 around that you should get:

glOrtho2D (2 - 8, 2 + 8, 3 - 4, 3 + 4);

That is:

glOrtho2D (-6, 10, -1, 7);

This effectively maps the X coordinate of -6 to the left edge of the viewport. The glViewport mapping then maps that to the actual location on the screen. As the screen size changes, you must adjust the glOrtho2D coordinates to compensate for the aspect ratio, but as long as the viewport is 2:1, these glOrtho2D calls will not need to change.

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