My Project
|
This class represents a single, contiguous chunk of terrain and is the primary public interface to Demeter. More...
#include <Terrain.h>
Classes | |
struct | DestroyStaticObject_ |
this is a dummy object that to ensure static objects are destroyed properly More... | |
Public Member Functions | |
Terrain () | |
Constructs a (mostly) empty terrain suitable for use by an ElevationLoader. | |
Terrain (const float *pElevations, int elevWidth, int elevHeight, const uint8 *pTextureImage, int textureWidth, int textureHeight, const uint8 *pDetailTextureImage, int detailWidth, int detailHeight, float vertexSpacing, float elevationScale, int maxNumTriangles, float offsetX=0.0f, float offsetY=0.0f) | |
Constructs a new terrain from raw elevation and image data in memory buffers. More... | |
Terrain (int widthVertices, int heightVertices, float vertexSpacing, int maxNumTriangles) | |
By using this constructor, you are specifying the layout of all of the vertices in the Terrain's mesh. More... | |
Terrain (int maxNumTriangles, float offsetX, float offsetY) | |
Constructs a (mostly) empty terrain suitable for use by an ElevationLoader. More... | |
virtual int | GetAttributeClassID () |
attribute class ID should be identical, unless one knows how overriding rules work. More... | |
virtual const char * | GetAttributeClassName () |
a static string, describing the attribute class object's name | |
virtual const char * | GetAttributeClassDescription () |
a static string, describing the attribute class object | |
virtual int | InstallFields (CAttributeClass *pClass, bool bOverride) |
this class should be implemented if one wants to add new attribute. More... | |
virtual bool | InvokeEditor (int nFieldID, const string &sParameters) |
Invoke an (external) editor for a given field. More... | |
ATTRIBUTE_METHOD1 (Terrain, IsModified_s, bool *) | |
ATTRIBUTE_METHOD1 (Terrain, SetModified_s, bool) | |
ATTRIBUTE_METHOD1 (Terrain, IsEmpty_s, bool *) | |
ATTRIBUTE_METHOD1 (Terrain, GetSize_s, float *) | |
ATTRIBUTE_METHOD1 (Terrain, GetOnloadScript_s, const char **) | |
ATTRIBUTE_METHOD1 (Terrain, GetTerrainElevFile_s, const char **) | |
ATTRIBUTE_METHOD1 (Terrain, GetTerrainConfigFile_s, const char **) | |
ATTRIBUTE_METHOD1 (Terrain, GetTerrainBaseTextureFile_s, const char **) | |
ATTRIBUTE_METHOD1 (Terrain, SetTerrainBaseTextureFile_s, const char *) | |
ATTRIBUTE_METHOD1 (Terrain, GetTerrainCommonTextureFile_s, const char **) | |
ATTRIBUTE_METHOD1 (Terrain, SetTerrainCommonTextureFile_s, const char *) | |
ATTRIBUTE_METHOD1 (Terrain, GetNumOfRegions_s, int *) | |
ATTRIBUTE_METHOD1 (Terrain, GetCurrentRegionIndex_s, int *) | |
ATTRIBUTE_METHOD1 (Terrain, SetCurrentRegionIndex_s, int) | |
ATTRIBUTE_METHOD1 (Terrain, GetCurrentRegionName_s, const char **) | |
ATTRIBUTE_METHOD1 (Terrain, SetCurrentRegionName_s, const char *) | |
ATTRIBUTE_METHOD1 (Terrain, GetCurrentRegionFilepath_s, const char **) | |
ATTRIBUTE_METHOD1 (Terrain, SetCurrentRegionFilepath_s, const char *) | |
void | Cleanup () |
clean up all | |
bool | IsModified () |
whether the terrain geometry, texture has been modified. More... | |
bool | IsModified (DWORD dwModifiedBits) |
return true if any part specified in dwModifiedBits has been modified. More... | |
void | SetModified (bool bIsModified, DWORD dwModifiedBits) |
Turn on/off the specified flag indicating whether the terrain has been modified or not. More... | |
bool | IsEmpty () |
whether the terrain is a fake terrain without vertices. More... | |
void | SetModified (bool bIsModified) |
set the terrain modified to true for all parts of the terrain. More... | |
void | InitDeviceObjects () |
this function currently does nothing | |
void | DeleteDeviceObjects () |
must call this function when device is lost. | |
void | InvalidateDeviceObjects () |
must call this function when device is invalid. | |
int | Tessellate () |
Breaks the Terrain down into triangles strips. More... | |
void | RepairCracks () |
repair cracks during tessellation. More... | |
void | RebuildRenderBuffer () |
Rebuild the rendering buffer from triangle strips and fans generated from Tessellate() and RepairCracks(). More... | |
void | Render () |
Render the terrain from Render Buffer. More... | |
string | GetRenderReport () |
get the rendering report string for debugging purposes | |
void | SetDetailThreshold (float threshold) |
Sets the "detail threshold", which controls how much Demeter simplifies the terrain. More... | |
float | GetDetailThreshold () const |
Returns the "detail threshold.". | |
void | SetMaximumVisibleBlockSize (int stride) |
Sets the maximum size of blocks that can be simplified when the terrain is tessellated. More... | |
int | GetMaximumVisibleBlockSize () |
int | GetWidthVertices () const |
Returns the width of the terrain in vertices (this is the count of vertices along the world's x-axis.) | |
int | GetHeightVertices () const |
Returns the height of the terrain in vertices (this is the count of vertices along the world's y-axis.) | |
float | GetWidth () const |
Returns the width of the terrain in world units (this is the length of the terrain along the world's x-axis.) | |
float | GetHeight () const |
Returns the height of the terrain in world units (this is the length of the terrain along the world's y-axis.) | |
float | GetVertexSpacing () const |
Returns the number of real units between vertices in the terrain's mesh. | |
float | GetElevation (float x, float y) const |
Returns the elevation (z-coordinate) in real units of the specified point on the terrain. More... | |
float | GetElevationW (float x, float y) const |
Returns the elevation (z-coordinate) in real units of the specified point on the terrain. More... | |
DWORD | GetRegionValue (const string &sLayerName, float x, float y) |
get value of a given terrain region layer More... | |
DWORD | GetRegionValueW (const string &sLayerName, float x, float y) |
get value of a given terrain region layer More... | |
float | GetElevation (int index) const |
Returns the elevation (z-coordinate) in real units of the specified terrain vertex. More... | |
void | GetNormal (float x, float y, float &normalX, float &normalY, float &normalZ) const |
Returns the surface normal of the terrain at the specified point. More... | |
void | GetNormalW (float x, float y, float &normalX, float &normalY, float &normalZ) const |
Returns the surface normal of the terrain at the specified point. More... | |
float | GetMaxElevation () const |
Returns the elevation (z-coordinate) in real units of the highest point on the terrain. | |
int | GetVertex (float x, float y) const |
Returns the index of the vertex closest to the specified point. More... | |
int | GetVertexW (float x, float y) const |
Returns the index of the vertex closest to the specified point. More... | |
float | GetVertexElevation (int index) const |
Returns the elevation (z-coordinate) in real units of the specified vertex on the terrain. More... | |
void | SetVertexElevation (int index, float newElevation, bool recalculate_geometry=true) |
Sets the elevation (z-coordinate) in real units of the specified vertex on the terrain. More... | |
void | SetVertexElevation (float x, float y, float newElevation) |
Sets the elevation (z-coordinate) in real units of the nearest vertex to the specified point. More... | |
void | SetHole (float x, float y, bool bIsHold) |
set a new terrain hole at the specified location. More... | |
void | SetHoleLocal (float x, float y, bool bIsHold) |
set a new terrain hole at the specified local location. More... | |
void | UpdateHoles () |
call this function after you have set new holes in the terrain. | |
void | SetHoleScale (int nHoleScale) |
this value can only be a power of 2, such as 2, 4, 8, etc. More... | |
bool | IsHole (float x, float y) |
Whether the terrain contains a hole at the specified location. More... | |
bool | IsHoleW (float x, float y) |
Whether the terrain contains a hole at the specified location. More... | |
void | CreateHoleMap (BYTE *pHoleData=NULL, int nLength=0) |
create hole map from terrain hole map. More... | |
void | RecalcGeometry (int index1, int index2) |
Recalculates bounding box for the quad spanning from vertex 1 to vertex 2. More... | |
void | RecalcGeometry () |
recalculate the entire terrain. More... | |
void | RecalcNormal (float x, float y) |
Recalculates the normal vector of the vertex closes to the specified point. More... | |
void | RecalcNormal (int vertexIndex) |
Recalculates the normal vector of the specified vertex. More... | |
void | SetAllElevations (const float *pElevations, int elevWidth, int elevHeight, float fTerrainSize, float elevationScale=1.0f) |
Replaces all of the Terrain's vertices with a new set of vertices. More... | |
int | GetNumberOfVertices () const |
Returns the total number of vertices in the terrain's mesh. | |
float | GetTextureTileWidth () const |
Returns the width (in vertices) of the terrain's texture cells. See the TextureCell class. | |
float | GetTextureTileHeight () const |
Returns the height (in vertices) of the terrain's texture cells. See the TextureCell class. | |
int | GetNumberOfTextureTilesWidth () const |
Returns the number of texture cells along the terrain's x-axis. See the TextureCell class. | |
int | GetNumberOfTextureTilesHeight () const |
Returns the number of texture cells along the terrain's y-axis. See the TextureCell class. | |
bool | SetTexture (const uint8 *pTextureImage, int width, int height) |
Applies the specified graphics image as a texture to the terrain. More... | |
bool | SetBaseTexture (const string &filename, int numTextureCellsX=8, int numTextureCellsY=8) |
Set the base texture to texture cells. More... | |
bool | SetCommonTexture (const uint8 *pImage, int width, int height) |
Uses the specified graphics image to apply a "common" texture to the entire surface of the terrain. More... | |
void | SetCommonTexture (const char *fileName) |
Uses the specified Texture to apply a "common" texture to the entire surface of the terrain. More... | |
void | SetCommonTexture (Texture *pTexture) |
A common texture is repeated across the entire terrain and is blended with the terrain's overall texture (if blending is supported by the user's hardware.) This is used to provide a texture to give the ground some definition when the camera is close to the ground, but is an inferior to alternative to the use of specific DetailTexture instances. More... | |
Texture * | GetCommonTexture () const |
Returns the Texture object representing the common texture that has been applied to the Terrain, if any. | |
int | ModelViewMatrixChanged () |
Notifies Demeter that OpenGL's modelview matrix has been modified, allowing Demeter to tessellate the terrain based on the new modelview matrix. More... | |
int | CuboidInFrustum (const CShapeBox &cuboid) const |
Indicates whether or not the specified cuboid is inside of the viewing frustum (as defined at the previous call to ModelViewMatrixChanged().) More... | |
bool | CuboidInFogRadius (const CShapeBox &cuboid) const |
return true if the cuboid intersect with the Fog End radius More... | |
Plane::Side | GetCuboidFogSide (const CShapeBox &cuboid) const |
return which side the cuboid is on | |
void | BoxToRenderCoordinate (CShapeBox &cuboid) const |
convert the box to render coordinate system | |
float | GetBoxToEyeMatrics (const CShapeBox &cuboid) const |
get a length matrics from the box to the current eye position. More... | |
float | IntersectRayW (float startX, float startY, float startZ, float dirX, float dirY, float dirZ, float &intersectX, float &intersectY, float &intersectZ, float fMaxDistance=INFINITY) |
Casts a ray from the specified point, in the specified direction, and calculates the ray's point of intersection with the terrain. More... | |
float | IntersectRay (float startX, float startY, float startZ, float dirX, float dirY, float dirZ, float &intersectX, float &intersectY, float &intersectZ, float fMaxDistance=INFINITY) |
Casts a ray from the specified point, in the specified direction, and calculates the ray's point of intersection with the terrain. More... | |
float | IntersectRay (float startX, float startY, float startZ, float dirX, float dirY, float dirZ, float &intersectX, float &intersectY, float &intersectZ, int &textureCellX, int &textureCellY, float &texU, float &texV, float fMaxDistance=INFINITY) |
An overload of IntersectRay that also provides information about the texture coordinates of the intersected point in addition the position of the point. More... | |
bool | Pick (int screenX, int screenY, float &pickedX, float &pickedY, float &pickedZ) const |
Quickly find the 3D point on the terrain where a given point on the screen is (for example, for mouse picking.) More... | |
bool | Pick (int screenX, int screenY, float &pickedX, float &pickedY, float &pickedZ, int &textureCellX, int &textureCellY, float &texU, float &texV) const |
Quickly find the 3D point on the terrain where a given point on the screen is (for example, for mouse picking.) More... | |
void | GetTextureCoordinates (float x, float y, int &textureCellX, int &textureCellY, float &texU, float &texV) const |
Returns the texture coordinates of a given point on the terrain in world coordinates. More... | |
void | Paint (ParaEngine::TextureEntity *detailTexture, float brushRadius, float brushIntensity, float maxIntensity, bool erase, float x, float y) |
Paints a "splat" of the specified shared texture at the specified position on the terrain in world coordinates. More... | |
void | Paint (int detailTextureIndex, float brushRadius, float brushIntensity, float maxIntensity, bool erase, float x, float y) |
bool | IsMultiTextureSupported () const |
Indicates whether or not OpenGL multitexture extensions are available from the OpenGL driver that this terrain instance is currently rendering against (as determined at the time the terrain instance was first constructed.) | |
void | SetLatticePosition (int x, int y) |
Sets this Terrain object's location within a lattice of Terrains that are being managed by a TerrainLattice object. More... | |
void | GetLatticePosition (int &x, int &y) |
Gets this Terrain object's location within a lattice of Terrains that are being managed by a TerrainLattice object. More... | |
void | SetTextureFactory (TextureFactory *pFactory) |
Installs an application-provided TextureFactory, disabling the default one supplied by Demeter. More... | |
TextureCell * | GetTextureCell (int index) |
Gets the TextureCell at the specified position within this Terrain's grid of cells. More... | |
TextureCell * | GetTextureCellW (float x, float y) |
Get the texture cell by world coordinate position. | |
TextureCell * | GetTextureCell (int textureCellX, int textureCellY) |
Gets the TextureCell at the specified position within this Terrain's grid of cells. More... | |
void | Write (char *szFilename) |
Writes a binary "surface" file for fine-grained detail textures. More... | |
void | Read (char *szFilename) |
Reads a binary "surface" file for fine-grained detail textures. More... | |
TextureSet * | GetTextureSet () |
Gets the TextureSet that represents this Terrain object's pool of shared Textures. | |
void | SetTextureSet (TextureSet *pTextureSet) |
Sets the TextureSet that represents this Terrain object's pool of shared Textures. More... | |
void | SetTextureCell (int index, TextureCell *pCell) |
Installs a new TextureCell at the specified position within this Terrain's grid of TextureCells. More... | |
void | WriteRawTextures (const char *szTerrainName) |
Write all of this Terrain's textures to raw binary files. More... | |
void | WriteRawElevations (const char *szFilename) |
Write all of this Terrain's vertices to a raw binary file. More... | |
void | AllocateTextureCells (int numTextureCellsX, int numTextureCellsY) |
Sets the size of this Terrain's grid of TextureCell objects. More... | |
void | GenerateTexture (int widthTexels, int heightTexels, const char *szGeneratorName) |
void | GenerateTexture (int widthTexels, int heightTexels, TextureGenerator *pGenerator) |
int | GetBaseTextureWidth () |
Returns the width of the overall terrain texture in pixels. | |
int | GetBaseTextureHeight () |
Returns the height of the overall terrain texture in pixels. | |
void | ref () const |
Increment the reference count by one, indicating that this object has another pointer which is referencing it. More... | |
void | unref () const |
Decrement the reference count by one, indicating that a pointer to this object is referencing it. More... | |
uint8 * | GetMaskBits (int textureCellX, int textureCellY, int detailIndex, int &maskWidth, int &maskHeight) |
Gets the raw bits of the alpha mask of the specified detail texture within the specified TextureCell. | |
void | ReloadMask (int textureCellX, int textureCellY, int detailIndex) |
Unbinds and rebinds the alpha mask of the specified TextureCell so that changes to the mask become visible when rendering. | |
void | LoadMaskFromDisk (bool bForceReload=false) |
load the terrain mask file from disk once again. More... | |
int | NormalizeMask (int textureCellX, int textureCellY, int detailIndex, bool bReload=true) |
normalize the given texture mask layer, so that the alpha of the specified layer is unchanged and the sum of all alpha values of all mask layers at all pixels in the cell is 1. More... | |
void | SetOffset (float x, float y) |
Set this Terrain object's origin. More... | |
float | GetOffsetX () const |
Gets this Terrain object's origin. More... | |
float | GetOffsetY () const |
Gets this Terrain object's origin. More... | |
void | DigCrater (float centerX, float centerY, float radius, int textureId=-1) |
void | GetVertices (float centerX, float centerY, float radius, std::vector< TerrainVertex > &vertices) |
const string & | GetOnloadScript () |
get the on load script which created all objects on this terrain. More... | |
const string & | GetTerrainElevFile () |
get the terrain elevation file | |
const string & | GetTerrainConfigFile () |
get the terrain elevation file | |
const string & | GetTerrainBaseTextureFile () |
get the terrain base texture file | |
void | SetTerrainBaseTextureFile (const string &str) |
const string & | GetTerrainCommonTextureFile () |
get the terrain common texture file | |
void | SetTerrainCommonTextureFile (const string &str) |
CShapeBox | GetBoundingBoxW () |
Get the bounding box from the last tessellation result. More... | |
void | GetBoundingBoxes (vector< CShapeAABB > &boxes, const Matrix4 *modelView, const CShapeFrustum &frustum, int nMaxBoxesNum=1024, int nSmallestBoxStride=4) |
Get the bounding boxes for a given view frustum. More... | |
DetailTexture * | GetDefaultBaseLayerMask () |
get the default base layer mask. More... | |
CTerrainRegions * | GetRegions () |
get the regions defined in this terrain. More... | |
CTerrainRegions * | CreateGetRegions () |
create region object if not created before. More... | |
int | GetNumOfRegions () |
get number terrain regions | |
void | SetCurrentRegionIndex (int nRegion) |
set terrain region index, so that we can later call GetCurrentRegionName() and GetCurrentRegionFilepath(), to access region properties. | |
int | GetCurrentRegionIndex () |
Get terrain region index, so that we can later call GetCurrentRegionName() and GetCurrentRegionFilepath(), to access region properties. More... | |
void | SetCurrentRegionName (const string &name) |
set the currently selected region name. More... | |
const string & | GetCurrentRegionName () |
get the currently selected region name. More... | |
void | SetCurrentRegionFilepath (const string &filename) |
set the current region file path. More... | |
const string & | GetCurrentRegionFilepath () |
get the current region file path. More... | |
int | GetTextureIDbyPoint (float x, float y, float &tileX, float &tileY) |
get texture ID by point. More... | |
void | GetLowResTexCord (int nIndex, float &u, float &v) |
load detailed (high-res) textures, which is usually a large collection of files More... | |
void | GetHighResTexCord (int nIndex, float &u, float &v) |
Get the high-res texture coordinate at a specified vertex index. | |
void | GetTexCord (int nIndex, float &lowU, float &lowV, float &detailU, float &detailV) |
get both low resolution and detailed texture coordinates | |
void | SetHighResTextureRadius (float radius) |
set the radius in world coordinates, within eye position of which high-res textures will be used if possible. | |
float | GetHighResTextureRadius () |
Gets the radius setting as set in a call to SetHighResTextureRadius(). | |
void | SetDetailTextureRepeats (float repeats) |
Specifies how many times detail textures are repeated within their parent textures. Higher values will make the detail textures smaller. | |
float | GetDetailTextureRepeats () |
Gets the repeats setting as set in a call to SetDetailTextureRepeats(). | |
void | SetLowestVisibleHeight (float fHeight) |
Set the height of the lowest visible terrain point. More... | |
float | GetLowestVisibleHeight () |
Get the height of the lowest visible terrain point. More... | |
void | GetMaskFile (string &sMaskFile, const string &sConfigFile) |
compute mask file from the terrain config file. More... | |
bool | SaveConfig (const string &filePath) |
save terrain configurations to file. More... | |
bool | SaveElevation (const string &filePath) |
save terrain height map to file. More... | |
bool | SaveDetailTexture (const string &filePath) |
save detail texture to texture mask file. More... | |
bool | LoadFromConfigFile (const char *sFileName, float fSize=0, const char *relativePath=NULL) |
Load from Configuration file. More... | |
void | OnLoad () |
this function is automatically called after the terrain has been loaded. More... | |
bool | SaveToFile (const char *filename=NULL) |
Save Terrain to file according to the modified bits. More... | |
bool | ReadMaskFile (CParaFile &fileMask) |
read mask file | |
void | ResizeTextureMaskWidth (int nWidth) |
resize all texture mask width More... | |
void | SetSharedIB (ParaIndexBuffer ib) |
void | SwitchLodStyle (bool useGeoMipmap, ParaIndexBuffer pSharedIndices, GeoMipmapIndicesGroup *geoMipmapIndicesGroup) |
void | SetSharedIndexInfoGroup (GeoMipmapIndicesGroup *geoMipmapIndicesGroup) |
void | BuildGeoMipmapBuffer () |
void | RenderGeoMipmap () |
void | TessellateGeoMipmap () |
void | BuildGeoMipmapBlocks () |
void | SetBlockLod (int indexX, int indexY, int level, GeoMipmapChunkType chunkType) |
bool | IsWalkable (float x, float y) const |
bool | IsWalkableW (float x, float y) const |
void | SetTerrainInfoData (const uint32 *pInfoData, int width) |
void | SetVertexInfo (int idx, uint32 data, uint32 bitMask, uint32 bitOffset) |
uint32 | GetVertexInfo (int idx, uint32 bitMask, uint8 bitOffset) |
void | RefreshTerrainInfo () |
bool | IsWalkable (float x, float y, Vector3 &oNormal) const |
void | SetVisibleDataMask (uint32 mask, uint8 bitOffset) |
void | SetEditorMode (bool enable) |
![]() | |
virtual int | GetChildAttributeColumnCount () |
we support multi-dimensional child object. More... | |
virtual int | GetChildAttributeObjectCount (int nColumnIndex=0) |
get the number of child objects (row count) in the given column. More... | |
virtual IAttributeFields * | GetChildAttributeObject (int nRowIndex, int nColumnIndex=0) |
virtual IAttributeFields * | GetChildAttributeObject (const std::string &sName) |
get attribute by child object. More... | |
ATTRIBUTE_METHOD1 (IAttributeFields, GetName_s, const char **) | |
ATTRIBUTE_METHOD1 (IAttributeFields, SetName_s, const char *) | |
ATTRIBUTE_METHOD (IAttributeFields, PrintObject_s) | |
ATTRIBUTE_METHOD (IAttributeFields, AddRef_s) | |
ATTRIBUTE_METHOD1 (IAttributeFields, GetRefCount_s, int *) | |
ATTRIBUTE_METHOD1 (IAttributeFields, SetTime_s, int) | |
ATTRIBUTE_METHOD1 (IAttributeFields, GetTime_s, int *) | |
ATTRIBUTE_METHOD (IAttributeFields, Release_s) | |
virtual const std::string & | GetIdentifier () |
virtual void | SetIdentifier (const std::string &sID) |
virtual bool | ValidateFields () |
validate all fields and return true if validation passed. More... | |
virtual string | GetValidationMessage () |
get the recent validation message due to the most recent call to ValidateFields() | |
virtual bool | ResetField (int nFieldID) |
Reset the field to its initial or default value. More... | |
virtual bool | InvokeEditor (int nFieldID, const std::string &sParameters) |
Invoke an (external) editor for a given field. More... | |
virtual bool | AddChildAttributeObject (IAttributeFields *pChild, int nRowIndex=-1, int nColumnIndex=0) |
add child object. More... | |
virtual void * | QueryObjectByName (const std::string &sObjectType) |
convert to object of a given type. More... | |
virtual void * | QueryObject (int nObjectType) |
convert to object of a given type. More... | |
virtual int | GetTime () |
get the current local time in case it is animated in milli seconds frames. More... | |
virtual void | SetTime (int nTime) |
virtual CDynamicAttributeField * | GetDynamicField (const std::string &sName) |
Get a dynamic field with a given name. More... | |
virtual CDynamicAttributeField * | GetDynamicField (int nIndex) |
Get a dynamic field with a given index. More... | |
virtual const char * | GetDynamicFieldNameByIndex (int nIndex) |
get field name by index | |
virtual int | GetDynamicFieldCount () |
how many dynamic field this object currently have. More... | |
virtual int | SetDynamicField (const std::string &sName, const CVariable &value) |
set a dynamic field with a given name. More... | |
virtual int | AddDynamicField (const std::string &sName, ATTRIBUTE_FIELDTYPE dwType) |
add dynamic field and return field index | |
virtual void | RemoveAllDynamicFields () |
remove all dynamic fields | |
virtual int | SaveDynamicFieldsToString (std::string &output) |
save only text dynamic fields to fieldname = value text strings. More... | |
virtual int | LoadDynamicFieldsFromString (const std::string &input) |
load only text dynamic fields from string More... | |
CAttributeClass * | GetAttributeClass () |
get the main attribute class object. More... | |
void | PrintObject () |
print the content of this object to a text file at temp/doc/[ClassName].txt. More... | |
![]() | |
virtual void | Clone (IObject *obj) const |
Clone the object's contains to a pointer. More... | |
virtual IObject * | Clone () const |
Clone the object's contains and return a pointer to the newly created object. More... | |
virtual bool | Equals (const IObject *obj) const |
Compare the object with another object. More... | |
virtual const IType * | GetType () const |
virtual std::string | ToString () const |
WeakPtr_type & | GetWeakReference () |
get weak reference object. More... | |
virtual int | ProcessObjectEvent (const ObjectEvent &event) |
this function is only used to backward compatibility of ParaObject:AddEvent() function. More... | |
![]() | |
void | addref () const |
add reference count of the object. More... | |
bool | delref () const |
decrease reference count of the object. More... | |
int | GetRefCount () const |
get the reference count | |
virtual int | Release () |
CRefCounted * | AddToAutoReleasePool () |
addref and releases the ownership sometime soon automatically (usually at the end of the current frame). More... | |
Static Public Member Functions | |
static void | RegisterTextureGenerator (std::string name, TextureGenerator *pGenerator) |
static void | RegisterDefaultGenerators () |
static void | StaticInitUV (int nWidthVertices, int nNumberOfTextureTiles, int nDetailTextureRepeats) |
init static UV coordinate constants, so that we need not calculate at runtime | |
![]() | |
static HRESULT | GetAttributeClassID_s (IAttributeFields *cls, int *p1) |
static HRESULT | GetAttributeClassName_s (IAttributeFields *cls, const char **p1) |
static bool | OpenWithDefaultEditor (const char *sFilename, bool bWaitOnReturn=false) |
Open a given file with the default registered editor in the game engine. More... | |
Public Attributes | |
ParaTerrain::CDetailTextureFactory * | m_pDetailedTextureFactory |
for high-res texture of terrain surfaces | |
bool | m_useGeoMipmap |
Static Public Attributes | |
static Vector2 * | s_LowResTexCords = NULL |
array of low resolution texture coordinates. More... | |
static Vector2 * | s_HighResTexCords = NULL |
array of high resolution texture coordinates. More... | |
Protected Member Functions | |
bool | GenerateTerrainNormal (bool bForceRegenerate=false) |
generate terrain normal for rendering with light on. More... | |
![]() | |
virtual CAttributeClass * | CreateAttributeClass () |
initialize fields | |
virtual CDynamicAttributesSet * | GetDynamicAttributes (bool bCreateIfNotExist=false) |
Friends | |
class | Triangle |
class | TriangleStrip |
class | TerrainBlock |
class | TriangleFan |
class | TerrainLattice |
class | TerrainBuffer |
class | Loader |
class | TextureSet |
Additional Inherited Members | |
![]() | |
typedef ParaEngine::weak_ptr< IObject, IAttributeFields > | WeakPtr_type |
![]() | |
typedef ParaEngine::weak_ptr< IObject > | WeakPtr_type |
![]() | |
WeakPtr_type | m_weak_reference |
![]() | |
int | m_refcount |
This class represents a single, contiguous chunk of terrain and is the primary public interface to Demeter.
Most applications will create a single instance of this class to represent the terrain in the application, but multiple instances can be used to stitch together a very large world comprised of multiple terrains using the TerrainLattice class. The simplest way to use this class to make a new instance using the constructor that takes no parameters and then use an ElevationLoader and a TextureLoader to give it vertices and textures. Alternatively, you can use the constructor that takes arrays of floats and bytes if you wish to load your own elevation and texture data.
Terrain::Terrain | ( | const float * | pElevations, |
int | elevWidth, | ||
int | elevHeight, | ||
const uint8 * | pTextureImage, | ||
int | textureWidth, | ||
int | textureHeight, | ||
const uint8 * | pDetailTextureImage, | ||
int | detailWidth, | ||
int | detailHeight, | ||
float | vertexSpacing, | ||
float | elevationScale, | ||
int | maxNumTriangles, | ||
float | offsetX = 0.0f , |
||
float | offsetY = 0.0f |
||
) |
Constructs a new terrain from raw elevation and image data in memory buffers.
By using this constructor, you are specifying the layout of all of the vertices in the Terrain's mesh. These vertices are always a rectangular grid of 3D points at regularly spaced intervals. You are also specifying what the overall terrain texture looks like.
pElevations | An array of floating point values representing the elevation (z value) of each vertex in the terrain's mesh. The size of this array must be equal to elevWidth * elevHeight |
elevWidth | The number of vertices along the x-axis (width) of the grid of vertices in pElevations. |
elevHeight | The number of vertices along the y-axis (height) of the grid of vertices in pElevations. |
pTextureImage | An array of byte values representing the texture image that will be draped across the entire surface of the Terrain (this is the "overall" texture.) The array must contain 3 bytes per pixel - the red, green, and blue color values of the pixel respectively. It is assumed that the array does not contain any extra padding per image row. Therefore, if your image is 1024x1024 pixels, then this array should be 9,437,184 bytes in size. You can pass NULL for this parameter to build a Terrain with no texture. |
textureWidth | The width of the texture image in pixels. |
textureHeight | The height of the texture image in pixels. |
pDetailTextureImage | This is similar to the pTextureImage parameter, but instead of describing the overall terrain texture, this buffer buffer describes the "common" texture. See Terrain::SetCommonTexture() for details. You can pass NULL for this parameter to build a Terrain with no common texture. |
detailWidth | The width of the detail texture image in pixels. |
detailHeight | The height of the detail texture image in pixels. |
vertexSpacing | The distance, in world modeling units, between vertices in the Terrain's mesh. This distance is constant in both the horizontal and vertical directions. For example, if your pass in an array of 1024x1024 vertices for the pElevations and elevWidth and elevHeight parameters, and pass a value of 10.0 for the vertexSpacing parameter, then the resulting Terrain will be 10240 x 10240 world units in size. |
elevationScale | A scaling factor that is applied to all of the values in the pElevations array. Most applications will pass a 1.0 for this value since presumably pElevations was built by the application. |
maxNumTriangles | The maximum number of triangles that the Terrain is allowed to tessellate to when rendering. This number should be relatively high and is chosen based on what you know about the geometry of your terrain. For example, if your terrain is typical then a value of 40000 works well, but if you know your Terrain contains numerous canyons and sharp cliffs that will tessellate to lots of triangles, you might need to raise this value to something on the order of 60000. The higher this number, the more memory the Terrain will use for tessellation. |
offsetX | Horizontal translation of this Terrain in world units. See Terrain::SetOffserX(). |
offsetY | Vertical translation of this Terrain in world units. See Terrain::SetOffserY(). |
Terrain::Terrain | ( | int | widthVertices, |
int | heightVertices, | ||
float | vertexSpacing, | ||
int | maxNumTriangles | ||
) |
By using this constructor, you are specifying the layout of all of the vertices in the Terrain's mesh.
This version of the constructor creates a Terrain that is a flat plane with elevations of zero at all vertices. Otherwise, it is identical to the constructor that takes pElevations.
widthVertices | The number of vertices along the x-axis (width) of the grid of vertices in the mesh. |
heightVertices | The number of vertices along the y-axis (height) of the grid of vertices in the mesh. |
vertexSpacing | The distance, in world modeling units, between vertices in the Terrain's mesh. This distance is constant in both the horizontal and vertical directions. For example, if your pass in an array of 1024x1024 vertices for the pElevations and elevWidth and elevHeight parameters, and pass a value of 10.0 for the vertexSpacing parameter, then the resulting Terrain will be 10240 x 10240 world units in size. |
maxNumTriangles | The maximum number of triangles that the Terrain is allowed to tessellate to when rendering. This number should be relatively high and is chosen based on what you know about the geometry of your terrain. For example, if your terrain is typical then a value of 40000 works well, but if you know your Terrain contains numerous canyons and sharp cliffs that will tessellate to lots of triangles, you might need to raise this value to something on the order of 60000. The higher this number, the more memory the Terrain will use for tessellation. |
Terrain::Terrain | ( | int | maxNumTriangles, |
float | offsetX, | ||
float | offsetY | ||
) |
Constructs a (mostly) empty terrain suitable for use by an ElevationLoader.
maxNumTriangles | The maximum number of triangles that the Terrain is allowed to tessellate to when rendering. This number should be relatively high and is chosen based on what you know about the geometry of your terrain. For example, if your terrain is typical then a value of 40000 works well, but if you know your Terrain contains numerous canyons and sharp cliffs that will tessellate to lots of triangles, you might need to raise this value to something on the order of 60000. The higher this number, the more memory the Terrain will use for tessellation. |
offsetX | Horizontal translation of this Terrain in world units. See Terrain::SetOffserX(). |
offsetY | Vertical translation of this Terrain in world units. See Terrain::SetOffserY(). |
void Terrain::AllocateTextureCells | ( | int | numTextureCellsX, |
int | numTextureCellsY | ||
) |
Sets the size of this Terrain's grid of TextureCell objects.
You must specify a number of cells such that the following equation evalues to integral values for tw
and tv
, otherwise your Terrain will show seams between textures:
CTerrainRegions * Terrain::CreateGetRegions | ( | ) |
create region object if not created before.
void Terrain::CreateHoleMap | ( | BYTE * | pHoleData = NULL , |
int | nLength = 0 |
||
) |
create hole map from terrain hole map.
pHoleData | if this value is NULL, a blank hole map without any holes will be created. Otherwise, it is interpreted as an array of X*X BYTE values. If the BYTE value is 1, it is interpreted as a hole, otherwise it is false. |
bool Terrain::CuboidInFogRadius | ( | const CShapeBox & | cuboid | ) | const |
return true if the cuboid intersect with the Fog End radius
cuboid | make sure this is in local terrain coordinate system. |
int Terrain::CuboidInFrustum | ( | const CShapeBox & | cuboid | ) | const |
Indicates whether or not the specified cuboid is inside of the viewing frustum (as defined at the previous call to ModelViewMatrixChanged().)
Please notice that the original Demeter terrain has the height info saved in z axis, yet, in ParaEngine, it is in y axis.
cuboid | : The box to test. make sure this is in local terrain coordinate system. |
So we secretly exchanged z,y during culling with the camera.
set whether we will use 8 points of the cuboid for frustum test or else using standard AABB test
if true, we will treat the far plane as a spherical plane when doing occlusion testing
|
protected |
generate terrain normal for rendering with light on.
This function will only generate normal when the m_pNormal is NULL.
bForceRegenerate | true to regenerate any way. |
void Terrain::GenerateTexture | ( | int | widthTexels, |
int | heightTexels, | ||
const char * | szGeneratorName | ||
) |
void Terrain::GenerateTexture | ( | int | widthTexels, |
int | heightTexels, | ||
TextureGenerator * | pGenerator | ||
) |
|
inlinevirtual |
attribute class ID should be identical, unless one knows how overriding rules work.
Reimplemented from ParaEngine::IAttributeFields.
void Terrain::GetBoundingBoxes | ( | vector< CShapeAABB > & | boxes, |
const Matrix4 * | modelView, | ||
const CShapeFrustum & | frustum, | ||
int | nMaxBoxesNum = 1024 , |
||
int | nSmallestBoxStride = 4 |
||
) |
Get the bounding boxes for a given view frustum.
The returned boxes are always in world coordinate with render origin applied and transform by modelView
boxes | [in|out] |
modelView | if not null, all returned boxes will be transformed by it, before testing with the frustum |
frustum | the view frustum to test against. |
nMaxBoxesNum | maximum number of boxes returned. Since it internally uses a breadth first traversal of the terrain quad tree, larger boxes will return when there are more boxes in the frustum than nMaxBoxesNum |
nSmallestBoxStride | what is the stride size of the smallest boxes returned. |
breadth first transversing the quad tree
CShapeBox Terrain::GetBoundingBoxW | ( | ) |
Get the bounding box from the last tessellation result.
The returned box is always in world coordinate.
float Terrain::GetBoxToEyeMatrics | ( | const CShapeBox & | cuboid | ) | const |
get a length matrics from the box to the current eye position.
LiXizhi 2009.2.15: http://www.gamasutra.com/features/20000228/ulrich_02.htm This one just determines whether to tesselate according to camera-quad distance, instead of using screen space metrics. bc[x,y,z] == coordinates of box center ex[x,y,z] == extent of box from the center (i.e. 1/2 the box dimensions) L1 = max(abs(bcx - viewx) - exx, abs(bcy - viewy) - exy, abs(bcz - viewz) - exz) enabled = maxerror * Threshold < L1
const string & Terrain::GetCurrentRegionFilepath | ( | ) |
get the current region file path.
int Terrain::GetCurrentRegionIndex | ( | ) |
Get terrain region index, so that we can later call GetCurrentRegionName() and GetCurrentRegionFilepath(), to access region properties.
-1 if nothing is selected.
const string & Terrain::GetCurrentRegionName | ( | ) |
get the currently selected region name.
DetailTexture * Terrain::GetDefaultBaseLayerMask | ( | ) |
get the default base layer mask.
All bits are 0xFF.
float Terrain::GetElevation | ( | float | x, |
float | y | ||
) | const |
Returns the elevation (z-coordinate) in real units of the specified point on the terrain.
if the specified point is inside a hole, we will return (-INFINITY)
float Terrain::GetElevation | ( | int | index | ) | const |
Returns the elevation (z-coordinate) in real units of the specified terrain vertex.
index | The index of the vertex in the Terrain's mesh to get the elevation of. |
float Terrain::GetElevationW | ( | float | x, |
float | y | ||
) | const |
Returns the elevation (z-coordinate) in real units of the specified point on the terrain.
if the specified point is inside a hole, we will return (-INFINITY)
void Terrain::GetLatticePosition | ( | int & | x, |
int & | y | ||
) |
Gets this Terrain object's location within a lattice of Terrains that are being managed by a TerrainLattice object.
x | Filled with the position within a TerrainLattice object's grid of Terrains that this object fills. |
y | Filled with the position within a TerrainLattice object's grid of Terrains that this object fills. |
float Terrain::GetLowestVisibleHeight | ( | ) |
Get the height of the lowest visible terrain point.
This may be used to render the ocean
|
inline |
load detailed (high-res) textures, which is usually a large collection of files
Get the low-res texture coordinate at a specified vertex index
void Terrain::GetMaskFile | ( | string & | sMaskFile, |
const string & | sConfigFile | ||
) |
compute mask file from the terrain config file.
the fold of terrain configure file + folder with terrain config file name+".mask" e.g. if the terrain configure file is "sample/config/sample_0_0.config.txt" then the mask files will be saved to "sample/config/sample_0_0.mask"
void Terrain::GetNormal | ( | float | x, |
float | y, | ||
float & | normalX, | ||
float & | normalY, | ||
float & | normalZ | ||
) | const |
Returns the surface normal of the terrain at the specified point.
x | The x location of the point on the Terrain's surface in local units. |
y | The y location of the point on the Terrain's surface in local units. |
normalX | Gets filled with the surface normal x component |
normalY | Gets filled with the surface normal y component |
normalZ | Gets filled with the surface normal z component |
void Terrain::GetNormalW | ( | float | x, |
float | y, | ||
float & | normalX, | ||
float & | normalY, | ||
float & | normalZ | ||
) | const |
Returns the surface normal of the terrain at the specified point.
x | The x location of the point on the Terrain's surface in world units. |
y | The y location of the point on the Terrain's surface in world units. |
normalX | Gets filled with the surface normal x component |
normalY | Gets filled with the surface normal y component |
normalZ | Gets filled with the surface normal z component |
float Terrain::GetOffsetX | ( | ) | const |
Gets this Terrain object's origin.
This is used by the TerrainLattice class when a grid of Terrains is being managed, but can also be used as a simple way to apply translation to a Terrain.
float Terrain::GetOffsetY | ( | ) | const |
Gets this Terrain object's origin.
This is used by the TerrainLattice class when a grid of Terrains is being managed, but can also be used as a simple way to apply translation to a Terrain.
const string & Terrain::GetOnloadScript | ( | ) |
get the on load script which created all objects on this terrain.
CTerrainRegions * Terrain::GetRegions | ( | ) |
get the regions defined in this terrain.
May return NULL if no regions defined.
DWORD Terrain::GetRegionValue | ( | const string & | sLayerName, |
float | x, | ||
float | y | ||
) |
DWORD Terrain::GetRegionValueW | ( | const string & | sLayerName, |
float | x, | ||
float | y | ||
) |
TextureCell * Terrain::GetTextureCell | ( | int | index | ) |
Gets the TextureCell at the specified position within this Terrain's grid of cells.
index | The index of the TextureCell within this Terrain's grid of TextureCells. |
TextureCell * Terrain::GetTextureCell | ( | int | textureCellX, |
int | textureCellY | ||
) |
Gets the TextureCell at the specified position within this Terrain's grid of cells.
textureCellX | The x position of the TextureCell within this Terrain's grid of TextureCells. |
textureCellY | The y position of the TextureCell within this Terrain's grid of TextureCells. |
void Terrain::GetTextureCoordinates | ( | float | x, |
float | y, | ||
int & | textureCellX, | ||
int & | textureCellY, | ||
float & | texU, | ||
float & | texV | ||
) | const |
Returns the texture coordinates of a given point on the terrain in world coordinates.
x | The x location of the point on the Terrain's surface in world units. |
y | The y location of the point on the Terrain's surface in world units. |
textureCellX | Filled with the X position of the intersected TextureCell object in the Terrain's grid of TextureCells. |
textureCellY | Filled with the Y position of the intersected TextureCell object in the Terrain's grid of TextureCells. |
texU | Filled with the coordinate within the TextureCell where the intersection point is (range from 0.0 to 1.0.) |
texV | Filled with the coordinate within the TextureCell where the intersection point is (range from 0.0 to 1.0.) |
int Terrain::GetTextureIDbyPoint | ( | float | x, |
float | y, | ||
float & | tileX, | ||
float & | tileY | ||
) |
get texture ID by point.
texture ID is the index of low-res textures in range [0, 8*8)
x | in local coordinate |
y | in local coordinate @ return: the texture ID returned. may be negative |
int Terrain::GetVertex | ( | float | x, |
float | y | ||
) | const |
float Terrain::GetVertexElevation | ( | int | index | ) | const |
Returns the elevation (z-coordinate) in real units of the specified vertex on the terrain.
index | The index of the vertex in the Terrain's mesh to get the elevation of. |
int Terrain::GetVertexW | ( | float | x, |
float | y | ||
) | const |
|
virtual |
this class should be implemented if one wants to add new attribute.
This function is always called internally.
Reimplemented from ParaEngine::IAttributeFields.
float Terrain::IntersectRay | ( | float | startX, |
float | startY, | ||
float | startZ, | ||
float | dirX, | ||
float | dirY, | ||
float | dirZ, | ||
float & | intersectX, | ||
float & | intersectY, | ||
float & | intersectZ, | ||
float | fMaxDistance = INFINITY |
||
) |
Casts a ray from the specified point, in the specified direction, and calculates the ray's point of intersection with the terrain.
This method makes use of the terrain's quad tree to optimize the ray-tracing. if the ray intersect with holes in the terrain, a negative value will be returned as well. IMPORTANT: it is assumed that the ray is specified in local coordinate system
startX | The starting point of the ray. |
startY | The starting point of the ray. |
startZ | The starting point of the ray. |
dirX | The direction of the ray - this vector should be normalized. |
dirY | The direction of the ray - this vector should be normalized. |
dirZ | The direction of the ray - this vector should be normalized. |
intersectX | Filled with the intersection point of this ray with the Terrain surface. |
intersectY | Filled with the intersection point of this ray with the Terrain surface. |
intersectZ | Filled with the intersection point of this ray with the Terrain surface. |
if the ray intersect with holes in the terrain, a negative value will be returned.
float Terrain::IntersectRay | ( | float | startX, |
float | startY, | ||
float | startZ, | ||
float | dirX, | ||
float | dirY, | ||
float | dirZ, | ||
float & | intersectX, | ||
float & | intersectY, | ||
float & | intersectZ, | ||
int & | textureCellX, | ||
int & | textureCellY, | ||
float & | texU, | ||
float & | texV, | ||
float | fMaxDistance = INFINITY |
||
) |
An overload of IntersectRay that also provides information about the texture coordinates of the intersected point in addition the position of the point.
if the ray intersect with holes in the terrain, a negative value will be returned as well. IMPORTANT: it is assumed that the ray is specified in local coordinate system
startX | The starting point of the ray. |
startY | The starting point of the ray. |
startZ | The starting point of the ray. |
dirX | The direction of the ray - this vector should be normalized. |
dirY | The direction of the ray - this vector should be normalized. |
dirZ | The direction of the ray - this vector should be normalized. |
intersectX | Filled with the intersection point of this ray with the Terrain surface. |
intersectY | Filled with the intersection point of this ray with the Terrain surface. |
intersectZ | Filled with the intersection point of this ray with the Terrain surface. |
textureCellX | Filled with the X position of the intersected TextureCell object in the Terrain's grid of TextureCells. |
textureCellY | Filled with the Y position of the intersected TextureCell object in the Terrain's grid of TextureCells. |
texU | Filled with the coordinate within the TextureCell where the intersection point is (range from 0.0 to 1.0.) |
texV | Filled with the coordinate within the TextureCell where the intersection point is (range from 0.0 to 1.0.) |
float Terrain::IntersectRayW | ( | float | startX, |
float | startY, | ||
float | startZ, | ||
float | dirX, | ||
float | dirY, | ||
float | dirZ, | ||
float & | intersectX, | ||
float & | intersectY, | ||
float & | intersectZ, | ||
float | fMaxDistance = INFINITY |
||
) |
Casts a ray from the specified point, in the specified direction, and calculates the ray's point of intersection with the terrain.
This method makes use of the terrain's quad tree to optimize the ray-tracing. if the ray intersect with holes in the terrain, a negative value will be returned as well. IMPORTANT: it is assumed that the ray is specified in world coordinate system
startX | The starting point of the ray. |
startY | The starting point of the ray. |
startZ | The starting point of the ray. |
dirX | The direction of the ray - this vector should be normalized. |
dirY | The direction of the ray - this vector should be normalized. |
dirZ | The direction of the ray - this vector should be normalized. |
intersectX | Filled with the intersection point of this ray with the Terrain surface. |
intersectY | Filled with the intersection point of this ray with the Terrain surface. |
intersectZ | Filled with the intersection point of this ray with the Terrain surface. |
|
virtual |
Invoke an (external) editor for a given field.
This is usually for NPL script field
nFieldID | : field ID |
sParameters | : the parameter passed to the editor |
bool Terrain::IsEmpty | ( | ) |
whether the terrain is a fake terrain without vertices.
bool Terrain::IsHole | ( | float | x, |
float | y | ||
) |
Whether the terrain contains a hole at the specified location.
Currently, we allow user to load a low resolution hole maps at the beginning of terrain creation.
x | The x location of the point on the Terrain's surface in local units. |
y | The y location of the point on the Terrain's surface in local units. |
bool Terrain::IsHoleW | ( | float | x, |
float | y | ||
) |
Whether the terrain contains a hole at the specified location.
Currently, we allow user to load a low resolution hole maps at the beginning of terrain creation.
x | The x location of the point on the Terrain's surface in world units. |
y | The y location of the point on the Terrain's surface in world units. |
|
virtual |
whether the terrain geometry, texture has been modified.
If any of them has been modified, this function will return true.
Reimplemented from ParaEngine::IAttributeFields.
bool Terrain::IsModified | ( | DWORD | dwModifiedBits | ) |
return true if any part specified in dwModifiedBits has been modified.
see TERRAIN_MODIFIED_BITS.
dwModifiedBits | this is any combination of TERRAIN_MODIFIED_BITS. |
bool Terrain::LoadFromConfigFile | ( | const char * | sFileName, |
float | fSize = 0 , |
||
const char * | relativePath = NULL |
||
) |
Load from Configuration file.
Modified bits are cleared. Please note that the on_load script is not called. one must manually call OnLoad() to load scene objects in this terrain.
fSize | if fSize is not 0, it will override the size read from the configuration file |
relativePath | if sFileName is not found, it will try appending relativePath before sFileName. relativePath is trimmed to the last slash character. i.e. "terrain/abc.txt" and "terrain/" are the same relative path. |
add terrain holes
add all detail textures used in this terrain tile
get regions layers
void Terrain::LoadMaskFromDisk | ( | bool | bForceReload = false | ) |
load the terrain mask file from disk once again.
This function only works when terrain is not editable. otherwise there is no need to load mask file manually here. This function is called when device is lost.
bForceReload | if true, it will reload mask file from disk. |
read mask data from file:
int Terrain::ModelViewMatrixChanged | ( | ) |
Notifies Demeter that OpenGL's modelview matrix has been modified, allowing Demeter to tessellate the terrain based on the new modelview matrix.
It is IMPERATIVE that his method be called every time the modelview matrix is changed, even if this is in every single rendering cycle of the application. Based on the current viewing parameters, the terrain will be broken down into a visually optimum set of triangles that can be rendered.
int Terrain::NormalizeMask | ( | int | textureCellX, |
int | textureCellY, | ||
int | detailIndex, | ||
bool | bReload = true |
||
) |
normalize the given texture mask layer, so that the alpha of the specified layer is unchanged and the sum of all alpha values of all mask layers at all pixels in the cell is 1.
it is good practice to keep every pixel mask normalized, so that we do not get overly lighted terrain surface.
detailIndex | if this is -1, the base layer is used |
bReload | if true, it will reload all mask layers |
void Terrain::OnLoad | ( | ) |
this function is automatically called after the terrain has been loaded.
it usually does the following things in the given order:
void Terrain::Paint | ( | ParaEngine::TextureEntity * | detailTexture, |
float | brushRadius, | ||
float | brushIntensity, | ||
float | maxIntensity, | ||
bool | erase, | ||
float | x, | ||
float | y | ||
) |
Paints a "splat" of the specified shared texture at the specified position on the terrain in world coordinates.
See the TextureSet class for details on how to get a detailTextureIndex for painting.
detailTexture | The shared index of a Texture object that is part of this Terrain object's TextureSet. |
brushRadius | The width of the brush to paint with in DetailTexture layer pixels. There are typically 256 of these pixels across a TextureCell. |
brushIntensity | The intensity with which to paint, ranging from 0.0 to 1.0. This determines how opaque the painted "splat" will be. |
maxIntensity | The maximum intensity of the painted splat, ranging from 0.0 to 1.0, accounting for mixing with a splat that may already reside on the surface. |
erase | Specifies whether to add the splat to the surface or remove existing splat texels already on the surface (pass false to paint and pass true to erase existing splats) |
x | The x location of the point to paint on the Terrain's surface in world units. |
y | The y location of the point to paint on the Terrain's surface in world units. |
bool Terrain::Pick | ( | int | screenX, |
int | screenY, | ||
float & | pickedX, | ||
float & | pickedY, | ||
float & | pickedZ | ||
) | const |
Quickly find the 3D point on the terrain where a given point on the screen is (for example, for mouse picking.)
This is cheaper and faster than using the ray tracing methods, but far less accurate. The accuracy of this method depends upon the z-buffer depth and the screen resolution.
screenX | The X position of the pixel on the screen that was "clicked" |
screenY | the Y position of the pixel on the screen that was "clicked" - you will often to invert this value since the OpenGL screen Y-axis runs opposite that of most window systems. For example, you may need to pass Settings::GetInstance()->GetScreenHeight() - mouseY instead of just passing mouseY . |
pickedX | Filled with the picked point on Terrain surface. |
pickedY | Filled with the picked point on Terrain surface. |
pickedZ | Filled with the picked point on Terrain surface. |
bool Terrain::Pick | ( | int | screenX, |
int | screenY, | ||
float & | pickedX, | ||
float & | pickedY, | ||
float & | pickedZ, | ||
int & | textureCellX, | ||
int & | textureCellY, | ||
float & | texU, | ||
float & | texV | ||
) | const |
Quickly find the 3D point on the terrain where a given point on the screen is (for example, for mouse picking.)
This is cheaper and faster than using the ray tracing methods, but far less accurate. The accuracy of this method depends upon the z-buffer depth and the screen resolution.
screenX | The X position of the pixel on the screen that was "clicked" |
screenY | the Y position of the pixel on the screen that was "clicked" - you will often to invert this value since the OpenGL screen Y-axis runs opposite that of most window systems. For example, you may need to pass Settings::GetInstance()->GetScreenHeight() - mouseY instead of just passing mouseY . |
pickedX | Filled with the picked point on Terrain surface. |
pickedY | Filled with the picked point on Terrain surface. |
pickedZ | Filled with the picked point on Terrain surface. |
textureCellX | Filled with the X position of the intersected TextureCell object in the Terrain's grid of TextureCells. |
textureCellY | Filled with the Y position of the intersected TextureCell object in the Terrain's grid of TextureCells. |
texU | Filled with the coordinate within the TextureCell where the intersection point is (range from 0.0 to 1.0.) |
texV | Filled with the coordinate within the TextureCell where the intersection point is (range from 0.0 to 1.0.) |
void ParaTerrain::Terrain::Read | ( | char * | szFilename | ) |
Reads a binary "surface" file for fine-grained detail textures.
NOTE: the format of this file will be changed soon.
szFilename | A filename to read from. The media path will be prepended to this file. See Settings::SetMediaPath(). |
void Terrain::RebuildRenderBuffer | ( | ) |
Rebuild the rendering buffer from triangle strips and fans generated from Tessellate() and RepairCracks().
void Terrain::RecalcGeometry | ( | int | index1, |
int | index2 | ||
) |
Recalculates bounding box for the quad spanning from vertex 1 to vertex 2.
index1 | The index of the top-left vertex |
index2 | The index of the bottom-right vertex |
void Terrain::RecalcGeometry | ( | ) |
recalculate the entire terrain.
It is actually fast.
void Terrain::RecalcNormal | ( | float | x, |
float | y | ||
) |
void Terrain::RecalcNormal | ( | int | vertexIndex | ) |
Recalculates the normal vector of the specified vertex.
vertexIndex | The index of the vertex in the Terrain's mesh. |
|
inline |
Increment the reference count by one, indicating that this object has another pointer which is referencing it.
This method is provided for use of Demeter with the Open Scene Graph.
|
static |
|
static |
void Terrain::Render | ( | void | ) |
Render the terrain from Render Buffer.
Applications should always call ModelViewMatrixChanged() at least once prior to calling Render(), so that Demeter will have a chance to tessellate the terrain.
draw nothing if there is nothing to draw
render the terrain by texture groups
for each texture group, we will use multi-texture stage to render blended textures at the same time
render the terrain by texture groups
for each texture group, we will use multi-texture stage to render blended textures at the same time
three groups at a time. ( alpha0 + detail1 ) + ( alpha3 + detail4 ) + ( alpha5 + detail6 )
void Terrain::RepairCracks | ( | ) |
repair cracks during tessellation.
the triangle strips built from Tessellate() will has cracks between neighboring triangles of different size. in these cases, the bigger triangle strips are replaced with triangle fans, so that there will be no cracks. Here "cracks" means that the surface is not a continuous surface.
void Terrain::ResizeTextureMaskWidth | ( | int | nWidth | ) |
resize all texture mask width
export all alpha mask data to disk with the name:
bool Terrain::SaveConfig | ( | const string & | filePath | ) |
save terrain configurations to file.
this function will save file regardless of the modified bits; it will not clear the modified bits either.
filePath | if this is "", the current config file name will be used. |
get regions layers
bool Terrain::SaveDetailTexture | ( | const string & | filePath | ) |
save detail texture to texture mask file.
this function will save file regardless of the modified bits; it will not clear the modified bits either.
filePath | if this is "", the current mask file name will be used. |
export all alpha mask data to disk with the name:
bool Terrain::SaveElevation | ( | const string & | filePath | ) |
save terrain height map to file.
this function will save file regardless of the modified bits; it will not clear the modified bits either.
filePath | if this is "", the current elevation file name will be used. |
bool Terrain::SaveToFile | ( | const char * | filename = NULL | ) |
Save Terrain to file according to the modified bits.
filename | file name of the terrain config file. All related files, such as elevation file and alpha mask files will be saved in the save directory of the terrain config file.If this is NULL, the load config file will be used. and will be overridden. |
fSize | if fSize is not 0, it will override the size of this terrain tile by the value supplied. |
relativePath | if sFileName is not found, it will try appending relativePath before sFileName. relativePath is trimmed to the last slash character. i.e. "terrain/abc.txt" and "terrain/" are the same relative path. |
void Terrain::SetAllElevations | ( | const float * | pElevations, |
int | elevWidth, | ||
int | elevHeight, | ||
float | fTerrainSize, | ||
float | elevationScale = 1.0f |
||
) |
Replaces all of the Terrain's vertices with a new set of vertices.
pElevations | An array of floating point values representing the elevation (z value) of each vertex in the terrain's mesh. The size of this array must be equal to elevWidth * elevHeight |
elevWidth | The number of vertices along the x-axis (width) of the grid of vertices in pElevations. |
elevHeight | The number of vertices along the y-axis (height) of the grid of vertices in pElevations. |
fTerrainSize | size of this terrain of 1024x1024 vertices for the pElevations and elevWidth and elevHeight parameters, and pass a value of 10.0 for the vertexSpacing parameter, then the resulting Terrain will be 10240 x 10240 world units in size. |
elevationScale | A scaling factor that is applied to all of the values in the pElevations array. Most applications will pass a 1.0 for this value since presumably pElevations was built by the application. |
this will repair imprecisions due to the floating calculations
bool Terrain::SetBaseTexture | ( | const string & | filename, |
int | numTextureCellsX = 8 , |
||
int | numTextureCellsY = 8 |
||
) |
Set the base texture to texture cells.
The base texture will be chopped according to the texture cell configuration. e.g. if the texture cell is 8x8, then the base texture is chopped to 64 small textures and set to each texture cell.
bool Terrain::SetCommonTexture | ( | const uint8 * | pImage, |
int | width, | ||
int | height | ||
) |
Uses the specified graphics image to apply a "common" texture to the entire surface of the terrain.
A common texture is repeated across the entire terrain and is blended with the terrain's overall texture (if blending is supported by the user's hardware.) This is used to provide a texture to give the ground some definition when the camera is close to the ground, but is an inferior to alternative to the use of specific DetailTexture instances.
pImage | An array of byte values representing the texture image that will be draped across the entire surface of the Terrain (this is the "overall" texture.) The array must contain 3 bytes per pixel - the red, green, and blue color values of the pixel respectively. It is assumed that the array does not contain any extra padding per image row. Therefore, if your image is 1024x1024 pixels, then this array should be 9,437,184 bytes in size. You can pass NULL for this parameter to build a Terrain with no texture. |
width | The width of the texture image in pixels. |
height | The height of the texture image in pixels. |
void Terrain::SetCommonTexture | ( | const char * | fileName | ) |
Uses the specified Texture to apply a "common" texture to the entire surface of the terrain.
A common texture is repeated across the entire terrain and is blended with the terrain's overall texture (if blending is supported by the user's hardware.) This is used to provide a texture to give the ground some definition when the camera is close to the ground, but is an inferior to alternative to the use of specific DetailTexture instances.
void Terrain::SetCommonTexture | ( | Texture * | pTexture | ) |
A common texture is repeated across the entire terrain and is blended with the terrain's overall texture (if blending is supported by the user's hardware.) This is used to provide a texture to give the ground some definition when the camera is close to the ground, but is an inferior to alternative to the use of specific DetailTexture instances.
pTexture | A Texture object to use as the common texture. |
void Terrain::SetCurrentRegionFilepath | ( | const string & | filename | ) |
set the current region file path.
void Terrain::SetCurrentRegionName | ( | const string & | name | ) |
set the currently selected region name.
The current region Index is changed to the current selected one or -1 if invalid. please note that: this does not create the region layer
void Terrain::SetDetailThreshold | ( | float | threshold | ) |
Sets the "detail threshold", which controls how much Demeter simplifies the terrain.
Higher thresholds will increase performance but make the terrain look worse, while lower thresholds will reduce performance and increase visual quality. Extremely high thresholds can cause significant visual artifacts.
threshold | An error metric, measured in screen pixels. Any terrain blocks smaller than this threshold will be simplified. Currently this is a squared value.i.e. If it is 7 pixels, then the value should be 49. |
void Terrain::SetHole | ( | float | x, |
float | y, | ||
bool | bIsHold | ||
) |
set a new terrain hole at the specified location.
Currently, we will allow user to dynamically dig holes in terrain. After calling this function, the user must manually Call UpdateHoles() to inform that the holes in the terrain has been updated.
x | The x location of the point on the Terrain's surface in world units. |
y | The y location of the point on the Terrain's surface in world units. |
void Terrain::SetHoleLocal | ( | float | x, |
float | y, | ||
bool | bIsHold | ||
) |
set a new terrain hole at the specified local location.
Currently, we will allow user to dynamically dig holes in terrain. After calling this function, the user must manually Call UpdateHoles() to inform that the holes in the terrain has been updated.
x | x component of the hole. it is relative to this terrain tile, not to the global world. |
y | x component of the hole. it is relative to this terrain tile, not to the global world. |
create a concrete hole map.
void Terrain::SetHoleScale | ( | int | nHoleScale | ) |
this value can only be a power of 2, such as 2, 4, 8, etc.
default value is 2 or 4. it denotes how many successive vertex in the height map represent a hole the larger the value is the larger the hole vertex is.
void Terrain::SetLatticePosition | ( | int | x, |
int | y | ||
) |
Sets this Terrain object's location within a lattice of Terrains that are being managed by a TerrainLattice object.
x | The position within a TerrainLattice object's grid of Terrains that this object will fill. |
y | The position within a TerrainLattice object's grid of Terrains that this object will fill. |
void Terrain::SetLowestVisibleHeight | ( | float | fHeight | ) |
Set the height of the lowest visible terrain point.
This may be used to render the ocean
void Terrain::SetMaximumVisibleBlockSize | ( | int | stride | ) |
Sets the maximum size of blocks that can be simplified when the terrain is tessellated.
This setting can be used by applications that allow much of the terrain to be visible from above, such as flight simulators, to prevent oversimplification of terrain in the distance. Setting this value too low will adversely affect performance.
stride | Specifies the number of vertices along one edge of the block (blocks are always square.) |
void Terrain::SetModified | ( | bool | bIsModified, |
DWORD | dwModifiedBits | ||
) |
Turn on/off the specified flag indicating whether the terrain has been modified or not.
bIsModified | true to turn on the bits specified in dwModifiedBits, false otherwise. |
dwModifiedBits | this is any combination of TERRAIN_MODIFIED_BITS. |
|
virtual |
set the terrain modified to true for all parts of the terrain.
Reimplemented from ParaEngine::IAttributeFields.
void Terrain::SetOffset | ( | float | x, |
float | y | ||
) |
Set this Terrain object's origin.
This is used by the TerrainLattice class when a grid of Terrains is being managed, but can also be used as a simple way to apply translation to a Terrain.
bool Terrain::SetTexture | ( | const uint8 * | pTextureImage, |
int | width, | ||
int | height | ||
) |
Applies the specified graphics image as a texture to the terrain.
This is done by breaking the specified image up into smaller textures of 256x256 called TextureCells and mapping these contiguously onto the terrain's surface. Textures are automatically applied by TextureLoaders and by the byte array constructors, so use of this method is entirely optional.
pTextureImage | An array of byte values representing the texture image that will be draped across the entire surface of the Terrain (this is the "overall" texture.) The array must contain 3 bytes per pixel - the red, green, and blue color values of the pixel respectively. It is assumed that the array does not contain any extra padding per image row. Therefore, if your image is 1024x1024 pixels, then this array should be 9,437,184 bytes in size. You can pass NULL for this parameter to build a Terrain with no texture. |
width | The width of the texture image in pixels. |
height | The height of the texture image in pixels. |
void Terrain::SetTextureCell | ( | int | index, |
TextureCell * | pCell | ||
) |
Installs a new TextureCell at the specified position within this Terrain's grid of TextureCells.
index | The index of the TextureCell within this Terrain's grid of TextureCells. |
pCell | The new TextureCell to install, presumably one that was created by your application. |
void Terrain::SetTextureFactory | ( | TextureFactory * | pFactory | ) |
Installs an application-provided TextureFactory, disabling the default one supplied by Demeter.
This allows applications to manage textures for themselves.
pFactory | A pointer to your TextureFactory object that will serve textures to this instance of Terrain. |
void Terrain::SetTextureSet | ( | TextureSet * | pTextureSet | ) |
Sets the TextureSet that represents this Terrain object's pool of shared Textures.
replacing the default one that was created automatically.
pTextureSet | The new TextureSet, presumably one that was created by your application. |
void Terrain::SetVertexElevation | ( | int | index, |
float | newElevation, | ||
bool | recalculate_geometry = true |
||
) |
Sets the elevation (z-coordinate) in real units of the specified vertex on the terrain.
index | The index of the vertex in the Terrain's mesh to set the elevation of. |
newElevation | The new z-value (elevation) of the vertex to be set. |
recalculate_geometry | Specified whether or not terrain block bounding boxes should be updated as a result of this vertex changed. You would pass false here only when you are sequentially setting many vertices, in which case you would pass true only on the last vertex changed (this prevents redundant recalculation for each vertex changed.) |
void Terrain::SetVertexElevation | ( | float | x, |
float | y, | ||
float | newElevation | ||
) |
Sets the elevation (z-coordinate) in real units of the nearest vertex to the specified point.
int Terrain::Tessellate | ( | ) |
Breaks the Terrain down into triangles strips.
Based on the current viewing parameters, this method breaks the terrain down into a visually optimum set of triangles that can be rendered. Normally, an application will never call this method directly, but will instead call the method ModelViewMatrixChanged() to allow Demeter to take care of this automatically.
set the render offset for this terrain.
void Terrain::TessellateGeoMipmap | ( | ) |
set the render offset for this terrain.
|
inline |
Decrement the reference count by one, indicating that a pointer to this object is referencing it.
If the reference count goes to zero, it is assumed that this object is no longer referenced and is automatically deleted. This method is provided for use of Demeter with the Open Scene Graph.
void ParaTerrain::Terrain::Write | ( | char * | szFilename | ) |
Writes a binary "surface" file for fine-grained detail textures.
szFilename | A filename to write to. The media path will be prepended to this file. See Settings::SetMediaPath(). |
void ParaTerrain::Terrain::WriteRawElevations | ( | const char * | szFilename | ) |
Write all of this Terrain's vertices to a raw binary file.
szFilename | A filename to write to. The media path will be prepended to this file. See Settings::SetMediaPath(). |
void ParaTerrain::Terrain::WriteRawTextures | ( | const char * | szTerrainName | ) |
Write all of this Terrain's textures to raw binary files.
szTerrainName | A filename to write to. The media path will be prepended to this file. See Settings::SetMediaPath(). |
|
static |
array of high resolution texture coordinates.
array size is m_WidthVertices*m_WidthVertices
|
static |
array of low resolution texture coordinates.
array size is m_WidthVertices*m_WidthVertices