Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6956 in orxonox.OLD for trunk/src/world_entities/terrain.cc


Ignore:
Timestamp:
Feb 1, 2006, 4:37:08 PM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: merged the HeightMapBranche back to the trunk

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/world_entities/terrain.cc

    r6815 r6956  
    2626#include "network_game_manager.h"
    2727
     28#include "height_map.h"
     29#include "material.h"
    2830
    2931#include "glincl.h"
     32
     33#include "state.h"
    3034
    3135using namespace std;
     
    4145  if( root != NULL)
    4246    this->loadParams(root);
     47
     48   this->heightMapMaterial = new Material();
     49   heightMapMaterial->setTransparency(1.0);
     50
     51   heightMapMaterial->setDiffuse(0.4,0.4,0.4);
     52   heightMapMaterial->setAmbient(0.4,0.4,0.4 );
     53   heightMapMaterial->setSpecular(0.4,0.4,0.4);
     54   heightMapMaterial->setShininess(.5);
     55   heightMapMaterial->setTransparency(1.0);
    4356
    4457//  if (this->model != NULL)
     
    90103    ResourceManager::getInstance()->unload(this->vegetation);
    91104  }
     105
     106  if(this->heightMap)
     107        delete heightMap;
    92108}
    93109
     
    101117  this->ssp = NULL;
    102118  this->vegetation = NULL;
     119
     120  this->heightMap = NULL;
     121  this->heightMapMaterial = NULL;
    103122}
    104123
     
    110129  LoadParam(root, "vegetation", this, Terrain, loadVegetation)
    111130      .describe("the fileName of the vegetation, that should be loaded onto this terrain. (must be relative to the data-dir)") ;
    112 }
     131
     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  LoadParam(root, "heigt-texture", this, Terrain, loadTexture)
     138      .describe("The name of the Texture for this heightMap");
     139}
     140
     141void Terrain::loadHeightMap(const char* heightMapFile, const char* colorMap)
     142{
     143  if (this->heightMap != NULL)
     144    delete this->heightMap;
     145  this->heightMap = NULL;
     146
     147  char* hmName = ResourceManager::getFullName(heightMapFile);
     148  char* hmColorName = ResourceManager::getFullName(colorMap);
     149
     150
     151  this->heightMap = new HeightMap(hmName, hmColorName);
     152  heightMap->scale(Vector(43.0f,4.7f,43.0f));
     153  heightMap->setAbsCoor(this->getAbsCoor());
     154  heightMap->load();
     155  delete[] hmName;
     156  delete[] hmColorName;
     157
     158}
     159
     160
     161void Terrain::loadTexture(const char* textureName)
     162{
     163  if (this->heightMapMaterial != NULL)
     164      delete this->heightMapMaterial;
     165
     166delete this->heightMapMaterial;
     167
     168   this->heightMapMaterial = new Material();
     169   heightMapMaterial->setTransparency(1.0);
     170
     171   heightMapMaterial->setDiffuse(1.0,1.0,1.0);
     172   heightMapMaterial->setAmbient(1.0,1.0,1.0 );
     173   heightMapMaterial->setSpecular(1.0,1.0,1.0);
     174   heightMapMaterial->setShininess(.5);
     175   heightMapMaterial->setTransparency(1.0);
     176
     177   heightMapMaterial->setDiffuseMap(textureName);
     178   heightMapMaterial->setAmbientMap(textureName);
     179   heightMapMaterial->setSpecularMap(textureName);
     180
     181
     182
     183}
     184
     185
    113186
    114187void Terrain::loadVegetation(const char* vegetationFile)
     
    128201
    129202
     203
     204
    130205void Terrain::draw () const
    131206{
     
    137212                this->getAbsCoor ().z);
    138213  /* rotate */
    139   Vector tmpRot = this->getAbsDir().getSpacialAxis();
    140   glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
     214 // Vector tmpRot = this->getAbsDir().getSpacialAxis();
     215  //glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
    141216
    142217  if (this->objectList)
     
    146221  if (this->vegetation)
    147222    this->vegetation->draw();
     223
     224  if(this->heightMap)
     225        {
     226        this->heightMapMaterial->select();
     227        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
     228        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
     229        glEnable(GL_LIGHTING);
     230        glColorMaterial ( GL_FRONT_AND_BACK, GL_EMISSION ) ;
     231        glEnable (GL_COLOR_MATERIAL) ;
     232        this->heightMap->draw();
     233        }
    148234  glPopMatrix();
    149235
     236
     237
     238
     239
     240 glMatrixMode(GL_MODELVIEW);
     241glPushMatrix();
     242glLoadIdentity();
     243 Vector camera =   State::getCamera()->getAbsCoor(); // Go on here ..........!!!
     244
     245    /*
     246    float height =    heightMap->getHeight(camera.x, camera.z);
     247
     248
     249  glEnable (GL_COLOR_MATERIAL) ;
     250    glBegin(GL_QUADS);            // Draw The Cube Using quads
     251    glColor3f(0.0f,1.0f,0.0f);  // Color Blue
     252    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)
     253    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)
     254    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)
     255    glVertex3f(camera.x+ 63.0f, getHeight(camera.x+63.0f, camera.z+10.0f)+13.0f, camera.z+10.0f);      // Bottom Right Of The Quad (Top)
     256   glEnd();                      // End Drawing The Plan
     257   */
     258
     259glPopMatrix();
    150260  /* THIS IS ONLY FOR DEBUGGING INFORMATION */
    151261  if (this->ssp != NULL)
     
    360470{
    361471}
     472
     473float Terrain::getHeight(float x, float y)
     474{
     475        if(this->heightMap != NULL)
     476                return (this->heightMap->getHeight(x, y));
     477        return 0;
     478}
Note: See TracChangeset for help on using the changeset viewer.