Sign in to follow this  

Recursive world rendering

This topic is 3589 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm currently developing a 3D asteroids game using XNA. My world will behave similar to the old 2D game where you wrap around the world when you go off one side and that is no problem doing that in a 3D cube. However, if the the player is not moving and an asteroid moves off the edge of the world and wraps round, then it will appear to have disappeared, which could be frustrating for the player. What I want is to be able to render the world, as well as the wrapped round view, as if the edge of the world is a window through to the other side. That way it will give the illusion of an infinite/recursive universe. My problem however, is that I can't think of a method of doing this reliably. The only idea I can think of at the moment which would likely work is to clone the world box around itself (up/down/left/right/diagonal etc...). However that would be extremely inefficient.. Hopefully there's some method I've not thought of yet or a compromise of some sort!

Share this post


Link to post
Share on other sites
Consider a 2D example, since that's much easier to picture. The center tile in this diagram is your game world, and the eight tiles around it are your border tiles.
    |    |
| |
| |
--------------
| |
| |
| |
--------------
| |
| |
| |
These border tiles are actually "phantoms" of the game tile, in order to simulate an infinitely wrapping universe. Whenever an object goes into a border tile, it's beginning to wrap around. Thus, you render it multiple times in your game tile. The relative location of the object in the border tile, is where you render it in the game tile. Let's say that the four '*' characters below indicate a box that has moved off the edge of the game tile into a corner. The '+' symbols indicate where you render the box in the game tile.
    |    |
| |
*|* |
--------------
*|* +|
| |
|+ +|
--------------
| |
| |
| |
Notice the relative positions between where the '*' symbols are in the border tiles, and where they're rendered as '+' in the game tile. Once the object is completely inside a border tile, you "teleport" it to the same relative position in the game tile so that it fully wraps around (and is entirely back in the game tile again).

On top of that you throw in portals, which allow you to see into the border tiles, which is really just looking back at the game world from another perspective. That way there is no discontinuity when rendering. The objects don't disappear, since you can see them through the portals.

In essence, it comes down to having multiple instances of objects when they're on tile edges (which can actually be lightweight clones, since they share all the same data as the original object), teleporting them back into the game tile when they fully enter a border tile, and using portals so that your view also wraps around to the other end of the world. And of course you need to extend this all to 3D, meaning 26 border tiles.

Hopefully that's all clear enough to follow :)

Share this post


Link to post
Share on other sites

This topic is 3589 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this