Mapping a 2D grid onto a sphere

Post your questions, suggestions and experiences regarding game design, integration of external libraries here. For irrEdit, irrXML and irrKlang, see the
ambiera forums
Post Reply
DarkDepths
Posts: 126
Joined: Sun Apr 02, 2006 1:21 am
Location: Canada

Mapping a 2D grid onto a sphere

Post by DarkDepths »

I have been asked to map a grid onto a sphere. The basic idea, as I understand it, is very similar to Civilization 4, if you have played it. If you haven't, the game basically works as a 2D RTS, but the 2D map is wrapped around a sphere that you can rotate and zoom in on and has 3D elements placed on the different grid tiles.

I have no idea how to accomplish this. I have worked quite extensively with 3D geometry and it seems to me that you can't fit a bunch of square onto a sphere. The squares must deform at some point.

In Civ 4, I think part of the way they get around this is by removing the poles from active play. They simply cover them with ice and say "You can't go there." I think that solves a portion of the problem, because most of the deformation usually occurs at the poles. However, the only truly perfect squares, methinks, would be in a ring around the equator. So again, I'm stuck.

Initially, I thought it would be best to essentially make it as a 2D game and map it onto a sphere. When I click a spot on the sphere, I would then (somehow) translate that into a grid cell. I'd make changes to the 2D grid, and then map it back onto the sphere.

The more I think about it though, the more horrible it sounds. I don't know how to map a 2D grid onto a sphere, I don't know how to pick a cell from a place on a sphere, I don't know how long it will take to map the grid to the sphere (so doing it 30 times a second might not be plausible), I just don't know!


So, any thoughts from you guys would be super duper cool!

Thanks!

Edit: I thought I should mention (since you will probably tell me to use google (:)) that I considered using the catmul-rom algorithm to make an approximate sphere with perfect square polygons. However, I was hoping to accomplish this without subdividing a sphere a gagillion times. By that I mean, ideally, I'd like to have as many grid cells as I want on a sphere with constant number of polygons.
REDDemon
Developer
Posts: 1044
Joined: Tue Aug 31, 2010 8:06 pm
Location: Genova (Italy)

Post by REDDemon »

u can make a ICO sphere split everi face in 4 pieces an repeat as you want (max 4 or 5 subdivision). then you can assume every 2 triangles are a quad. (not really. but if you zoom only local you can scale triangles to seem squares).
Junior Irrlicht Developer.
Real value in social networks is not about "increasing" number of followers, but about getting in touch with Amazing people.
- by Me
DarkDepths
Posts: 126
Joined: Sun Apr 02, 2006 1:21 am
Location: Canada

Post by DarkDepths »

Thanks for the reply, but your solution still requires me to subdivide the sphere many times.

I think I've changed my mind on exactly what I want to do. First, rather than using a square grid, I'll use a hexagonal grid. Secondly, it won't span the entire globe, it will be just a wide band around the equator with the poles blocked off.

I suppose my next question would be better suited in the beginners forum, but as it is currently a contemplation and not really an implementation, I think it might fit here...

So I guess the question would be, is it feasible/possible to get the coordinates of a texture based on where you click on a model. I don't know a lot about Texture coordinates, but it seems to my uneducated mind that I would need to make use of them for this task...
Post Reply