TDME2 1.9.121
Classes | Public Types | Static Public Member Functions | Static Public Attributes | Static Private Member Functions | List of all members
Terrain2 Class Reference

Terrain 2 utility. More...

#include <tdme/utilities/Terrain2.h>

Collaboration diagram for Terrain2:
Collaboration graph

Classes

struct  FoliageBrush
 
struct  FoliageBrushPrototype
 

Public Types

enum  BrushOperation {
  BRUSHOPERATION_NONE , BRUSHOPERATION_ADD , BRUSHOPERATION_SUBTRACT , BRUSHOPERATION_FLATTEN ,
  BRUSHOPERATION_DELETE , BRUSHOPERATION_SMOOTH , BRUSHOPERATION_WATER_ADD , BRUSHOPERATION_WATER_DELETE ,
  BRUSHOPERATION_RAMP
}
 

Static Public Member Functions

static void createTerrainModels (float width, float depth, float y, vector< float > &terrainHeightVector, BoundingBox &terrainBoundingBox, vector< Model * > &terrainModels, bool createLODLevels=false)
 Create terrain models. More...
 
static void applyBrushToTerrainModels (BoundingBox &terrainBoundingBox, vector< Model * > &terrainModels, vector< float > &terrainHeightVector, const Vector3 &brushCenterPosition, Texture *brushTexture, float brushScale, float brushStrength, BrushOperation brushOperation, float flattenHeight=0.0f)
 Apply brush to given terrain models. More...
 
static void applyRampBrushToTerrainModels (BoundingBox &terrainBoundingBox, vector< Model * > &terrainModels, vector< float > &terrainHeightVector, const Vector3 &brushCenterPosition, Texture *brushTexture, float brushRotation, const Vector2 &brushScale, float flattenHeightMin, float flattenHeightMax)
 Apply ramp brush to given terrain models. More...
 
static void updateFoliageTerrainBrush (BoundingBox &terrainBoundingBox, vector< float > &terrainHeightVector, const Vector3 &brushCenterPosition, const FoliageBrush &foliageBrush, vector< unordered_map< int, vector< Transformations > > > &foliageMaps, unordered_set< int > &updateFoliagePartitions)
 Update foliage after using terrain brush. More...
 
static void updateFoliageTerrainRampBrush (BoundingBox &terrainBoundingBox, vector< float > &terrainHeightVector, const Vector3 &brushCenterPosition, Texture *brushTexture, float brushRotation, const Vector2 &brushScale, vector< unordered_map< int, vector< Transformations > > > &foliageMaps, unordered_set< int > &updateFoliagePartitions)
 Update foliage after using terrain ramp brush. More...
 
static bool computeWaterPositionMap (BoundingBox &terrainBoundingBox, const vector< float > &terrainHeightVector, const Vector3 &brushCenterPosition, float waterHeight, unordered_map< int, unordered_set< int > > &waterPositionMap)
 Compute water positions map using a auto fill like algorithm at given brush center position. More...
 
static Vector3 computeWaterReflectionEnvironmentMappingPosition (const unordered_map< int, unordered_set< int > > &waterPositionMap, float waterHeight)
 Compute water reflection environment mapping position. More...
 
static void createWaterModels (BoundingBox &terrainBoundingBox, const unordered_map< int, unordered_set< int > > &waterPositionMap, float waterHeight, int waterModelIdx, vector< Model * > &waterModels)
 Create partitioned water models using given water position map. More...
 
static bool getTerrainModelsHeight (BoundingBox &terrainBoundingBox, vector< Model * > &terrainModels, vector< float > &terrainHeightVector, const Vector3 &brushCenterPosition, float &brushHeight)
 Get terrain models height for e.g. More...
 
static void createFoliageMaps (BoundingBox &terrainBoundingBox, vector< unordered_map< int, vector< Transformations > > > &foliageMaps)
 Create foliage maps. More...
 
static void createFoliageMaps (float terrainWidth, float terrainDepth, vector< unordered_map< int, vector< Transformations > > > &foliageMaps)
 Create foliage maps. More...
 
static void emptyFoliageMaps (vector< unordered_map< int, vector< Transformations > > > &foliageMaps)
 Empty foliage maps. More...
 
static void applyFoliageBrush (BoundingBox &terrainBoundingBox, vector< float > &terrainHeightVector, const Vector3 &brushCenterPosition, const FoliageBrush &foliageBrush, const vector< FoliageBrushPrototype > &foliageBrushPrototypes, BrushOperation brushOperation, vector< unordered_map< int, vector< Transformations > > > &foliageMaps, vector< unordered_map< int, vector< Transformations > > > &newFoliageMaps)
 Apply foliage brush. More...
 
static void applyFoliageDeleteBrush (BoundingBox &terrainBoundingBox, const Vector3 &brushCenterPosition, const FoliageBrush &foliageBrush, const vector< FoliageBrushPrototype > &foliageBrushPrototypes, BrushOperation brushOperation, vector< unordered_map< int, vector< Transformations > > > &foliageMaps, unordered_set< int > &recreateFoliagePartitions)
 Apply foliage delete brush. More...
 
static void mirrorXAxis (bool flipZ, float width, float depth, vector< float > &terrainHeightVector, unordered_map< int, float > &waterPositionMapsHeight, unordered_map< int, unordered_map< int, unordered_set< int > > > &waterPositionMaps, vector< unordered_map< int, vector< Transformations > > > &foliageMaps)
 Mirror terrain around X axis. More...
 
static void mirrorZAxis (bool flipX, float width, float depth, vector< float > &terrainHeightVector, unordered_map< int, float > &waterPositionMapsHeight, unordered_map< int, unordered_map< int, unordered_set< int > > > &waterPositionMaps, vector< unordered_map< int, vector< Transformations > > > &foliageMaps)
 Mirror terrain around Z axis. More...
 

Static Public Attributes

static constexpr float STEP_SIZE { 1.0f }
 
static constexpr float PARTITION_SIZE { 64.0f }
 

Static Private Member Functions

static void getTerrainVertex (int x, int z, Vector3 &vertex)
 Get the terrain vertex for given x and z position without providing y component. More...
 
static bool getTerrainVertex (const vector< float > &terrainHeightVector, int verticesPerX, int verticesPerZ, int x, int z, Vector3 &vertex)
 Get the terrain vertex for given x and z position. More...
 
static void getWaterVertex (int x, int z, float waterHeight, Vector3 &vertex)
 Get the terrain vertex for given x and z position. More...
 
static bool hasWaterPosition (const unordered_map< int, unordered_set< int > > &waterPositionSet, int x, int z)
 
static const Vector3 computeTerrainVertexNormal (const vector< float > &terrainHeightVector, int verticesPerX, int verticesPerZ, int x, int z)
 Compute terrain vertex normal for given x and z position. More...
 
static bool determineWater (const vector< float > &terrainHeightVector, int verticesPerX, int verticesPerZ, int x, int z, float waterHeight)
 Determine if water can be generated. More...
 
static void determineWaterXPositionSet (const vector< float > &terrainHeightVector, int verticesPerX, int verticesPerZ, int x, int z, float waterHeight, unordered_set< int > &waterXPositionSet)
 Determine if water can be generated from left to right starting with x and z. More...
 

Detailed Description

Terrain 2 utility.

Author
Andreas Drewke

Definition at line 32 of file Terrain2.h.

Member Enumeration Documentation

◆ BrushOperation

Enumerator
BRUSHOPERATION_NONE 
BRUSHOPERATION_ADD 
BRUSHOPERATION_SUBTRACT 
BRUSHOPERATION_FLATTEN 
BRUSHOPERATION_DELETE 
BRUSHOPERATION_SMOOTH 
BRUSHOPERATION_WATER_ADD 
BRUSHOPERATION_WATER_DELETE 
BRUSHOPERATION_RAMP 

Definition at line 205 of file Terrain2.h.

Member Function Documentation

◆ applyBrushToTerrainModels()

void applyBrushToTerrainModels ( BoundingBox terrainBoundingBox,
vector< Model * > &  terrainModels,
vector< float > &  terrainHeightVector,
const Vector3 brushCenterPosition,
Texture brushTexture,
float  brushScale,
float  brushStrength,
BrushOperation  brushOperation,
float  flattenHeight = 0.0f 
)
static

Apply brush to given terrain models.

Parameters
terrainBoundingBoxterrain bounding box
terrainModelsterrain models vector
terrainHeightVectorterrain height vector
brushCenterPositionbrush center position
brushTexturebrush texture
brushScalebrush scale
brushStrengthbrush strength
brushOperationbrush operation
flattenHeightflatten height

Definition at line 395 of file Terrain2.cpp.

◆ applyFoliageBrush()

void applyFoliageBrush ( BoundingBox terrainBoundingBox,
vector< float > &  terrainHeightVector,
const Vector3 brushCenterPosition,
const FoliageBrush foliageBrush,
const vector< FoliageBrushPrototype > &  foliageBrushPrototypes,
BrushOperation  brushOperation,
vector< unordered_map< int, vector< Transformations > > > &  foliageMaps,
vector< unordered_map< int, vector< Transformations > > > &  newFoliageMaps 
)
static

Apply foliage brush.

Parameters
terrainBoundingBoxterrain bounding box
terrainHeightVectorterrain height vector
brushCenterPositionbrush center position
foliageBrushfoliage brush
foliageBrushPrototypesfoliage brush prototypes
brushOperationbrush operation
foliageMapsfoliage maps
newFoliageMapsnew foliage maps
prototypeScaleprototype scale

Definition at line 1385 of file Terrain2.cpp.

◆ applyFoliageDeleteBrush()

void applyFoliageDeleteBrush ( BoundingBox terrainBoundingBox,
const Vector3 brushCenterPosition,
const FoliageBrush foliageBrush,
const vector< FoliageBrushPrototype > &  foliageBrushPrototypes,
BrushOperation  brushOperation,
vector< unordered_map< int, vector< Transformations > > > &  foliageMaps,
unordered_set< int > &  recreateFoliagePartitions 
)
static

Apply foliage delete brush.

Parameters
terrainBoundingBoxterrain bounding box
brushCenterPositionbrush center position
foliageBrushfoliage brush
foliageBrushPrototypesfoliage brush prototypes
brushOperationbrush operation
foliageMapsfoliage maps
recreateFoliagePartitionsrecreate foliage partitions

Definition at line 1634 of file Terrain2.cpp.

◆ applyRampBrushToTerrainModels()

void applyRampBrushToTerrainModels ( BoundingBox terrainBoundingBox,
vector< Model * > &  terrainModels,
vector< float > &  terrainHeightVector,
const Vector3 brushCenterPosition,
Texture brushTexture,
float  brushRotation,
const Vector2 brushScale,
float  flattenHeightMin,
float  flattenHeightMax 
)
static

Apply ramp brush to given terrain models.

Parameters
terrainBoundingBoxterrain bounding box
terrainModelsterrain models vector
terrainHeightVectorterrain height vector
brushCenterPositionbrush center position
brushTexturebrush texture
brushRotationbrush rotation
brushScalebrush scale
flattenHeightMinminimum flatten height
flattenHeightMaxmaximum flatten height

Definition at line 736 of file Terrain2.cpp.

◆ computeTerrainVertexNormal()

const Vector3 computeTerrainVertexNormal ( const vector< float > &  terrainHeightVector,
int  verticesPerX,
int  verticesPerZ,
int  x,
int  z 
)
inlinestaticprivate

Compute terrain vertex normal for given x and z position.

Parameters
terrainHeightVectorterrain height vector
verticesPerXvertices per x
verticesPerZvertices per z
xx
zz
Returns
normal for given vertex index

Definition at line 299 of file Terrain2.cpp.

◆ computeWaterPositionMap()

bool computeWaterPositionMap ( BoundingBox terrainBoundingBox,
const vector< float > &  terrainHeightVector,
const Vector3 brushCenterPosition,
float  waterHeight,
unordered_map< int, unordered_set< int > > &  waterPositionMap 
)
static

Compute water positions map using a auto fill like algorithm at given brush center position.

Parameters
terrainBoundingBoxterrain bounding box
terrainHeightVectorterrain height vector
brushCenterPositionbrush center position
waterHeightwaterHeight
waterPositionMapwater position map

Definition at line 1055 of file Terrain2.cpp.

◆ computeWaterReflectionEnvironmentMappingPosition()

Vector3 computeWaterReflectionEnvironmentMappingPosition ( const unordered_map< int, unordered_set< int > > &  waterPositionMap,
float  waterHeight 
)
static

Compute water reflection environment mapping position.

Parameters
waterPositionMapwater position map
waterHeightwater height
Returns
water reflection environment mapping position

Definition at line 1157 of file Terrain2.cpp.

◆ createFoliageMaps() [1/2]

void createFoliageMaps ( BoundingBox terrainBoundingBox,
vector< unordered_map< int, vector< Transformations > > > &  foliageMaps 
)
static

Create foliage maps.

Parameters
terrainBoundingBoxterrain bounding box
foliageMapsfoliage maps

Definition at line 1355 of file Terrain2.cpp.

◆ createFoliageMaps() [2/2]

void createFoliageMaps ( float  terrainWidth,
float  terrainDepth,
vector< unordered_map< int, vector< Transformations > > > &  foliageMaps 
)
static

Create foliage maps.

Parameters
terrainWidthterrain width
terrainDepthterrain depth
foliageMapsfoliage maps

Definition at line 1365 of file Terrain2.cpp.

◆ createTerrainModels()

void createTerrainModels ( float  width,
float  depth,
float  y,
vector< float > &  terrainHeightVector,
BoundingBox terrainBoundingBox,
vector< Model * > &  terrainModels,
bool  createLODLevels = false 
)
static

Create terrain models.

Parameters
widthwidth
depthdepth
yfloat y
terrainHeightVectorterrain height vector
terrainBoundingBoxterrain bounding box
terrainModelsterrain models vector
createLODLevelscreate LOD Levels

Definition at line 70 of file Terrain2.cpp.

◆ createWaterModels()

void createWaterModels ( BoundingBox terrainBoundingBox,
const unordered_map< int, unordered_set< int > > &  waterPositionMap,
float  waterHeight,
int  waterModelIdx,
vector< Model * > &  waterModels 
)
static

Create partitioned water models using given water position map.

Parameters
terrainBoundingBoxterrain bounding box
waterPositionMapwater position map
waterHeightwaterHeight
waterModelIdxwater model index
waterModelswater models

Definition at line 1180 of file Terrain2.cpp.

◆ determineWater()

static bool determineWater ( const vector< float > &  terrainHeightVector,
int  verticesPerX,
int  verticesPerZ,
int  x,
int  z,
float  waterHeight 
)
inlinestaticprivate

Determine if water can be generated.

Parameters
terrainHeightVectorterrain height vector
verticesPerXvertices per x
verticesPerZvertices per z
xx
zz
waterHeightwater height
Returns
if water can be generated at given position

Definition at line 151 of file Terrain2.h.

◆ determineWaterXPositionSet()

static void determineWaterXPositionSet ( const vector< float > &  terrainHeightVector,
int  verticesPerX,
int  verticesPerZ,
int  x,
int  z,
float  waterHeight,
unordered_set< int > &  waterXPositionSet 
)
inlinestaticprivate

Determine if water can be generated from left to right starting with x and z.

Parameters
terrainHeightVectorterrain height vector
verticesPerXvertices per x
verticesPerZvertices per z
xx
zz
waterHeightwater height
waterXPositionSetwater x position set
Returns
if water can be generated at given position

Definition at line 171 of file Terrain2.h.

◆ emptyFoliageMaps()

void emptyFoliageMaps ( vector< unordered_map< int, vector< Transformations > > > &  foliageMaps)
static

Empty foliage maps.

Parameters
foliageMapsfoliage maps

Definition at line 1378 of file Terrain2.cpp.

◆ getTerrainModelsHeight()

bool getTerrainModelsHeight ( BoundingBox terrainBoundingBox,
vector< Model * > &  terrainModels,
vector< float > &  terrainHeightVector,
const Vector3 brushCenterPosition,
float &  brushHeight 
)
static

Get terrain models height for e.g.

flatten

Parameters
terrainBoundingBoxterrain bounding box
terrainModelsterrain models vector
terrainHeightVectorterrain height vector
brushHeightbrush height

Definition at line 1332 of file Terrain2.cpp.

◆ getTerrainVertex() [1/2]

static bool getTerrainVertex ( const vector< float > &  terrainHeightVector,
int  verticesPerX,
int  verticesPerZ,
int  x,
int  z,
Vector3 vertex 
)
inlinestaticprivate

Get the terrain vertex for given x and z position.

Parameters
terrainHeightVectorterrain height vector
verticesPerXvertices per x
verticesPerZvertices per z
xx
zz
Returns
terrain vertex

Definition at line 85 of file Terrain2.h.

◆ getTerrainVertex() [2/2]

static void getTerrainVertex ( int  x,
int  z,
Vector3 vertex 
)
inlinestaticprivate

Get the terrain vertex for given x and z position without providing y component.

Parameters
xx
zz
Returns
terrain vertex

Definition at line 69 of file Terrain2.h.

◆ getWaterVertex()

static void getWaterVertex ( int  x,
int  z,
float  waterHeight,
Vector3 vertex 
)
inlinestaticprivate

Get the terrain vertex for given x and z position.

Parameters
xx
zz
waterHeightwater height
vertexvertex

Definition at line 108 of file Terrain2.h.

◆ hasWaterPosition()

static bool hasWaterPosition ( const unordered_map< int, unordered_set< int > > &  waterPositionSet,
int  x,
int  z 
)
inlinestaticprivate
Returns
if water includes given position
Parameters
waterPositionSetwater position set
xx
zz

Definition at line 122 of file Terrain2.h.

◆ mirrorXAxis()

void mirrorXAxis ( bool  flipZ,
float  width,
float  depth,
vector< float > &  terrainHeightVector,
unordered_map< int, float > &  waterPositionMapsHeight,
unordered_map< int, unordered_map< int, unordered_set< int > > > &  waterPositionMaps,
vector< unordered_map< int, vector< Transformations > > > &  foliageMaps 
)
static

Mirror terrain around X axis.

Parameters
flipZflip Z
widthwidth
depthdepth
terrainHeightVectorterrain height vector
waterPositionMapsHeightwater position maps heights
waterPositionMapswater position maps
foliageMapsfoliage maps

Definition at line 2093 of file Terrain2.cpp.

◆ mirrorZAxis()

void mirrorZAxis ( bool  flipX,
float  width,
float  depth,
vector< float > &  terrainHeightVector,
unordered_map< int, float > &  waterPositionMapsHeight,
unordered_map< int, unordered_map< int, unordered_set< int > > > &  waterPositionMaps,
vector< unordered_map< int, vector< Transformations > > > &  foliageMaps 
)
static

Mirror terrain around Z axis.

Parameters
flipXflip X
widthwidth
depthdepth
terrainHeightVectorterrain height vector
waterPositionMapsHeightwater position maps heights
waterPositionMapswater position maps
foliageMapsfoliage maps

Definition at line 2189 of file Terrain2.cpp.

◆ updateFoliageTerrainBrush()

void updateFoliageTerrainBrush ( BoundingBox terrainBoundingBox,
vector< float > &  terrainHeightVector,
const Vector3 brushCenterPosition,
const FoliageBrush foliageBrush,
vector< unordered_map< int, vector< Transformations > > > &  foliageMaps,
unordered_set< int > &  updateFoliagePartitions 
)
static

Update foliage after using terrain brush.

Parameters
terrainBoundingBoxterrain bounding box
terrainHeightVectorterrain height vector
brushCenterPositionbrush center position
foliageBrushfoliage brush
foliageMapsfoliage maps
updateFoliagePartitionsupdate foliage partitions

Definition at line 1766 of file Terrain2.cpp.

◆ updateFoliageTerrainRampBrush()

void updateFoliageTerrainRampBrush ( BoundingBox terrainBoundingBox,
vector< float > &  terrainHeightVector,
const Vector3 brushCenterPosition,
Texture brushTexture,
float  brushRotation,
const Vector2 brushScale,
vector< unordered_map< int, vector< Transformations > > > &  foliageMaps,
unordered_set< int > &  updateFoliagePartitions 
)
static

Update foliage after using terrain ramp brush.

Parameters
terrainBoundingBoxterrain bounding box
terrainHeightVectorterrain height vector
brushCenterPositionbrush center position
brushTexturebrush texture
brushRotationbrush rotation
brushScalebrush scale
foliageMapsfoliage maps
updateFoliagePartitionsupdate foliage partitions

Definition at line 1922 of file Terrain2.cpp.

Member Data Documentation

◆ PARTITION_SIZE

constexpr float PARTITION_SIZE { 64.0f }
staticconstexpr

Definition at line 36 of file Terrain2.h.

◆ STEP_SIZE

constexpr float STEP_SIZE { 1.0f }
staticconstexpr

Definition at line 35 of file Terrain2.h.


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