How would one implement wrapping a flat 3d world so that it simulates being on a sphere? Ie… you would run forward and be able to run forever because it wraps around. I want to implement it this way because I want the world to be flat… but also … to loop. It’s hard to explain! It’s like the old flying astroid game where you fly up and suddenly appear on the bottom so you can fly straight forever. But since this is 3d, you should be able to render the stuff on the bottom of the world when you are near the top…
You want things to appear flat like they do to the human eye, but acutally walk like I would if there was a bridge around the earth…looks flat, but x tim elater I would be back where I started.
Not sure if this would work, but could you set a min and max x and y and if you pass the max, you end up at the min, and vice versa ??!
I think I need to use modular arithmitic… so that if I go past the world limit, it will round to the opposite side of the world…
That is exactly right. For example, if your world was 255*255, then you can set x = (x + deltax) % 255.
Just a note (Because I like to nag about these things) but if you go off the top and appear on the bottom and then go off one side and appear on the other, then it’s not a spere. That shape is technically called a torus, aka, the donut. If the world were a flattened sphere, then going off the bottom would bring you back up on the bottom and one radii distance to the side.
There’s two basic ways to approach this:
-
Use spherical coordinates for everything, and use great-circle calculations for direction, movement, distance, et al. These are very hard to make fast, since you have to give up all straight-line calculations.
-
Invent a tile-based system that more-or-less evenly tesselates over a sphere. Plan on spending lots of time looking at soccer balls and such, and thinking about 72-degree angles.
Both of these approaches are much more difficult than you might think. We looked at both approaches for our current game and eventually settled on #2. However, in the process we had to invent an entire coordinate system that is then used for distance and direction calculations. In retrospect, we might have done a different type of game if we had known how hard this was going to be.
You will basically not be able to use a lot of existing algorithms for your game, because they are mostly assuming flat surfaces. Plan on spending a lot of time on just getting basic geometry stuff working correctly. And don’t get me started on sphere-based navigation and camera positioning…
On the other hand, having gone through the pain and ending up with a pretty cool system, I can say that the end result may well be worth it. : Being able to fly (or walk) all over an entire planet is actually pretty cool…
Also, a lot depends on what kind of game you are making. If you just want to do collision detection on a sphere for purposes of placing a 3D model, then it’s easy. But it gets harder real fast when you start talking about movement.
I dunno, maybe it would be cool to have a donut-shaped planet…
But I think the actual shape wouldn’t even be a donut. It would be more like a thick washer. The reason is the same reason it wouldn’t be a sphere. If the map were interpreted as a sphere, then we would have to assume some kind of spacetime distortion if you move off of a great circle. Similarly, if you travel along the major circumference of a torus, there is only one great circle, and we’d have to assume a distortion off of that great circle.
“In the beginning, there was a washer-shaped planetoid called Galacto…”
Ok, so i’m a bit late here but what You want to achieve is perfectly reasonable.
take a look at: http://irrforge.org/index.php/Tutorials for details
edit: Seamless World and Donut World are the ones to look at