Friday, March 18, 2016

opengl - Square game map rendered as sphere


For a hobby project of mine I have created a finite voxel world (similar to Minecraft), but as I said, mine is finite. When you reach the edge of it, you are sent to the other side. That is all working fine along with rendering the far side of the map, but I want to be able to render this grid as a sphere.


Looking down from above, the world is a square. I basically want to be able to represent a portion of that square as a sphere, as if you were looking at a planet. Right now I am experimenting with taking a circular section of the map, and rendering that, but it look to flat (no curvature around the edges).



My question then, is what would be the best way to add some curvature to the edges of a 2d circle to make it look like a hemisphere. However, I am not overly attached to this implementation so if somebody has some other idea for representing the square as a planet, I am all ears.



Answer



Right now you essentially have a 2D plane, or at least a thick sheet of cubes. That's your map. You want to take that map and wrap it around a sphere. An easy way to do that is to convert your wrapping coordinates into spherical coordinates. Wrapping the same way you would with your current world.


To avoid all the nasty warping effects you get from this conversion at the poles, I would also shift the wrapping so that your player is always on the equator of the sphere.


This can be done entirely in the shader if you like. This keeps things very simple because it's an effect you can just turn on or off and you don't have to worry about changing any of your game logic.


I did a little experimenting with this myself and the above is the method I used. The results were promising:


enter image description here enter image description here


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...