Thursday, 11 February 2010

HS: trouble with spheres

Having got my mode switching working and Neoforce mostly behaving itself (though I have noticed that it's perhaps stealing keyboard events, something worth investigating), I turned to the task of getting myself a spherical Earth model displaying itself.

My first instinct was to use a prefabbed sphere mesh, one of which I found here. However, I couldn't figure out how to load the vertices out of the model, knowing that I have certain rather advanced plans for my Earth. So, I turned to this code to procedurally generate a sphere for my Earth.

I had to adjust the code to use my homegrown vertex declaration that includes texture coordinates, and discovered in the process how to draw a sphere with texture coordinates that go all the way from 0 to 1 in both axes. There were two parts to this:

1. Adding an extra column of vertices that overlap x=0 with x=1 for texture coordinates (essentially, generating the first vertex in every row twice, once for 0 and once for 1).
2. Removing the triangle fans at the top and bottom of the sphere and replacing them with strips. This is because otherwise you have to set the texcoord of the poles to {0.5,1}, which leads to texture twisting in the triangle fans. Instead, I generated an additional vertex at each pole for each column, these overlapping vertices having gradually increasing x coordinates for the texture.

So, here's my Earth! You can also see some axis lines I'm drawing on, and a Neoforce button on there for testing purposes:


Eventually, as well as lighting it, I plan to calculate surface normals based on a NASA bump map, potentially multitexture it with a nighttime texture, and of course add all the game components such as cities, bases and UFOs.

Two things to do next: allow proper click-drag modification of the camera view, and add a variable-rate clock. Perhaps I will try getting a default light source in first, though.

No comments:

Post a Comment