C3DLandscape::Load

Top  Previous  Next

Syntax:

 

Load(C3DScreen pScreen, string  heightMapFile, string  lightMapFile, string  coverageFile, string  tile1File, string  tile2File, string  tile3File, float  blockSizeX, float  blockSizeZ, float  maxBlockHeight, float  textureScaleX, float  textureScaleZ, int  useGrayscaleLightMap), int

 

Purpose:

Creates a landscape object.

 

Parameters:

pScreen - Screen object.

heightMapFile - Image file containing the height map for the landscape.

lightMapFile - Image file containing the light map for the landscape.

coverageFile - Image file containing the coverage file for the landscape.

tile1File - The first blended texture.

tile2File - The second  blended texture.

tile3File - The third blended texture.

blockSizeX - The size of each block of the landscape along x axis.

blockSizeZ - The size of each block of the landscape along z axis.

maxBlockHeight - The height that 255 in the height map file corresponds to.

textureScaleX - The scale of texture along the width of each block.

textureScaleZ - The scale of texture along the height of each block.

useGrayscaleLightMap - Flag that specifies whether the light map is grayscale or color.

 

Returned value(s):
None

 
Application:

'Setup the landscape properties
/* Size of each block of land along x and z axis */
blockSizeX = 2.0f
blockSizeZ = 2.0f
/* Tell the program what value 255 of height map color corresponds to  */
maximumLandHeight = 50.0f
/* Texture scaling along x axis, fraction along the width of the texture per block of land */
landTextureScaleX = .2f
/* Texture scaling along z axis, fraction along the height of the texture per block of land */
landTextureScaleZ = .2f
/* Whether light map is gray scale or color, in this case, it's gray scale light map */
grayScaleLightMap = true
'load the landscape.
mediaPath = GetStartPath() + "media\\"
m.Load(s,mediaPath + "map.bmp",mediaPath + "lightmap.tga",mediaPath + "coverage.bmp",_
       mediaPath + "tile1.tga",mediaPath + "tile2.tga",mediaPath + "tile3.tga",_
       blockSizeX, blockSizeZ, maximumLandHeight, landTextureScaleX, landTextureScaleZ, grayScaleLightMap)
m.Position(-256,25,512)
m.EnableLighting(false)
m.InitCollision(false)

 
Class Hierarchy

C3DObject

-------C3DMesh

--------------C3DLandscape
 
Additional Info:

The height of each vertex in the landscape is calculated using the red component of each pixel of the height map file. maxBlockHeight is the height in 3D units that the value 255 corresponds to. The range of elevations will be -maxBlockHeight < 0 < maxBlockHeight with 0 corresponding to a red pixel value of 127 in the height map image file.

 

The light map file determines the brightness of each vertex of the landscape.  The light map file must have the same dimensions as the height map as each pixel in the light map determines the final brightness of the corresponding pixel in the height map. If useGrayScaleLightMap is TRUE then only the red component of the light map is actually used resulting in an adjusted light range of 0 for totally black to 255 for full lighting of the vertex.  If useGrayScaleLightMap is FALSE then the color and intensity of the light map pixel is used to blend the vertex creating the effect of using a colored light source.

 

The coverage image file must be the same size as the height map.  Each pixel value in the coverage file determines the amount of the three textures should be used to render each corner of the landscape.  Red determines the blending of the tile1 texture, green determines the bending of the tile2 texture and blue determines the bending of the tile3 texture. The final pixel color before being modulated by the light map is calculated using the formula (r / 255)*t1 + (g / 255)g*t2 + (b / 255)*t2 where r, g, b are the red, green, blue components of the coverage file pixel. t1, t2, t3 are the color of the three textures tile1, tile2, and tile3 respectively.

 

The dimensions of the height map file determine the number of triangles generated in the final mesh.  There will be a total of width * (height-1) * 2 triangles generated.  A height map image of 256*256 will result in a mesh of 130560 triangles for example.  Internally a quadtree is used for rendering the landscape to only draw the parts of the mesh that are in the view of the camera.