Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jul 24, 2006, 1:46:23 PM (18 years ago)
Author:
bensch
Message:

renamings

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/terrain/src/world_entities/terrain_entity.cc

    r9414 r9421  
    3232#include "state.h"
    3333
    34 using namespace std;
    35 
    36 CREATE_FACTORY( TerrainEntity, CL_TERRAIN );
     34CREATE_FACTORY( TerrainEntity, CL_TERRAIN_ENTITY );
    3735
    3836/**
     
    4139TerrainEntity::TerrainEntity (const TiXmlElement* root)
    4240{
    43         this->init();
    44 
    45 
    46         if( root != NULL)
    47                 this->loadParams(root);
    48         terrain->build( );
     41  this->init();
     42
     43
     44  if( root != NULL)
     45    this->loadParams(root);
     46  terrain->build( );
    4947}
    5048
     
    6058  this->init();
    6159
    62   if (fileName.rfind(".obj" ) != -1 || fileName.rfind(".OBJ") != -1 )
     60  if (fileName.rfind(".obj" ) != std::string::npos || fileName.rfind(".OBJ") != std::string::npos )
    6361  {
    6462    this->loadModel(fileName);
     
    10098void TerrainEntity::init()
    10199{
    102   this->setClassID( CL_TERRAIN, "TerrainEntity");
     100  this->setClassID( CL_TERRAIN_ENTITY, "TerrainEntity");
    103101  this->toList(OM_ENVIRON);
    104102  this->toReflectionList();
     
    115113void TerrainEntity::loadParams(const TiXmlElement* root)
    116114{
    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  }
    165170}
    166171
    167172void TerrainEntity::setScale(float x, float y, float z)
    168173{
    169         terrain->setScale( Vector( x, y, z ) );
     174  terrain->setScale( Vector( x, y, z ) );
    170175}
    171176
    172177void TerrainEntity::loadElevationmap( const std::string& _eleFile )
    173178{
    174         terrain->setHeightmap( _eleFile );
     179  terrain->setHeightmap( _eleFile );
    175180}
    176181
    177182void TerrainEntity::loadLightmap( const std::string& _lightFile )
    178183{
    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  }
    188194}
    189195
     
    210216void TerrainEntity::draw () const
    211217{
    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();
    226233
    227234
     
    231238void TerrainEntity::buildDebugTerrainEntity(DebugTerrainEntity debugTerrainEntity)
    232239{
    233         terrain->build( );
     240  terrain->build( );
    234241  /*
    235242  // if the TerrainEntity is the TerrainEntity of Dave
     
    255262      for (int j = 0; j<sizeZ-1;j+=1)
    256263        //height[i][j] = rand()/20046 + (j-25)*(j-25)/30;
    257 #ifdef __WIN32__
     264  #ifdef __WIN32__
    258265        height[i][j]=(sin((float)j/3)*rand()*i/182400)*.5;
    259 #else
     266  #else
    260267        height[i][j]=(sin((float)j/3)*rand()*(long)i/6282450500.0)*.5;
    261 #endif
     268  #endif
    262269
    263270    //Die Huegel ein wenig glaetten
     
    369376    glEndList();
    370377  }
    371         */
     378  */
    372379  if (debugTerrainEntity == TERRAINENTITY_BENSCH)
    373380  {
     
    405412void TerrainEntity::getAltitude( Vector& _position, Vector& _normal )
    406413{
    407         Vector  altitude( _position.x-getAbsCoor().x, 0.0f, _position.z-getAbsCoor().z ),
    408                         normal( 0.0f, 0.0f, 0.0f );
    409         if ( terrain )
    410                         terrain->getAltitude( altitude, normal );
    411                        
    412         _position.y = altitude.y+getAbsCoor().y;
    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;
    414421}
    415422
    416423float TerrainEntity::getHeight( float x, float z )
    417424{
    418         Vector  altitude( x-getAbsCoor().x, 0.0f, z-getAbsCoor().z ),
    419                         normal( 0.0f, 0.0f, 0.0f );
    420         if ( terrain )
    421                 terrain->getAltitude( altitude, normal );
    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
    423430  return altitude.y+getAbsCoor().y;
    424431}
Note: See TracChangeset for help on using the changeset viewer.