Creating and using Terrain objects from heightmaps. More...

Collaboration diagram for Terrain:

Detailed Description

Creating and using Terrain objects from heightmaps.

The Terrain class is an entity that can be built from a heightmap texture. The terrain can be created and saved through the TerrainAssets manager. To create a Terrain, use the TerrainAssets::Load() function and pass in a string storage key, a wide string of the filepath, a ShaderTextureLight pointer (must be of this type), a texture to apply to the terrain, and various integer parameters for adjusting the scale, height and texture repeat. For more info see the documentation on TerrainAssets::Load().

LoadResources.cpp:

{
...
//---------------------------------------------------------------------------------------------------------
// Load the Terrains
//---------------------------------------------------------------------------------------------------------
TerrainAssets::Load("Terrain_Grass", L"Textures/HeightMaps/LevelOne.tga", ShaderAssets::Get("SHADER_TEXTURE_LIGHT"),
Color::White, 5000, 150, 10, TextureAssets::Get("TexGrass"));
TerrainAssets::Load("Terrain_Sand", L"Textures/HeightMaps/LevelTwo.tga", ShaderAssets::Get("SHADER_TEXTURE_LIGHT"),
Color::White, 5000, 100, 10, TextureAssets::Get("TexSand"));
TerrainAssets::Load("Terrain_Rock", L"Textures/HeightMaps/LevelThree.tga", ShaderAssets::Get("SHADER_TEXTURE_LIGHT"),
Color::White, 5000, 200, 10, TextureAssets::Get("TexHardGround"));
...
}

The Terrain object can be applied to the scene with the Scene::SetTerrain() function which takes in a string key to the storage key in the TerrainAssets manager. The Scene::SetTerrain() function can be called within the Scene::Initialize() like so:

UserScene.cpp:

void UserScene::Initialize()
{
SetTerrain("Terrain_Grass");
...
}

The Scene class also offers a Scene::GetCurTerrain() function to retreive a pointer to the current active Terrain. This can also be called through SceneManager's SceneManager::GetCurrentTerrain() function. The Terrain class offers only a few functions such as Terrain::SetTexture() to modify the texture of the Terrain and Terrain::GetSurfacePoint() which takes in a Vect position and returns a position clamped to the surface of the Terrain (if the passed in position was above/below the Terrain).

Classes

class  Terrain
 Terrain class for 3D terrain. More...
 
class  TerrainAssets
 System manager for for creating and accessing Terrain objects from external resources. More...