Coordinate systems II
I am doing my fractal terrain generation in a pretty strange coordinate system: six square grids, one living on each face of a cube. Since planets are round, I then project this onto the surface of the sphere. The projection assumes that the sphere circumscribes the cube (i.e. the eight corners of the cube lie in the surface of the sphere) and that everything gets projected radially (i.e., if you draw a ray from the center of the sphere through a point on the cube's surface, that point gets mapped to the sphere's surface where the ray intersects that surface.)
I am using a cube because I find it easier to work in square grids. It was necessary for me to number the faces of the cube, and define a local coordinate system in each face. Unfortunately, I couldn't think of a nice isotropic way of doing this, so the connectivity is pretty haphazard. Here it is:
Each cube face is divided into a 20x20 (for now) grid of coarsest-level squares, which are also the root nodes of fractal evaluation quadtrees. One of these faces when projected onto the sphere looks like this:
This set of squares is always visible to the player (although, of course, it may get clipped.) As a ship gets close to the planet, these squares expand into more detailed terrain, obeying the fractal expansion rules. Internally, the quadtree nodes represent squares at some level of detail. Each node has pointers to its four neighbors. Note that these pointers may point from one face of the cube over the edge to another face; this is how I manage to evaluate the fractal on multiple faces at once. Neighboring squares on different faces negotiate what the fractal evaluates to on their shared border.
Home | Terrain Generation