Camera/Tiles visibility

Started by
1 comment, last by SH code 13 years ago
Hello there,

I'm fairly new to game programming and, even though it's probably not the best idea, i've decided to try and build a 2D isometric engine as a first game programming project (with XNA). Probably not the easiest project for someone totally new to game programming, but i find it motivating, so meh...

I've been reading around about 2D isometric engines and rendering techniques, and have got some of the basic stuff pretty much figured out, but there's a big question still bugging me.
Since i want my engine to support heights (and my tiles aren't flat), i'm working with many layers of tiles. For now my tiles are actually really just blocks that i'm stacking on top of each other.
My drawing test sandbox looks a little bit like this currently:

imgUDA.png


On to my concern: Since i have many layers of blocks, and want pretty large maps, i'll be dealing with a lot of blocks when it comes to rendering the game world. Now it's quite obvious that, for a full cube of 5 x 5 x 5 blocks, i'd only need to render 61 blocks, since the blocks inside/at the back of the cube wouldn't be visible anyways.
Now let's say i want to render a map with dimensions 25 x 25 x 10... At that point i assume it would be a pretty big waste of ressources to render every single block, including the ones that aren't visible to the camera. What if i have holes in my map, making some blocks from the inner layers visible, and others invisible? When i iterate through my blocks, how do i know if the block i'm about to render is actually visible to the camera, and doesn't already have a cube/cubes hiding it entirely from the camera? Since i want to avoid drawing blocks that are hidden, that's pretty much what i need to figure out in order to decide if a block should or shouldn't be rendered, right? I get the feeling there probably is a pretty simple solution, but i can't seem to think of it... It just seems to me that there wouldn't be an efficient way of doing this, since blocks really far away from each other can still overlap and hide each other visually because of their height...

(The reason i'd want my 5 x 5 x 5 blocks cube to be made up of 125 blocks rather than just 61 is because i'm planning on making some cubes breakable, so the inner layers have to actually exist)

Any idea?
Advertisement
Hi. I understand that you want to develop an efficient engine but I believe you don't really need to be concerned about any slowdown with those numbers.
However, the first thing that comes to my mind is to find a mathematical relation between a given block and the blocks that are in front of it and would hide it, completely or partially. Of course you would have to assign order numbers to your entire grid. Then you would have to check if those blocks exist and are visible. The main problem seems to be finding a way to determine when a group of blocks that individually only partially hide the given block, collectively hides it. You could find an angle of view or a height of the blocks that makes this calculation easier, and find for example that for each block you can define a set of configurations that hide the block. This would result in the definition of multiple sub-sets of hiding blocks, let's say A, B, C and D, and finding out that when you have at least one block in A & C, or in B, C & D, the given block is completely hidden.

Any idea?


how i would do it (not saying it's a good idea, not sure about the performance, but i'm trying to do something similar this way):
preprocess your map, give every tile a "visible" bool property, and when loading, set it - you know which tiles are closer to screen, and how high are they, and how much tiles "UP" you have to draw to cover one tile behind it, so you can do it.

then, at draw-time, or when camera moves, first query your array for tiles which are in the area that are in the view - if you've got the tiles in array, figure how much camera can see, and loop only through that part of array), and draw only if "visible" bool property is true.

but as gentleman above me already wrote, the "do not draw tiles obscured by other tiles" shouldn't be much of an issue, the more important (and simpler) one is "do not draw tiles that are offscreen".

This topic is closed to new replies.

Advertisement