0
\$\begingroup\$

Before someone mark it duplicate - I am aware that there are few questions already on this topic but the explanations are all theoretical and no graphical elaboration was provided which I think will help in understanding these concepts better.

Coming to the query in hand, I assume LibGDX follows OpenGl definitions of GameWorld, Camera and ViewPorts - please correct me if I am wrong. Now when I am trying to understand these basic concepts of LibGDX, confusions are arising all around me. I am sure these concepts are not that hard to understand and I must be looking at the things in a wrong way. As per my understanding:

GameWorld Dimensions: This is the dimension of the GameWorld that I have created, perhaps a Tiled map or some background which will be showing to the player. Lets assume the GameWorld dimension is 4096 x 4096 px.

Camera Dimensions: This is the dimension of the Camera that I would like to show to the user at a time. It could be 800x480 px or 320x240 px or whatever I want. When set, user will only be able to see that part of the GameWorld at a time.

ViewPort Dimensions: I have absolutely no clue how this works!

And my queries are: (Please explain with image/graphics for better clarity)

a. How is ViewPort related to Camera?

b. Is Camera a part of ViewPort or is it vice-versa?

c. Can Camera dimensions be different than that of ViewPort? eg: Can camera be 800x480 px whereas Viewport 320x240 px or vice-versa?

d. When designing games for multiple screen densities/sizes, which is a better approach - Camera with standard dimensions (16/9 - 4/3 - 800x480) or ViewPort? If ViewPort then which is the best in such cases - Stretch/Fill/Fit/Expanded ?

\$\endgroup\$
2
  • \$\begingroup\$ I'm not sure what you mean by "graphical elaboration", most of these are just concepts, e.g. you can't draw a viewport \$\endgroup\$
    – Bálint
    Nov 13, 2017 at 13:23
  • \$\begingroup\$ By graphical elaboration I mean if someone can enlighten these concepts with GameWorld drawn as a rectangle or square on MS Paint or something simlar and then showing exactly what portion of the GameWorld will be covered in Camera dimension and how ViewPort affects it. \$\endgroup\$
    – Harry_S
    Nov 13, 2017 at 13:26

2 Answers 2

0
\$\begingroup\$

I'm not very good at drawing but I will give you my best shot at describing the relationships using analogies. This will not include technical descriptions since that has already been described elsewhere.

Game World

The game world is, well, the world. It's everything your game contains. The game world has no actual size, it is an infinite space containing whatever you put there.

Your idea of the game world is that it is like the Earth (limited size), while it is more like Space (infinite size). It just feels finite because you just use and see a small bit of it at a time.

Camera

The camera is your looking glass into the game world from outside. You can think of the camera as your eyes if you will. The "size" of the camera comes from how far to the sides we can see (aspect ratio) and how far we can see (view distance / clipping plane). It can also move around in the world.

Viewport

While the camera controls how much we see and what we are currently looking at the viewport is what we're looking through. The viewport is the only one that has an actual size. Think of the viewport as your TV-screen or computer monitor.

Conclusion

Final shot at an analogy:

  • The Game World is the real world. The part of the Game World that you see is the set of a movie with actors jumping around doing their things and interacting with objects.
  • The Camera is a camera filming the real world and the actors and objects in it, moving around to film at interesting angles. You can even change the camera when you need to film a different part of the world.
  • The Viewport is your TV or computer monitor. You use it to look at the movie that the Camera recorded of the Game World. By changing your TV you change how you see the movie. If you use a really wide TV there will be black bars at the edges because the movie does not occupy the entire width of the TV.
\$\endgroup\$
0
0
\$\begingroup\$

First of all, OpenGL doesn't have a definition for a camera or a game world, those are relatively high level.

A gameworld doesn't have dimensions (and even if it did, it certainly wouldn't be in pixels). It's pretty much infinite. Just because you put a 5x5 tilemap in it, it doesn't become finite.

Camera's don't have a resolution, only an aspect ratio and they technically don't even exist, the underlying APIs only render the stuff between (-1, -1, 0) and (1, 1, 1), the engine's job is to put the relevant things in this range by transforming them. They are basically a matrix projecting the coordinate in a cone shaped frustum into a box shaped one:

Camera frustum

Viewport is just a part of your screen the underlying API renders to, this is the only thing, that has a resolution from your question. It's not related to the camera in any way apart from being in the same graphics pipeline. It's usually the same aspect ratio as the camera to keep the image from stretching, but it's not required.

It's definitely a bad way to solve the different aspect ratio problem by stretching or expanding the image or by filling the remaining parts with black. You can simply set the camera to have an aspect ratio, that fits to the window.!!!

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .