Changeset 9421 in orxonox.OLD for branches/terrain/src/world_entities
- Timestamp:
- Jul 24, 2006, 1:46:23 PM (18 years ago)
- Location:
- branches/terrain/src/world_entities
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/terrain/src/world_entities/terrain_entity.cc
r9414 r9421 32 32 #include "state.h" 33 33 34 using namespace std; 35 36 CREATE_FACTORY( TerrainEntity, CL_TERRAIN ); 34 CREATE_FACTORY( TerrainEntity, CL_TERRAIN_ENTITY ); 37 35 38 36 /** … … 41 39 TerrainEntity::TerrainEntity (const TiXmlElement* root) 42 40 { 43 44 45 46 47 48 41 this->init(); 42 43 44 if( root != NULL) 45 this->loadParams(root); 46 terrain->build( ); 49 47 } 50 48 … … 60 58 this->init(); 61 59 62 if (fileName.rfind(".obj" ) != -1 || fileName.rfind(".OBJ") != -1)60 if (fileName.rfind(".obj" ) != std::string::npos || fileName.rfind(".OBJ") != std::string::npos ) 63 61 { 64 62 this->loadModel(fileName); … … 100 98 void TerrainEntity::init() 101 99 { 102 this->setClassID( CL_TERRAIN , "TerrainEntity");100 this->setClassID( CL_TERRAIN_ENTITY, "TerrainEntity"); 103 101 this->toList(OM_ENVIRON); 104 102 this->toReflectionList(); … … 115 113 void TerrainEntity::loadParams(const TiXmlElement* root) 116 114 { 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, "light_map", this, TerrainEntity, loadLightmap ) 123 .describe("The name of the lightmap."); 124 125 LoadParam( root, "elevation_map", this, TerrainEntity, loadElevationmap ) 126 .describe( "The name of the elevation map. Must be an 8bit image" ); 127 ResourceManager *manager = ResourceManager::getInstance(); 128 TiXmlElement * layer = (TiXmlElement*)root->FirstChild( "material_layer" ); 129 while ( layer ) { 130 LayerInfo *info = new LayerInfo(); 131 TiXmlElement *detail = (TiXmlElement*)layer->FirstChild( "detail_map" ); 132 if ( detail ) { 133 string detailmap( detail->Attribute( "file" ) ); 134 info->detail = (Texture*)manager->load( detailmap, 135 IMAGE, RP_GAME, (int)GL_TEXTURE_2D ); 136 if ( !info->detail ) { 137 PRINTF(0)( "%s not found\n", detailmap.c_str() ); 138 } 139 else 140 PRINTF(0)( "loaded %s\n", detailmap.c_str() ); 141 TiXmlElement *repeat = (TiXmlElement*)detail->FirstChild( "repeat" ); 142 if ( repeat ) { 143 repeat->QueryFloatAttribute( "x", &info->repeatX ); 144 repeat->QueryFloatAttribute( "z", &info->repeatZ ); 145 } 146 } 147 else { 148 PRINTF(0)( "Please specify a detail-map" ); 149 } 150 TiXmlElement *alpha = (TiXmlElement*)layer->FirstChild( "alpha" ); 151 if ( alpha ) { 152 if ( !alpha->Attribute( "full" ) ) { 153 string alphamap( alpha->Attribute( "file" ) ); 154 info->alpha = (Texture*)manager->load( alphamap, 155 IMAGE, RP_GAME, (int)GL_TEXTURE_2D ); 156 if ( !info->alpha ) 157 PRINTF(0)( "%s not found\n", alphamap.c_str() ); 158 else 159 PRINTF(0)( "loaded %s\n", alphamap.c_str() ); 160 } 161 } 162 terrain->addMaterialLayer( info ); 163 layer = (TiXmlElement*)layer->NextSibling( "material_layer" ); 164 } 115 WorldEntity::loadParams( root ); 116 117 LoadParam(root, "scale", this, TerrainEntity, setScale) 118 .describe("The scale in x,y,z direction"); 119 120 LoadParam( root, "light_map", this, TerrainEntity, loadLightmap ) 121 .describe("The name of the lightmap."); 122 123 LoadParam( root, "elevation_map", this, TerrainEntity, loadElevationmap ) 124 .describe( "The name of the elevation map. Must be an 8bit image" ); 125 ResourceManager *manager = ResourceManager::getInstance(); 126 TiXmlElement * layer = (TiXmlElement*)root->FirstChild( "material_layer" ); 127 while ( layer ) 128 { 129 LayerInfo *info = new LayerInfo(); 130 TiXmlElement *detail = (TiXmlElement*)layer->FirstChild( "detail_map" ); 131 if ( detail ) 132 { 133 std::string detailmap( detail->Attribute( "file" ) ); 134 info->detail = (Texture*)manager->load( detailmap, 135 IMAGE, RP_GAME, (int)GL_TEXTURE_2D ); 136 if ( !info->detail ) 137 { 138 PRINTF(0)( "%s not found\n", detailmap.c_str() ); 139 } 140 else 141 PRINTF(0)( "loaded %s\n", detailmap.c_str() ); 142 TiXmlElement *repeat = (TiXmlElement*)detail->FirstChild( "repeat" ); 143 if ( repeat ) 144 { 145 repeat->QueryFloatAttribute( "x", &info->repeatX ); 146 repeat->QueryFloatAttribute( "z", &info->repeatZ ); 147 } 148 } 149 else 150 { 151 PRINTF(0)( "Please specify a detail-map" ); 152 } 153 TiXmlElement *alpha = (TiXmlElement*)layer->FirstChild( "alpha" ); 154 if ( alpha ) 155 { 156 if ( !alpha->Attribute( "full" ) ) 157 { 158 std::string alphamap( alpha->Attribute( "file" ) ); 159 info->alpha = (Texture*)manager->load( alphamap, 160 IMAGE, RP_GAME, (int)GL_TEXTURE_2D ); 161 if ( !info->alpha ) 162 PRINTF(0)( "%s not found\n", alphamap.c_str() ); 163 else 164 PRINTF(0)( "loaded %s\n", alphamap.c_str() ); 165 } 166 } 167 terrain->addMaterialLayer( info ); 168 layer = (TiXmlElement*)layer->NextSibling( "material_layer" ); 169 } 165 170 } 166 171 167 172 void TerrainEntity::setScale(float x, float y, float z) 168 173 { 169 174 terrain->setScale( Vector( x, y, z ) ); 170 175 } 171 176 172 177 void TerrainEntity::loadElevationmap( const std::string& _eleFile ) 173 178 { 174 179 terrain->setHeightmap( _eleFile ); 175 180 } 176 181 177 182 void TerrainEntity::loadLightmap( const std::string& _lightFile ) 178 183 { 179 ResourceManager *manager = ResourceManager::getInstance(); 180 Texture *lightmap = (Texture*)manager->load( _lightFile, 181 IMAGE, RP_GAME, (int)GL_TEXTURE_2D ); 182 if ( lightmap ) 183 terrain->setLightmap( lightmap ); 184 else { 185 PRINTF(0)("no lightmap %s\n", _lightFile.c_str() ); 186 187 } 184 ResourceManager *manager = ResourceManager::getInstance(); 185 Texture *lightmap = (Texture*)manager->load( _lightFile, 186 IMAGE, RP_GAME, (int)GL_TEXTURE_2D ); 187 if ( lightmap ) 188 terrain->setLightmap( lightmap ); 189 else 190 { 191 PRINTF(0)("no lightmap %s\n", _lightFile.c_str() ); 192 193 } 188 194 } 189 195 … … 210 216 void TerrainEntity::draw () const 211 217 { 212 glMatrixMode( GL_MODELVIEW ); 213 glPushMatrix(); 214 215 glTranslatef( this->getAbsCoor().x, 216 this->getAbsCoor().y, 217 this->getAbsCoor().z ); 218 219 Vector cam = State::getCameraNode()->getAbsCoor(); 220 221 if ( this->terrain ) { 222 terrain->setCameraPosition( cam ); 223 terrain->draw( ); 224 } 225 glPopMatrix(); 218 glMatrixMode( GL_MODELVIEW ); 219 glPushMatrix(); 220 221 glTranslatef( this->getAbsCoor().x, 222 this->getAbsCoor().y, 223 this->getAbsCoor().z ); 224 225 Vector cam = State::getCameraNode()->getAbsCoor(); 226 227 if ( this->terrain ) 228 { 229 terrain->setCameraPosition( cam ); 230 terrain->draw( ); 231 } 232 glPopMatrix(); 226 233 227 234 … … 231 238 void TerrainEntity::buildDebugTerrainEntity(DebugTerrainEntity debugTerrainEntity) 232 239 { 233 240 terrain->build( ); 234 241 /* 235 242 // if the TerrainEntity is the TerrainEntity of Dave … … 255 262 for (int j = 0; j<sizeZ-1;j+=1) 256 263 //height[i][j] = rand()/20046 + (j-25)*(j-25)/30; 257 #ifdef __WIN32__264 #ifdef __WIN32__ 258 265 height[i][j]=(sin((float)j/3)*rand()*i/182400)*.5; 259 #else266 #else 260 267 height[i][j]=(sin((float)j/3)*rand()*(long)i/6282450500.0)*.5; 261 #endif268 #endif 262 269 263 270 //Die Huegel ein wenig glaetten … … 369 376 glEndList(); 370 377 } 371 378 */ 372 379 if (debugTerrainEntity == TERRAINENTITY_BENSCH) 373 380 { … … 405 412 void TerrainEntity::getAltitude( Vector& _position, Vector& _normal ) 406 413 { 407 Vector altitude( _position.x-getAbsCoor().x, 0.0f, _position.z-getAbsCoor().z ), 408 409 if ( terrain ) 410 411 412 413 _normal.z = normal.z; _normal.y = normal.y; _normal.z = normal.z; 414 Vector altitude( _position.x-getAbsCoor().x, 0.0f, _position.z-getAbsCoor().z ), 415 normal( 0.0f, 0.0f, 0.0f ); 416 if ( terrain ) 417 terrain->getAltitude( altitude, normal ); 418 419 _position.y = altitude.y+getAbsCoor().y; 420 _normal.z = normal.z; _normal.y = normal.y; _normal.z = normal.z; 414 421 } 415 422 416 423 float TerrainEntity::getHeight( float x, float z ) 417 424 { 418 Vector altitude( x-getAbsCoor().x, 0.0f, z-getAbsCoor().z ), 419 420 421 422 425 Vector altitude( x-getAbsCoor().x, 0.0f, z-getAbsCoor().z ), 426 normal( 0.0f, 0.0f, 0.0f ); 427 if ( terrain ) 428 terrain->getAltitude( altitude, normal ); 429 423 430 return altitude.y+getAbsCoor().y; 424 431 } -
branches/terrain/src/world_entities/terrain_entity.h
r9414 r9421 27 27 { 28 28 29 30 31 32 33 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 41 42 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 44 void buildDebugTerrainEntity(DebugTerrainEntity debugTerrainEntity); 45 45 46 47 48 49 50 51 52 53 54 55 56 46 float getHeight(float x, float y); 47 void getAltitude( Vector& _position, Vector& _normal ); 48 virtual void draw() const; 49 virtual void tick( float _dt ); 50 public: 51 52 private: 53 Model* vegetation; 54 int objectList; 55 Terrain* terrain; 56 Vector TerrainEntityScale; 57 57 }; 58 58
Note: See TracChangeset
for help on using the changeset viewer.