Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8328 in orxonox.OLD for branches/terrain/src/world_entities


Ignore:
Timestamp:
Jun 12, 2006, 5:17:14 PM (19 years ago)
Author:
ponder
Message:
  • Renamed Terrain into TerrainEntity in order to avoid conflicts between the importer/terrain class and the world_entities/terrain.
  • Changed TerrainEntity to support the new terrain class.
Location:
branches/terrain/src/world_entities
Files:
1 edited
2 moved

Legend:

Unmodified
Added
Removed
  • branches/terrain/src/world_entities/WorldEntities.am

    r8271 r8328  
    88                world_entities/skysphere.cc \
    99                world_entities/skybox.cc \
    10                 world_entities/terrain.cc \
     10                world_entities/terrain_entity.cc \
    1111                world_entities/satellite.cc \
    1212                world_entities/movie_entity.cc \
     
    6363                skysphere.h \
    6464                skybox.h \
    65                 terrain.h \
     65                terrain_entity.h \
    6666                satellite.h \
    6767                movie_entity.h \
  • branches/terrain/src/world_entities/terrain_entity.cc

    r8321 r8328  
    1616
    1717
    18 #include "terrain.h"
    19 
     18#include "terrain_entity.h"
     19#include "terrain/terrain.h"
    2020#include "util/loading/load_param.h"
    2121#include "util/loading/factory.h"
     
    2626#include "network_game_manager.h"
    2727
    28 #include "height_map.h"
    2928#include "material.h"
    3029
     
    3534using namespace std;
    3635
    37 CREATE_FACTORY(Terrain, CL_TERRAIN);
     36CREATE_FACTORY( TerrainEntity, CL_TERRAIN );
    3837
    3938/**
    4039 *  standard constructor
    4140 */
    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);
     41TerrainEntity::TerrainEntity (const TiXmlElement* root)
     42{
     43        this->init();
     44
     45
     46        if( root != NULL)
     47                this->loadParams(root);
     48        terrain->build( );
    5249}
    5350
    5451
    5552/**
    56  *  Constructor for loading a Terrain out of a file
     53 *  Constructor for loading a TerrainEntity out of a file
    5754 * @param fileName The file to load data from.
    5855
    5956   this either loads out of an OBJ-file, or loads a heightmap if no .obj-extension is found.
    6057*/
    61 Terrain::Terrain(const std::string& fileName)
     58TerrainEntity::TerrainEntity(const std::string& fileName )
    6259{
    6360  this->init();
     
    7673 *  a Constructor for the Debug-Worlds
    7774 */
    78 Terrain::Terrain(DebugTerrain debugTerrain)
     75TerrainEntity::TerrainEntity(DebugTerrainEntity debugTerrainEntity)
    7976{
    8077  this->init();
    81   this->buildDebugTerrain(debugTerrain);
     78  this->buildDebugTerrainEntity(debugTerrainEntity);
    8279}
    8380
     
    8683
    8784*/
    88 Terrain::~Terrain ()
     85TerrainEntity::~TerrainEntity ()
    8986{
    9087  if (objectList)
    9188    glDeleteLists(this->objectList, 1);
    92   if( this->ssp)
    93     delete ssp;
     89
    9490  if (this->vegetation)
    9591  {
    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
     100void TerrainEntity::init()
     101{
     102  this->setClassID( CL_TERRAIN, "TerrainEntity");
    107103  this->toList(OM_ENVIRON_NOTICK);
    108104  this->toReflectionList();
    109105
    110106  this->objectList = 0;
    111   this->ssp = NULL;
    112107  this->vegetation = NULL;
    113108
    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
     115void 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
     130void TerrainEntity::setScale(float x, float y, float z)
     131{
     132        terrain->setScale( Triple( x, y, z ) );
     133}
     134
     135void TerrainEntity::loadElevationmap( const std::string& _eleFile )
     136{
     137        terrain->setHeightmap( _eleFile );
     138}
     139
     140void TerrainEntity::loadLightmap( const std::string& _lightFile )
     141{
     142        terrain->setLightmap( _lightFile );
     143}
     144
     145
     146
     147void TerrainEntity::loadVegetation(const std::string& vegetationFile)
    179148{
    180149  PRINTF(4)("loadVegetation: %s\n", vegetationFile.c_str());
     
    194163
    195164
    196 void Terrain::draw () const
    197 {
    198   glPushMatrix();
     165void TerrainEntity::draw () const
     166{
     167        glMatrixMode( GL_MODELVIEW );
     168        glPushMatrix();
    199169
    200170  /* translate */
    201   glTranslatef (this->getAbsCoor ().x,
     171 /* glTranslatef (this->getAbsCoor ().x,
    202172                this->getAbsCoor ().y,
    203                 this->getAbsCoor ().z);
     173                this->getAbsCoor ().z );*/
    204174  /* rotate */
    205175  // Vector tmpRot = this->getAbsDir().getSpacialAxis();
    206176  //glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
    207177
    208   if (this->objectList)
     178  /*if (this->objectList)
    209179    glCallList(this->objectList);
    210180  else if (this->getModel())
     
    213183  if (this->vegetation)
    214184    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();
    227195  /*
    228196    glMatrixMode(GL_MODELVIEW);
     
    236204    glBegin(GL_QUADS);            // Draw The Cube Using quads
    237205    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)
    239207    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)
    240208    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)
     
    244212    glPopMatrix();*/
    245213
    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
     217void TerrainEntity::buildDebugTerrainEntity(DebugTerrainEntity debugTerrainEntity)
     218{
     219        terrain->build( );
     220  /*
     221  // if the TerrainEntity is the TerrainEntity of Dave
     222  if (debugTerrainEntity == TERRAINENTITY_DAVE)
    257223  {
    258224    objectList = glGenLists(1);
     
    389355    glEndList();
    390356  }
    391 
    392   if (debugTerrain == TERRAIN_BENSCH)
     357        */
     358  if (debugTerrainEntity == TERRAINENTITY_BENSCH)
    393359  {
    394360    /*
     
    424390}
    425391
    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 }
     392float 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  
    11/*!
    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
    45
    56    @todo implement it
    67
    7     The terrain should 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.
    89*/
    910
    10 #ifndef _TERRAIN_H
    11 #define _TERRAIN_H
     11#ifndef _TERRAINENTITY_H
     12#define _TERRAINENTITY_H
    1213
    1314#include "world_entity.h"
     
    1516
    1617// FORWARD DECLARATION
    17 class SpatialSeparation;
    18 class HeightMap;
    1918class Material;
     19class Terrain;
    2020
    2121//! A simple method to call a desired debug world.
    22 enum DebugTerrain {TERRAIN_DAVE, TERRAIN_BENSCH};
     22enum DebugTerrainEntity {TERRAINENTITY_DAVE, TERRAINENTITY_BENSCH};
    2323
    2424
    25 //! A Class to handle Terrain of orxonox
    26 class Terrain : public WorldEntity
     25//! A Class to handle TerrainEntity of orxonox
     26class TerrainEntity : public WorldEntity
    2727{
    2828
    29  public:
    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();
    3434
    35   void init();
    36   virtual void loadParams(const TiXmlElement* root);
     35                void init();
     36                virtual void loadParams(const TiXmlElement* root);
    3737
    38   void loadVegetation(const std::string& vegetationFile);
     38                void loadVegetation(const std::string& vegetationFile);
    3939
    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 );
    4343
    44   void buildDebugTerrain(DebugTerrain debugTerrain);
     44                void buildDebugTerrainEntity(DebugTerrainEntity debugTerrainEntity);
    4545
    46   float getHeight(float x, float y);
    47   virtual void draw() const;
     46                float getHeight(float x, float y);
     47                virtual void draw() const;
    4848
    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;
    5956};
    6057
    61 #endif /* _TERRAIN_H */
     58#endif /* _TerrainEntity_H */
Note: See TracChangeset for help on using the changeset viewer.