#include <Terrain.h>
Collaboration diagram for pge::HeightmapLoader:
Public Member Functions | |
HeightmapLoader (const std::string &file) | |
Constructor. | |
virtual | ~HeightmapLoader (void) |
Destructor. | |
Vector3f * | generateTerrain (Vector3f startCorner, float mapScale, int vertexNumX, int vertexNumZ, float terrainWidth, float terrainDepth) |
Private Member Functions | |
bool | loadHeightmap (const std::string &file) |
Private Attributes | |
Image * | m_heightmap |
|
Constructor.
Definition at line 22 of file Terrain.cpp. References loadHeightmap().
00022 { 00023 loadHeightmap(file); 00024 } |
Here is the call graph for this function:
|
Destructor.
Definition at line 32 of file Terrain.cpp.
00032 { 00033 } |
|
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:
|
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:
|
Definition at line 62 of file Terrain.h. Referenced by generateTerrain(), and loadHeightmap(). |