# Visualization Library

A lightweight C++ OpenGL middleware for 2D/3D graphics

[Home] [Tutorials] [All Classes] [Grouped Classes]

Public Member Functions | Protected Attributes

# vl::Terrain Class Reference

The Terrain class implements a ActorKdTree-based terrain scene manager. More...

`#include <Terrain.hpp>`

Inheritance diagram for vl::Terrain:

List of all members.

## Public Member Functions

virtual const char * | className ()
| Returns the name of the class.
| Terrain ()
void | init ()
bool | useGLSL () const
int | detailRepetitionMode () const
double | width () const
double | depth () const
double | height () const
const vec3 & | origin () const
const String & | detailTexture () const
const String & | terrainTexture () const
const String & | heightmapTexture () const
ETextureFormat | heightmapTextureFormat () const
ETextureFormat | terrainTextureFormat () const
ETextureFormat | detailTextureFormat () const
void | setUseGLSL (bool enable)
void | setDetailRepetitionCount (int count)
void | setWidth (double w)
void | setDepth (double d)
void | setHeight (double h)
void | setOrigin (const vec3 &origin)
void | setHeightmapTextureFormat (ETextureFormat format)
void | setTerrainTextureFormat (ETextureFormat format)
void | setDetailTextureFormat (ETextureFormat format)
void | setVertexShader (const String &vs_path)
const String & | vertexShader () const
void | setFragmentShader (const String &fs_path)
const String & | fragmentShader () const
const ActorCollection & | chunks () const
int | chunkCount () const
Actor * | chunk (int i)
const Actor * | chunk (int i) const
void | setDetailTexture (const String &texture)
| Sets the texture to be used as detail texture, it can be of any size.
void | setTerrainTexture (const String &texture)
| Sets the texture to be used as the base terrain texture.
void | setHeightmapTexture (const String &texture)
| Sets the texture to be used as the heightmap.
const ShaderNode * | shaderNode () const
ShaderNode * | shaderNode ()

## Protected Attributes

ref< ShaderNode > | mShaderNode
ActorCollection | mChunks
double | mWidth
double | mHeight
double | mDepth
vec3 | mOrigin
String | mDetailTexture
String | mTerrainTexture
String | mHeightmapTexture
String | mVertexShader
String | mFragmentShader
int | mDetailRepetitionCount
ETextureFormat | mHeightmapTextureFormat
ETextureFormat | mTerrainTextureFormat
ETextureFormat | mDetailTextureFormat
bool | mUseGLSL

## Detailed Description

The Terrain class implements a ActorKdTree-based terrain scene manager.

Some applications do not need complex LOD or CLOD management algorithms to display height fields or terrains, either because the data displayed has a limited size or because particular constraints are applied to the camera (like in RTS games for example) for which only a limited portion of the terrain is visible at a given time.

This applications can greatly benefit from the vl::Terrain scene manager which implements a fool-proof, high-precision (8, 16 and 32 bits heightmaps are supported) and efficient terrain/heightfield generation and management system. All the user has to provide is a texture for the terrain, a heightfield image and a detail texture following very simple and precise guidelines.

The vl::Terrain class takes care of all the rest, like dividing the provided images into chunks, generating the geometry, generating the kd-tree, computing the appropriate texture coordinates in order to prevent seams and so on.

If the OpenGL Shading Language is available, the vl::Terrain class can also store the heightmap directly on the GPU and can generate the geometry on the fly using a technique called "vertex texture fetch" (http://developer.nvidia.com/object/using_vertex_textures.html). This technique allows the application to save GPU memory and to manage even greater terrain databases at a higher speed.

See also:
  setTerrainTexture(), setHeightmapTexture(), setDetailTexture()

Definition at line 63 of file Terrain.hpp.

## Constructor & Destructor Documentation

vl::Terrain::Terrain | ( | ) | `[inline]`

Definition at line 67 of file Terrain.hpp.

## Member Function Documentation

virtual const char* vl::Terrain::className | ( | ) | `[inline, virtual]`

Returns the name of the class.

Reimplemented from vl::SceneManagerActorKdTree.

Definition at line 66 of file Terrain.hpp.

void Terrain::init | ( | ) |

Definition at line 43 of file Terrain.cpp.

References vl::ShaderNode::addChild(), vl::ActorKdTree::buildKdTree(), vl::Collection< T >::clear(), depth(), detailTexture(), detailTextureFormat(), vl::String::empty(), vl::EN_CULL_FACE, vl::EN_DEPTH_TEST, vl::Log::error(), fragmentShader(), vl::ref< T >::get(), height(), heightmapTexture(), heightmapTextureFormat(), vl::loadImage(), vl::String::loadText(), vl::makeGrid(), vl::max(), mChunks, mDepth, mDetailRepetitionCount, mHeight, mOrigin, mWidth, vl::Collection< T >::push_back(), vl::Vector4< T_Scalar >::r(), vl::Matrix4< T_Scalar >::scale(), vl::ShaderNode::setEnable(), vl::AABB::setMaxCorner(), vl::AABB::setMinCorner(), vl::ShaderNode::setRenderState(), shaderNode(), vl::TEM_MODULATE, terrainTexture(), terrainTextureFormat(), vl::TPF_LINEAR, vl::TPF_LINEAR_MIPMAP_LINEAR, vl::TPF_NEAREST, vl::TPW_REPEAT, vl::Matrix4< T_Scalar >::translate(), vl::SceneManagerBVH< ActorKdTree >::tree(), vl::ShaderNode::updateHierarchy(), useGLSL(), vertexShader(), and width().

bool vl::Terrain::useGLSL | ( | ) | const`[inline]`

Definition at line 77 of file Terrain.hpp.

Referenced by init().

int vl::Terrain::detailRepetitionMode | ( | ) | const`[inline]`

Definition at line 78 of file Terrain.hpp.

double vl::Terrain::width | ( | ) | const`[inline]`

Definition at line 79 of file Terrain.hpp.

Referenced by init().

double vl::Terrain::depth | ( | ) | const`[inline]`

Definition at line 80 of file Terrain.hpp.

Referenced by init().

double vl::Terrain::height | ( | ) | const`[inline]`

Definition at line 81 of file Terrain.hpp.

Referenced by init().

const vec3& vl::Terrain::origin | ( | ) | const`[inline]`

Definition at line 82 of file Terrain.hpp.

const String& vl::Terrain::detailTexture | ( | ) | const`[inline]`

Definition at line 83 of file Terrain.hpp.

Referenced by init().

const String& vl::Terrain::terrainTexture | ( | ) | const`[inline]`

Definition at line 84 of file Terrain.hpp.

Referenced by init().

const String& vl::Terrain::heightmapTexture | ( | ) | const`[inline]`

Definition at line 85 of file Terrain.hpp.

Referenced by init().

ETextureFormat vl::Terrain::heightmapTextureFormat | ( | ) | const`[inline]`

Definition at line 86 of file Terrain.hpp.

Referenced by init().

ETextureFormat vl::Terrain::terrainTextureFormat | ( | ) | const`[inline]`

Definition at line 87 of file Terrain.hpp.

Referenced by init().

ETextureFormat vl::Terrain::detailTextureFormat | ( | ) | const`[inline]`

Definition at line 88 of file Terrain.hpp.

Referenced by init().

void vl::Terrain::setUseGLSL | ( | bool | enable ) | `[inline]`

Definition at line 90 of file Terrain.hpp.

void vl::Terrain::setDetailRepetitionCount | ( | int | count ) | `[inline]`

Definition at line 91 of file Terrain.hpp.

void vl::Terrain::setWidth | ( | double | w ) | `[inline]`

Definition at line 92 of file Terrain.hpp.

void vl::Terrain::setDepth | ( | double | d ) | `[inline]`

Definition at line 93 of file Terrain.hpp.

void vl::Terrain::setHeight | ( | double | h ) | `[inline]`

Definition at line 94 of file Terrain.hpp.

void vl::Terrain::setOrigin | ( | const vec3 & | origin ) | `[inline]`

Definition at line 95 of file Terrain.hpp.

void vl::Terrain::setHeightmapTextureFormat | ( | ETextureFormat | format ) | `[inline]`

Definition at line 96 of file Terrain.hpp.

void vl::Terrain::setTerrainTextureFormat | ( | ETextureFormat | format ) | `[inline]`

Definition at line 97 of file Terrain.hpp.

void vl::Terrain::setDetailTextureFormat | ( | ETextureFormat | format ) | `[inline]`

Definition at line 98 of file Terrain.hpp.

void vl::Terrain::setVertexShader | ( | const String & | vs_path ) | `[inline]`

Definition at line 100 of file Terrain.hpp.

const String& vl::Terrain::vertexShader | ( | ) | const`[inline]`

Definition at line 101 of file Terrain.hpp.

Referenced by init().

void vl::Terrain::setFragmentShader | ( | const String & | fs_path ) | `[inline]`

Definition at line 103 of file Terrain.hpp.

const String& vl::Terrain::fragmentShader | ( | ) | const`[inline]`

Definition at line 104 of file Terrain.hpp.

Referenced by init().

const ActorCollection& vl::Terrain::chunks | ( | ) | const`[inline]`

Definition at line 106 of file Terrain.hpp.

int vl::Terrain::chunkCount | ( | ) | const`[inline]`

Definition at line 107 of file Terrain.hpp.

Actor* vl::Terrain::chunk | ( | int | i ) | `[inline]`

Definition at line 108 of file Terrain.hpp.

const Actor* vl::Terrain::chunk | ( | int | i ) | const`[inline]`

Definition at line 109 of file Terrain.hpp.

void vl::Terrain::setDetailTexture | ( | const String & | texture ) | `[inline]`

Sets the texture to be used as detail texture, it can be of any size.

Definition at line 114 of file Terrain.hpp.

void vl::Terrain::setTerrainTexture | ( | const String & | texture ) | `[inline]`

Sets the texture to be used as the base terrain texture.

Its size must be of the form: n * d - n + 1 where:

- 'n' is any positive integer. 'n' is the value passed to setChunkSubdivision().
- 'd' is a power of 2 and defines the dimension of the texture applied to each terrain chunk. For example: for a terrain with 8x8 chunks each of which with a 256x256 texture we have: 8*256-8+1 = 2041 = x and y size of the texture image.

Definition at line 122 of file Terrain.hpp.

void vl::Terrain::setHeightmapTexture | ( | const String & | texture ) | `[inline]`

Sets the texture to be used as the heightmap.

Its size must be of the form: n * d - n + 1 where:

- 'n' is any positive integer. 'n' is the value passed to setChunkSubdivision().
- 'd' is a power of 2 and defines the dimension of the heightmap portion used to build each terrain chunk. For example: for a terrain with 8x8 chunks each of which with a 256x256 heightmap we have: 8*256-8+1 = 2041 = x and y size of the heightmap image.

Definition at line 130 of file Terrain.hpp.

const ShaderNode* vl::Terrain::shaderNode | ( | ) | const`[inline]`

Definition at line 132 of file Terrain.hpp.

Referenced by init().

ShaderNode* vl::Terrain::shaderNode | ( | ) | `[inline]`

Definition at line 133 of file Terrain.hpp.

## Member Data Documentation

ref<ShaderNode> vl::Terrain::mShaderNode`[protected]`

Definition at line 136 of file Terrain.hpp.

ActorCollection vl::Terrain::mChunks`[protected]`

Definition at line 137 of file Terrain.hpp.

Referenced by init().

double vl::Terrain::mWidth`[protected]`

Definition at line 138 of file Terrain.hpp.

Referenced by init().

double vl::Terrain::mHeight`[protected]`

Definition at line 139 of file Terrain.hpp.

Referenced by init().

double vl::Terrain::mDepth`[protected]`

Definition at line 140 of file Terrain.hpp.

Referenced by init().

vec3 vl::Terrain::mOrigin`[protected]`

Definition at line 141 of file Terrain.hpp.

Referenced by init().

String vl::Terrain::mDetailTexture`[protected]`

Definition at line 142 of file Terrain.hpp.

String vl::Terrain::mTerrainTexture`[protected]`

Definition at line 143 of file Terrain.hpp.

String vl::Terrain::mHeightmapTexture`[protected]`

Definition at line 144 of file Terrain.hpp.

String vl::Terrain::mVertexShader`[protected]`

Definition at line 145 of file Terrain.hpp.

String vl::Terrain::mFragmentShader`[protected]`

Definition at line 146 of file Terrain.hpp.

int vl::Terrain::mDetailRepetitionCount`[protected]`

Definition at line 147 of file Terrain.hpp.

Referenced by init().

ETextureFormat vl::Terrain::mHeightmapTextureFormat`[protected]`

Definition at line 148 of file Terrain.hpp.

ETextureFormat vl::Terrain::mTerrainTextureFormat`[protected]`

Definition at line 149 of file Terrain.hpp.

ETextureFormat vl::Terrain::mDetailTextureFormat`[protected]`

Definition at line 150 of file Terrain.hpp.

bool vl::Terrain::mUseGLSL`[protected]`

Definition at line 151 of file Terrain.hpp.

The documentation for this class was generated from the following files:

- D:/VL/BuildSystem/VL_DISTRO/Visualization_Library_SDK/src/vlGraphics/Terrain.hpp
- D:/VL/BuildSystem/VL_DISTRO/Visualization_Library_SDK/src/vlGraphics/Terrain.cpp

Visualization Library v2011.05.1142 Reference Documentation
Copyright 2005-2011 Michele Bosi. All rights reserved.
Updated on Thu May 26 2011 22:51:46.
Permission is granted to use this page to write and publish articles regarding Visualization Library.