War in Space Day 9 – Toroidal Space

Toroidal

Not screenshot today, but I implemented the first step of the toroidal space which allows the ships to “wrap around” when they get to the edge of the screen. As explained here, the type of space in which such a wrap-around happens is called toroidal since it can be thought of as existing as the surface of a torus. It’s pretty interesting that a lot of the early classic video games chose such a space, including Space War and Asteroids.

There are different possibilites of creating this wraparound effect. One would be to detect that an object is intersecting an edge, and create a “clone” of the object at the opposite edge. The other possibility which I chose is to handle the problem by rendering the scene several times. Looking at the diagram above, you see the visible part of the screen with the planet in the center. The bright red ship has been placed above the upper edge of the screen. Normally it would not be visible since it is outside of the area that is projected onto the screen. It is rendered inside the visible area by offsetting the camera position and look-at point by the screen’s height. This results in the faintly red ship shown in the center area. Similarly, all the 8 areas around the screen’s edges and borders can be rendered.

Next steps

The next step now is to move objects which have passed one of the edges completely back into the regular visible space, otherwise they would leave the “extended” space consisting of the 8 boxes adjacent to the visible area and become invisible again. This process complicates collision detection a bit, since a projectile could visibly overlap a ship but could actually be in different boxes.