Changeset 8328 in orxonox.OLD for branches/terrain/src/world_entities
- Timestamp:
- Jun 12, 2006, 5:17:14 PM (19 years ago)
- Location:
- branches/terrain/src/world_entities
- Files:
-
- 1 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/terrain/src/world_entities/WorldEntities.am
r8271 r8328 8 8 world_entities/skysphere.cc \ 9 9 world_entities/skybox.cc \ 10 world_entities/terrain .cc \10 world_entities/terrain_entity.cc \ 11 11 world_entities/satellite.cc \ 12 12 world_entities/movie_entity.cc \ … … 63 63 skysphere.h \ 64 64 skybox.h \ 65 terrain .h \65 terrain_entity.h \ 66 66 satellite.h \ 67 67 movie_entity.h \ -
branches/terrain/src/world_entities/terrain_entity.cc
r8321 r8328 16 16 17 17 18 #include "terrain .h"19 18 #include "terrain_entity.h" 19 #include "terrain/terrain.h" 20 20 #include "util/loading/load_param.h" 21 21 #include "util/loading/factory.h" … … 26 26 #include "network_game_manager.h" 27 27 28 #include "height_map.h"29 28 #include "material.h" 30 29 … … 35 34 using namespace std; 36 35 37 CREATE_FACTORY( Terrain, CL_TERRAIN);36 CREATE_FACTORY( TerrainEntity, CL_TERRAIN ); 38 37 39 38 /** 40 39 * standard constructor 41 40 */ 42 Terrain::Terrain (const TiXmlElement* root) 43 { 44 this->init(); 45 46 47 if( root != NULL) 48 this->loadParams(root); 49 50 // if (this->model != NULL) 51 //this->ssp = new SpatialSeparation((Model*)this->model, 10.0f); 41 TerrainEntity::TerrainEntity (const TiXmlElement* root) 42 { 43 this->init(); 44 45 46 if( root != NULL) 47 this->loadParams(root); 48 terrain->build( ); 52 49 } 53 50 54 51 55 52 /** 56 * Constructor for loading a Terrain out of a file53 * Constructor for loading a TerrainEntity out of a file 57 54 * @param fileName The file to load data from. 58 55 59 56 this either loads out of an OBJ-file, or loads a heightmap if no .obj-extension is found. 60 57 */ 61 Terrain ::Terrain(const std::string& fileName)58 TerrainEntity::TerrainEntity(const std::string& fileName ) 62 59 { 63 60 this->init(); … … 76 73 * a Constructor for the Debug-Worlds 77 74 */ 78 Terrain ::Terrain(DebugTerrain debugTerrain)75 TerrainEntity::TerrainEntity(DebugTerrainEntity debugTerrainEntity) 79 76 { 80 77 this->init(); 81 this->buildDebugTerrain (debugTerrain);78 this->buildDebugTerrainEntity(debugTerrainEntity); 82 79 } 83 80 … … 86 83 87 84 */ 88 Terrain ::~Terrain()85 TerrainEntity::~TerrainEntity () 89 86 { 90 87 if (objectList) 91 88 glDeleteLists(this->objectList, 1); 92 if( this->ssp) 93 delete ssp; 89 94 90 if (this->vegetation) 95 91 { 96 ResourceManager::getInstance()->unload( this->vegetation);97 } 98 99 if( this->heightMap)100 delete heightMap;101 } 102 103 104 void Terrain ::init()105 { 106 this->setClassID( CL_TERRAIN, "Terrain");92 ResourceManager::getInstance()->unload( this->vegetation ); 93 } 94 95 if( this->terrain ) 96 delete terrain; 97 } 98 99 100 void TerrainEntity::init() 101 { 102 this->setClassID( CL_TERRAIN, "TerrainEntity"); 107 103 this->toList(OM_ENVIRON_NOTICK); 108 104 this->toReflectionList(); 109 105 110 106 this->objectList = 0; 111 this->ssp = NULL;112 107 this->vegetation = NULL; 113 108 114 this->heightMap = NULL; 115 116 this->heightMapMaterial = new Material(); 117 } 118 119 120 void Terrain::loadParams(const TiXmlElement* root) 121 { 122 WorldEntity::loadParams(root); 123 124 LoadParam(root, "scale", this, Terrain, setScale) 125 .describe("The scale in x,y,z direction"); 126 127 LoadParam(root, "texture", this, Terrain, loadTexture) 128 .describe("The name of the Texture for this heightMap"); 129 130 LoadParam(root, "vegetation", this, Terrain, loadVegetation) 131 .describe("the fileName of the vegetation, that should be loaded onto this terrain. (must be relative to the data-dir)") ; 132 133 LoadParam(root, "height-map", this, Terrain, loadHeightMap) 134 .describe("The HeightMap, splitted into two strings seperated by ','. 1: HeighMap, 2: ColorMap"); 135 136 } 137 138 void Terrain::setScale(float x, float y, float z) 139 { 140 this->terrainScale = Vector(x, y, z); 141 } 142 143 void Terrain::loadHeightMap(const std::string& heightMapFile, const std::string& colorMap) 144 { 145 if (this->heightMap != NULL) 146 delete this->heightMap; 147 this->heightMap = NULL; 148 149 std::string hmName = ResourceManager::getFullName(heightMapFile); 150 std::string hmColorName = ResourceManager::getFullName(colorMap); 151 152 153 this->heightMap = new HeightMap(hmName, hmColorName); 154 // heightMap->scale(Vector(43.0f,4.7f,43.0f)); 155 heightMap->scale(this->terrainScale); 156 heightMap->setAbsCoor(this->getAbsCoor()); 157 heightMap->load(); 158 } 159 160 161 void Terrain::loadTexture(const std::string& textureName) 162 { 163 PRINTF(4)("Load texture: %s\n", textureName.c_str()); 164 165 heightMapMaterial->setDiffuse(1.0,1.0,1.0); 166 heightMapMaterial->setAmbient(1.0,1.0,1.0 ); 167 heightMapMaterial->setSpecular(1.0,1.0,1.0); 168 heightMapMaterial->setShininess(.5); 169 heightMapMaterial->setTransparency(1.0); 170 171 heightMapMaterial->setDiffuseMap(textureName); 172 // heightMapMaterial->setAmbientMap(textureName); 173 // heightMapMaterial->setSpecularMap(textureName); 174 } 175 176 177 178 void Terrain::loadVegetation(const std::string& vegetationFile) 109 this->terrain = new Terrain(); 110 111 //this->heightMapMaterial = new Material(); 112 } 113 114 115 void TerrainEntity::loadParams(const TiXmlElement* root) 116 { 117 WorldEntity::loadParams(root); 118 119 LoadParam(root, "scale", this, TerrainEntity, setScale) 120 .describe("The scale in x,y,z direction"); 121 122 LoadParam( root, "lightmap", this, TerrainEntity, loadLightmap ) 123 .describe("The name of the lightmap."); 124 125 LoadParam( root, "elevationmap", this, TerrainEntity, loadElevationmap ) 126 .describe( "The name of the elevation map. Must be an 8bit image" ); 127 128 } 129 130 void TerrainEntity::setScale(float x, float y, float z) 131 { 132 terrain->setScale( Triple( x, y, z ) ); 133 } 134 135 void TerrainEntity::loadElevationmap( const std::string& _eleFile ) 136 { 137 terrain->setHeightmap( _eleFile ); 138 } 139 140 void TerrainEntity::loadLightmap( const std::string& _lightFile ) 141 { 142 terrain->setLightmap( _lightFile ); 143 } 144 145 146 147 void TerrainEntity::loadVegetation(const std::string& vegetationFile) 179 148 { 180 149 PRINTF(4)("loadVegetation: %s\n", vegetationFile.c_str()); … … 194 163 195 164 196 void Terrain::draw () const 197 { 198 glPushMatrix(); 165 void TerrainEntity::draw () const 166 { 167 glMatrixMode( GL_MODELVIEW ); 168 glPushMatrix(); 199 169 200 170 /* translate */ 201 glTranslatef (this->getAbsCoor ().x,171 /* glTranslatef (this->getAbsCoor ().x, 202 172 this->getAbsCoor ().y, 203 this->getAbsCoor ().z );173 this->getAbsCoor ().z );*/ 204 174 /* rotate */ 205 175 // Vector tmpRot = this->getAbsDir().getSpacialAxis(); 206 176 //glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); 207 177 208 if (this->objectList)178 /*if (this->objectList) 209 179 glCallList(this->objectList); 210 180 else if (this->getModel()) … … 213 183 if (this->vegetation) 214 184 this->vegetation->draw(); 215 216 if( this->heightMap) 217 { 218 this->heightMapMaterial->select(); 219 220 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 221 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 222 this->heightMap->draw(); 223 } 224 glPopMatrix(); 225 226 185 */ 186 187 Vector cam = State::getCameraNode()->getAbsCoor(); 188 189 if ( this->terrain ) { 190 terrain->setCameraPosition( Triple( cam.x, cam.y, cam.z ) ); 191 terrain->draw( ); 192 } 193 194 glPopMatrix(); 227 195 /* 228 196 glMatrixMode(GL_MODELVIEW); … … 236 204 glBegin(GL_QUADS); // Draw The Cube Using quads 237 205 glColor3f(0.0f,1.0f,0.0f); // Color Blue 238 glVertex3f(camera.x + 63.0f,Terrain ->getHeight(camera.x+63.0f, camera.z-10.0f)+13.0f,camera.z-10.0f); // Top Right Of The Quad (Top)206 glVertex3f(camera.x + 63.0f,TerrainEntity->getHeight(camera.x+63.0f, camera.z-10.0f)+13.0f,camera.z-10.0f); // Top Right Of The Quad (Top) 239 207 glVertex3f(camera.x-63.0f, getHeight(camera.x+63.0f, camera.z-10.0f)+13.0f,camera.z-10.0f); // Top Left Of The Quad (Top) 240 208 glVertex3f(camera.x-63.0f, getHeight(camera.x+63.0f, camera.z+10.0f)+13.0f, camera.z+10.0f); // Bottom Left Of The Quad (Top) … … 244 212 glPopMatrix();*/ 245 213 246 247 /* THIS IS ONLY FOR DEBUGGING INFORMATION */ 248 if (this->ssp != NULL) 249 this->ssp->drawQuadtree(); 250 } 251 252 253 void Terrain::buildDebugTerrain(DebugTerrain debugTerrain) 254 { 255 // if the terrain is the Terrain of Dave 256 if (debugTerrain == TERRAIN_DAVE) 214 } 215 216 217 void TerrainEntity::buildDebugTerrainEntity(DebugTerrainEntity debugTerrainEntity) 218 { 219 terrain->build( ); 220 /* 221 // if the TerrainEntity is the TerrainEntity of Dave 222 if (debugTerrainEntity == TERRAINENTITY_DAVE) 257 223 { 258 224 objectList = glGenLists(1); … … 389 355 glEndList(); 390 356 } 391 392 if (debugTerrain == TERRAIN_BENSCH)357 */ 358 if (debugTerrainEntity == TERRAINENTITY_BENSCH) 393 359 { 394 360 /* … … 424 390 } 425 391 426 float Terrain::getHeight(float x, float y) 427 { 428 if(this->heightMap != NULL) 429 return (this->heightMap->getHeight(x, y)); 430 return 0; 431 } 392 float TerrainEntity::getHeight( float x, float z ) 393 { 394 Triple altitude( x, 0.0f, z ), normal( 0.0f, 0.0f, 0.0f ); 395 if ( terrain ) 396 terrain->getAltitude( altitude, normal ); 397 398 return altitude.y; 399 } -
branches/terrain/src/world_entities/terrain_entity.h
r8321 r8328 1 1 /*! 2 * @file terrain.h 3 * Defines and handles the terrain of the World 2 * @file TerrainEntity.h 3 4 * Defines and handles the TerrainEntity of the World 4 5 5 6 @todo implement it 6 7 7 The terrainshould either be build from a Model a OBJModel or from a HeightMap.8 The TerrainEntity should either be build from a Model a OBJModel or from a HeightMap. 8 9 */ 9 10 10 #ifndef _TERRAIN _H11 #define _TERRAIN _H11 #ifndef _TERRAINENTITY_H 12 #define _TERRAINENTITY_H 12 13 13 14 #include "world_entity.h" … … 15 16 16 17 // FORWARD DECLARATION 17 class SpatialSeparation;18 class HeightMap;19 18 class Material; 19 class Terrain; 20 20 21 21 //! A simple method to call a desired debug world. 22 enum DebugTerrain {TERRAIN_DAVE, TERRAIN_BENSCH};22 enum DebugTerrainEntity {TERRAINENTITY_DAVE, TERRAINENTITY_BENSCH}; 23 23 24 24 25 //! A Class to handle Terrain of orxonox26 class Terrain : public WorldEntity25 //! A Class to handle TerrainEntity of orxonox 26 class TerrainEntity : public WorldEntity 27 27 { 28 28 29 30 Terrain(const TiXmlElement* root = NULL);31 Terrain(const std::string& fileName);32 Terrain(DebugTerrain debugTerrain);33 virtual ~Terrain();29 public: 30 TerrainEntity(const TiXmlElement* root = NULL); 31 TerrainEntity(const std::string& fileName); 32 TerrainEntity(DebugTerrainEntity debugTerrainEntity); 33 virtual ~TerrainEntity(); 34 34 35 36 35 void init(); 36 virtual void loadParams(const TiXmlElement* root); 37 37 38 38 void loadVegetation(const std::string& vegetationFile); 39 39 40 void loadHeightMap(const std::string& heightMapFile, const std::string& colorMap);41 void loadTexture(const std::string& textureName);42 void setScale(float x, float y, float z);40 void loadElevationmap( const std::string& _eleFile ); 41 void loadLightmap(const std::string& _lightFile ); 42 void setScale( float x, float y, float z ); 43 43 44 void buildDebugTerrain(DebugTerrain debugTerrain);44 void buildDebugTerrainEntity(DebugTerrainEntity debugTerrainEntity); 45 45 46 47 46 float getHeight(float x, float y); 47 virtual void draw() const; 48 48 49 public: 50 SpatialSeparation* ssp; 51 52 private: 53 Model* vegetation; 54 int objectList; 55 56 HeightMap* heightMap; 57 Material* heightMapMaterial; 58 Vector terrainScale; 49 public: 50 51 private: 52 Model* vegetation; 53 int objectList; 54 Terrain* terrain; 55 Vector TerrainEntityScale; 59 56 }; 60 57 61 #endif /* _T ERRAIN_H */58 #endif /* _TerrainEntity_H */
Note: See TracChangeset
for help on using the changeset viewer.