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

pge::Terrain Class Reference

#include <Terrain.h>

Inheritance diagram for pge::Terrain:

Inheritance graph
[legend]
Collaboration diagram for pge::Terrain:

Collaboration graph
[legend]

Public Member Functions

 Terrain (const std::string &heightmapFile, const std::string &textureFile, Vector3f startCorner, float mapScale, int vertexNumX, int vertexNumZ, float terrainWidth, float terrainDepth)
 Constructor.

virtual ~Terrain (void)
 Destructor.

void createTerrain (Vector3f *vertices, int vertexNumX, int vertexNumZ)

Private Attributes

Texturem_texture

Constructor & Destructor Documentation

pge::Terrain::Terrain const std::string &  heightmapFile,
const std::string &  textureFile,
Vector3f  startCorner,
float  mapScale,
int  vertexNumX,
int  vertexNumZ,
float  terrainWidth,
float  terrainDepth
 

Constructor.

Definition at line 105 of file Terrain.cpp.

References pge::MeshModel::buildBoundingBox(), createTerrain(), pge::HeightmapLoader::generateTerrain(), and m_texture.

00107                                                                 {
00108 
00109                 HeightmapLoader *loader = new HeightmapLoader(heightmapFile);
00110 
00111                 // Load texture for terrain.
00112                 m_texture = TextureDatabase::getInstance()->addTexture(textureFile);
00113 
00114                 // Create the terrain.
00115                 createTerrain(loader->generateTerrain(startCorner, mapScale, vertexNumX, vertexNumZ,
00116                         terrainWidth, terrainDepth), vertexNumX, vertexNumZ);
00117 
00118                 // Build the bounding box here to enabled height queries.
00119                 buildBoundingBox();
00120         }

Here is the call graph for this function:

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

Destructor.

Definition at line 128 of file Terrain.cpp.

00128                               {
00129         }


Member Function Documentation

void pge::Terrain::createTerrain Vector3f vertices,
int  vertexNumX,
int  vertexNumZ
 

Definition at line 137 of file Terrain.cpp.

References pge::MeshModel::addMesh(), pge::Mesh::addTriangle(), pge::Triangle::m_plane, pge::Triangle::m_texCoords, m_texture, pge::Triangle::m_vertices, and pge::SingleTexturedMesh::setTexture().

Referenced by Terrain().

00137                                                                                       {
00138                 int x;
00139                 int z;
00140                 int numTriangles;
00141                 float textureRepeatU = 20.0f;
00142                 float textureRepeatV = 20.0f;
00143                 float texPerCentU = textureRepeatU / (float) vertexNumX;
00144                 float texPerCentV = textureRepeatV / (float) vertexNumX;
00145                 SingleTexturedMesh *mesh = new SingleTexturedMesh();
00146 
00147 
00148                 mesh->setTexture(m_texture);
00149 
00150                 numTriangles = 0;
00151                 for(z = 0; z < vertexNumZ - 1; z++) {
00152                         for(x = 0; x < vertexNumX - 1; x++) {
00153 
00154                                 Vector3f v0 = vertices[(z * vertexNumX) + x];
00155                                 Vector3f v1 = vertices[((z + 1) * vertexNumX) + x];
00156                                 Vector3f v2 = vertices[(z * vertexNumX) + (x + 1)];
00157                                 Vector3f v3 = vertices[((z + 1) * vertexNumX) + (x + 1)];
00158 
00159                                 Triangle triangle0;
00160                                 Triangle triangle1;
00161 
00162                                 triangle0.m_vertices[0] = v0;
00163                                 triangle0.m_vertices[1] = v1;
00164                                 triangle0.m_vertices[2] = v2;
00165                                 triangle0.m_texCoords[0] = Vector2f(x * texPerCentU, z * texPerCentV);
00166                                 triangle0.m_texCoords[1] = Vector2f(x * texPerCentU, (z + 1) * texPerCentV);
00167                                 triangle0.m_texCoords[2] = Vector2f((x + 1) * texPerCentU, z * texPerCentV);
00168 
00169                                 triangle1.m_vertices[0] = v2;
00170                                 triangle1.m_vertices[1] = v1;
00171                                 triangle1.m_vertices[2] = v3;
00172                                 triangle1.m_texCoords[0] = Vector2f((x + 1) * texPerCentU, z * texPerCentV);
00173                                 triangle1.m_texCoords[1] = Vector2f(x * texPerCentU, (z + 1) * texPerCentV);
00174                                 triangle1.m_texCoords[2] = Vector2f((x + 1) * texPerCentU, (z + 1) * texPerCentV);
00175 
00176                                 // Planes.
00177                                 triangle0.m_plane = new Plane(v0, v1, v2);
00178                                 triangle1.m_plane = new Plane(v2, v1, v3);
00179 
00180                                 mesh->addTriangle(triangle0);
00181                                 mesh->addTriangle(triangle1);
00182                                 numTriangles += 2;
00183 
00184                                 if(numTriangles >= 1000000) {
00185                                         addMesh(mesh);
00186                                         mesh = NULL;
00187                                         mesh = new SingleTexturedMesh();
00188                                         mesh->setTexture(m_texture);
00189                                         numTriangles = 0;
00190                                 }
00191                         }
00192                 }
00193 
00194                 if(numTriangles > 0) {
00195                         addMesh(mesh);
00196                 }
00197         }

Here is the call graph for this function:


Field Documentation

Texture* pge::Terrain::m_texture [private]
 

Definition at line 103 of file Terrain.h.

Referenced by createTerrain(), and Terrain().


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