LIBGDX:什么是“视口”? [英] LIBGDX: What is a "viewport"?

查看:209
本文介绍了LIBGDX:什么是“视口”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这篇文章涉及到想要学习如何在LIBGDX和Box2D之间正确呈现的早期文章。

经过大量的代码/阅读后,我觉得视口的含义是相机镜头的矩形开口,可以看到LIBGDX的游戏世界,在那里我可以将它移动到世界上来查看我想要的东西。但是,在阅读更多内容之后,我似乎远不及实际意义。

我已经阅读了LIBGDX wiki,并阅读了OpenGL文档,这些文档似乎将视口解释为两种不同的东西。



LIBGDX Wiki:


视口是一个矩形的可视区域屏幕显示三维场景的投射点,只不过是将三维物体映射到二维平面。


OpenGL:


视口指示场景映射到的可用屏幕区域的形状。

Stackoverflow:


.. 。(


我尝试阅读数十篇论坛帖子和教程。但不幸的是,几乎每个人都跳入其中,就好像视口是一个每个人都能理解并知道的原始概念。

我知道我会为这个最基本的问题获得大量的热量,请不要火焰,我问,因为我其实并不需要帮助。



无论如何,进入实际的问题。



什么是LIBGDX上下文中的viewport?

解决方案

这取决于您使用的LibGDX版本。 LibGDX 1.0.0引入了 Viewport 类,可能这是最新的教程和文章的意思,当他们谈论视口时。 p>

这个类管理两件事:


  • 相机的视口

  • OpenGL视口



相机的视口定义了您希望看到的游戏世界的多少。如果您有一个大小为10000px X 10000px的巨大 TiledMap ,那么您可能只想立即显示该地图的一个小区域。如果您将相机视口定义为800px X 480px,那么您将看到地图的一部分恰好具有此维度(至少在 OrthographicCamera 的情况下)。它就像一个窗口,通过它来查看你的世界,并通过视口定义它的大小。



OpenGL视口定义相机视图应该被映射到。默认情况下,该视口是桌面操作系统上窗口大小的100%。但是,这也可能不同。使用LibGDX 1.0.0的 FitViewport 可以缩放该视口,使其保持您定义的虚拟视口的纵横比(这实际上是相机的视口,即由 Viewport 类管理)。这意味着如果窗口的宽高比与 Viewport (虚拟)宽高比不匹配,则OpenGL视口将设置为较小的大小,并且会出现黑条。因此,您可以将它想像为桌面上的实际窗口和相机之间的另一层。此图层取得您相机的输出,并在您的桌面窗口中将其缩放至所定义的大小。


This post is related to an earlier post of wanting to learn how to properly render in between LIBGDX and Box2D. I had to understand viewport well before I could proceed.
After much code/post readings, I felt the meaning of "viewport" was "the rectangle opening of a lens of the camera that views LIBGDX's Game world, where I can move it about the world to view what I want". But, after more reading, I seemed to be nowhere near the actual meaning.
I've read the LIBGDX wiki, and read in the OpenGL documentation, which seem to explain viewport as being two different things.

LIBGDX Wiki:

"The viewport is a rectangular viewing region of the screen where the 3D scene is projected. It is nothing more than mapping the 3 dimensional objects to the 2 dimensional plane."

OpenGL:

"the viewport indicates the shape of the available screen area into which the scene is mapped."

Stackoverflow:

"...It has several definitions in different contexts..." :'(

I've tried reading tens of forum posts and tutorials. But, unfortunately almost everybody jumps right into it as if "viewport" is such a primitive concept that everyone understands and knows.
I know I will get lots of heat for this utterly basic question. Please don't flame, I am asking because I actually don't know and actually need help.

Anyway, into the actual question.

What is "viewport" in LIBGDX context?

解决方案

That depends on the version of LibGDX you are using. With LibGDX 1.0.0 the Viewport class was introduced and probably that's what the latest tutorials and articles mean, when they talk about "viewports".

This class manages two things:

  • The viewport of a camera
  • The OpenGL viewport

The viewport of a camera defines how much you want to see of your game world. If you have a huge TiledMap of the size 10000px X 10000px, then you probably only want to show a small area of that map at once. If you define your cameras viewport to be 800px X 480px, then you will see a part of your map which has exactly this dimension (at least in the case of an OrthographicCamera). It is like a window through which you look through your world and you define the size of it via the viewport.

The OpenGL viewport defines the area to which the camera's view should be mapped to. By default that viewport is 100% of the size of your window on desktop operating systems. But that could also be different. A FitViewport with LibGDX 1.0.0 can scale that viewport so that it keeps the aspect ratio of a "virtual viewport" which you define (which is actually the camera's viewport, which is being managed by the Viewport class). That means in case the window's aspect ratio doesn't match the Viewport (virtual) aspect ratio, the OpenGL viewport will be set to a smaller size and black bars will appear. So you can think of it like another layer between the actual window on your desktop, and the camera. This layer takes the output of your camera and scales that to the defined size within your desktop window.

这篇关于LIBGDX:什么是“视口”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆