Documentation ¶
Overview ¶
Package land is used to procedurally generate world terrain height maps. Generated lands are unique to a supplied random seed so they can be different or identical based on need. They can also be as detailed as desired although maps at higher level of detail will need to be managed since only a portion will fit in main memory and an even smaller portion in graphics memory.
Package land is provided as part of the vu (virtual universe) 3D engine.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Land ¶
type Land interface { Lod() int // Level of detail (max zoom) for this land. TileSize() int // Land tile width, height. Standard is 256 Size(lod int) int // Width and height at the given level of detail. // Allocate and populate the indicated land tile with height data. // lod : indicates the resolution/size/level-of-detail. // tx, ty: topo/tile index at given zoom. NewTile(lod, tx, ty int) Tile FillTile(tile Tile) // (Re)populates an existing tile with height data. }
Land provides the ability to procedurally generate terrain height information. The higher the level of detail the larger the terrain. Land is created using land.New().
func New ¶
New initializes the procedural land generator. The seed determines land shape, such that lands created from the same seed will be the same. The level of detail lod determines the overall size of the land (limit to 8 or less pending stress testing). For example if tileSize is 256 then increasing the level of detail results in the following sizes:
lod 0 : 256*2^0 = 256 lod 1 : 256*2^1 = 512 lod 2 : 256*2^2 = 1024 ~1km2 lod 3 : 256*2^3 = 2048 lod 4 : 256*2^4 = 4096 lod 5 : 256*2^5 = 8192 lod 6 : 256*2^6 = 16384 lod 7 : 256*2^7 = 37768 lod 8 : 256*2^8 = 65536 ~65km2 Medium size city. lod 9 : 256*2^9 = 131072 lod 10 : 256*2^10 = 262144 lod 11 : 256*2^11 = 524288 lod 12 : 256*2^12 = 1048576 ~1,000,000km2 Size of Ontario lod 13 : 256*2^13 = 2097152 3162000 ~10,000,000km2 Size of Canada lod 14 : 256*2^14 = 4194304 lod 15 : 256*2^15 = 8388608 lod 16 : 256*2^16 = 16777216 22583000 ~510,000,000km2 Size of Earth lod 17 : 256*2^17 = 33554472
Land heights are generated by creating tiles at a particular zoom level. It is up to the caller to store/cache or regenerate tiles as needed.
type RegionData ¶
type RegionData [][]int
RegionData is used to associate a data value at each land location. For example this can be used to associate a land type or land region at each height location.
func Regions ¶
func Regions(size, numRegions int, seed int64) RegionData
Regions divides a given land. This is attempting to do something similar to creating a Voronoi diagram, just using a lot less code (also less efficient). The random seed is injected so that identical results can be re-created.
type Tile ¶
type Tile interface { Topo() Topo // Height data. Zoom() int // Zoom (level of detail) for this tile. XY() (tx, ty int) // Tile X, Y index within the world. Key() string // Unique tile id using zoom and tile XY. Set(zoom, tx, ty int) Tile // Repurpose this tile. Data needs resetting. }
Tile holds a portion of the overall world map. It is indexed and keyed for easy storage and access. Tile is the pre-rendered portion of the map at different levels of detail.
type Topo ¶
type Topo [][]float64
Topo (topology) is height map information representing one part of a world. A small world may consist of only one zoom level (4 topos). A topo provides height information at a overall resolution based on a zoom value. Larger zoom values mean larger maps and hence more height maps. Each topo section at a given zoom level has an implied x, y index based on the topo size and zoom level.