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

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

问题描述

这篇文章与之前想学习如何在 LIBGDX 和 Box2D 之间正确渲染的文章有关.在继续之前,我必须充分了解视口.
经过大量代码/帖子阅读后,我觉得视口"的含义是查看LIBGDX游戏世界的相机镜头的矩形开口,我可以在其中移动它以查看我想要的东西".但是,经过更多阅读,我似乎与实际意思相去甚远.
我已经阅读了 LIBGDX wiki,并阅读了 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 维基:

视口是投影3D场景的屏幕的矩形观看区域.它只不过是将3维对象映射到2维平面."

"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."

堆栈溢出:

"...它在不同的上下文中有几个定义..." :'(

"...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.

什么是 LIBGDX 上下文中的视口"?

What is "viewport" in LIBGDX context?

推荐答案

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

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".

这个类管理两件事:

  • 相机的视口
  • OpenGL 视口

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

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.

OpenGL 视口定义了相机视图应映射到的区域.默认情况下,视口是桌面操作系统上窗口大小的 100%.但这也可能不同.带有 LibGDX 1.0.0 的 FitViewport 可以缩放该视口,使其保持您定义的虚拟视口"的纵横比(实际上是相机的视口,由 视口类).这意味着如果窗口的纵横比与 Viewport(虚拟)纵横比不匹配,OpenGL 视口将被设置为更小的尺寸并且会出现黑条.因此,您可以将其视为桌面上实际窗口和相机之间的另一层.该层获取相机的输出并将其缩放到桌面窗口中定义的大小.

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天全站免登陆