Main Page | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals

pge::HeightmapLoader Class Reference

#include <Terrain.h>

Collaboration diagram for pge::HeightmapLoader:

Collaboration graph
[legend]

Public Member Functions

 HeightmapLoader (const std::string &file)
 Constructor.

virtual ~HeightmapLoader (void)
 Destructor.

Vector3fgenerateTerrain (Vector3f startCorner, float mapScale, int vertexNumX, int vertexNumZ, float terrainWidth, float terrainDepth)

Private Member Functions

bool loadHeightmap (const std::string &file)

Private Attributes

Imagem_heightmap

Constructor & Destructor Documentation

pge::HeightmapLoader::HeightmapLoader const std::string &  file  ) 
 

Constructor.

Definition at line 22 of file Terrain.cpp.

References loadHeightmap().

00022                                                               {
00023                 loadHeightmap(file);
00024         }

Here is the call graph for this function:

pge::HeightmapLoader::~HeightmapLoader void   )  [virtual]
 

Destructor.

Definition at line 32 of file Terrain.cpp.

00032                                               {
00033         }


Member Function Documentation

Vector3f * pge::HeightmapLoader::generateTerrain Vector3f  startCorner,
float  mapScale,
int  vertexNumX,
int  vertexNumZ,
float  terrainWidth,
float  terrainDepth
 

Definition at line 57 of file Terrain.cpp.

References pge::Image::getHeight(), pge::Image::getImage(), pge::Image::getWidth(), m_heightmap, and pge::Vector3f::m_v.

Referenced by pge::Terrain::Terrain().

00058                                                                                         {
00059 
00060                 int x;
00061                 int z;
00062                 float spaceX;
00063                 float spaceZ;
00064                 float dataY;
00065                 float y;
00066                 int mX;
00067                 int mZ;
00068                 Vector3f *vertices = new Vector3f[vertexNumX * vertexNumZ];
00069                 unsigned char *buffer;
00070                 int heightmapWidth = m_heightmap->getWidth();
00071                 int heightmapHeight = m_heightmap->getHeight();
00072                 int index;
00073 
00074 
00075                 spaceX = terrainWidth / vertexNumX;
00076                 spaceZ = terrainDepth / vertexNumZ;
00077 
00078                 buffer = m_heightmap->getImage();
00079 
00080                 index = 0;
00081 
00082                 for (z = 0; z < vertexNumZ; z++) {
00083                         for (x = 0; x < vertexNumX; x++) {
00084 
00085                                 mX = (int)mathutils::mapValueToInterval(0.0f, (float)vertexNumX, 0.0f, (float)heightmapWidth, (float)x);
00086                                 mZ = (int)mathutils::mapValueToInterval(0.0f, (float)vertexNumZ, 0.0f, (float)heightmapHeight, (float)z);
00087                 
00088                                 dataY = (float)buffer[((mZ * heightmapHeight) + mX) * 4];
00089 
00090                                 y = startCorner.m_v[1] + dataY * mapScale;
00091 
00092                                 vertices[index] = Vector3f(startCorner.m_v[0] + (x * spaceX), y, startCorner.m_v[2] + (z * spaceZ));
00093                                 index++;
00094                         }
00095                 }
00096                 return vertices;
00097         }

Here is the call graph for this function:

bool pge::HeightmapLoader::loadHeightmap const std::string &  file  )  [private]
 

Definition at line 41 of file Terrain.cpp.

References pge::Image::getType(), pge::Image::isLoaded(), and m_heightmap.

Referenced by HeightmapLoader().

00041                                                                  {
00042                 m_heightmap = new Image(file);
00043 
00044                 if(m_heightmap->getType() == Image::RGBA) {
00045                         printf("INFO: [%s] Heightmap type: RGBA\n", __FILE__);
00046                 }
00047 
00048                 return m_heightmap->isLoaded();
00049         }

Here is the call graph for this function:


Field Documentation

Image* pge::HeightmapLoader::m_heightmap [private]
 

Definition at line 62 of file Terrain.h.

Referenced by generateTerrain(), and loadHeightmap().


The documentation for this class was generated from the following files:
Generated on Mon Oct 16 12:09:11 2006 for Phobosengine by doxygen 1.3.4