Chapter 5 Scene Management terrain of Pro Ogre 3D Programming

Source: Internet
Author: User

Terrain in Ogre

Use terrain. cfg
Worldtexturew.terrain_texture.jpg // terrain texture
Detailtexturew.terrain_detail.jpg // detailed texture
DetailTile = 3 // specifies the number of tiles in a small terrain block.
PageSource = Heightmap // height chart data source
Heightmap.image%terrain.png // height chart name, 2 ^ n + 1
PageSize = 513 // height chart size
TileSize = 65 // small terrain block size
MaxPixelError = 3 // The error is sufficient when the level details are used.
PageWorldX = 1500 // The range of terrain in the world x direction
PageWorldZ = 1500 // z direction
MaxHeight = 100 // The highest ing height of the world's terrain
MaxMipMapLevel = 5 // upper limit of level details
# VertexNormals = yes // calculate the vertex normal in the buffer, Which is enabled when the computer light or GPU program is used
# VertexColors = yes // set the vertex color in the buffer. If a GPU program needs to be enabled
# UseTriStrips = yes // we recommend that you disable the current hardware.
VertexProgramMorph = yes // use a vertex program to perform the level of granularity fusion.
LODMorphStart = 0.2 // the start point of LODMorphStart Fusion: the ratio of distance between high and low levels of dsls.

The following parameters are used to provide your own coloring program. This will provide your own defined material.
The settings of WorldTexture and DetailTexture are no longer used and redundant.

MorphLODFactorParamName = morphFactor
// If VertexProgramMorph is set to yes, the custom material contains an advanced vertex program. It specifies a vertex
// The parameter name of the program. This parameter is used to combine the dashboard. The parameter value ranges from 0 to 1, indicating that the value is not adjusted, and 1 indicates that the parameter value is completely adjusted to the next level.
MorphLODFactorParamIndex // used when materail contains a low-level vertex program, meaning the same as above
CustomMaterialName // The specified materail name

The preceding configuration file defines the Terrain Based on the height chart. These parameter definitions can be summarized into two categories: Ogre uses the first type to generate a terrain from a height chart
Mesh and material. The second type is the custom material and GPU vertex program, which can replace the coloring program automatically generated by ogre.
Note:
TerrainScenceManager divides a height chart into pages. Each page consists of several tiles, and they are just convenient names,
They define a set of vertex sets that constitute a square in the generated mesh.
The texture defined by WorldTexture does not have to be as big as the target terrain.
PageWorldX and PageWorldZ can scale the world's terrain.
MaxHeight scales the terrain in the Y direction.
DetailTexture only uses one texture. For example, you should use custom materail for multi-level texture.

Load terrain from a program
SetWorldGeometry () is overloaded. One is used to load the configuration file, and the other is used in the program.
To achieve the function of manual loading. Here, SceneData is converted to std: map by typedef, which stores
See those value pairs. Suppose we have read what we want from a binary file to SceneData. We want to do
Is to convert the read content to the type required by setWorldGeometry. Let's take a look at the function prototype first:
Ogre: SceneManager: setWorldGeometry (DataStreamPtr & stream,
Const String & typeName = StringUtil: BLANK
)
DataStreamPtr is a smart pointer, so it is safe to return from local variables, and the program is quite intuitive.

Ogre: DataStreamPtr Process_Loader: getSceneDataStream (SceneData & data ){
// Create what looks like a config file for the edification of Ogre
Std: string mem;
SceneData: iterator it;
For (it = data. begin (); it! = Data. end (); it ++ ){
Mem + = it-> first;
Mem + = "= ";
Mem + = it-> second;
Mem + = "\ n ";
}
Void * pMem = (void *) new unsigned char [mem. length () + 1];
Memset (pMem, 0, mem. length () + 1 );
Memcpy (pMem, mem. c_str (), mem. length () + 1 );
// Stuff this into a MemoryDataStream
Ogre: DataStreamPtr pStr (new Ogre: MemoryDataStream (pMem, mem. length () + 1 ));
Return pStr;
}
// And then elsewhere in the world loader:
Ogre: DataStreamPtr pStr = getSceneDataStream (terrainDef );
M_sceneMgr-> setWorldGeometry (pStr );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.