Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6727 in orxonox.OLD for branches/height_map_merge/src


Ignore:
Timestamp:
Jan 25, 2006, 5:46:16 PM (19 years ago)
Author:
bottac
Message:
 
Location:
branches/height_map_merge/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/height_map_merge/src/lib/graphics/importer/height_map.cc

    r6603 r6727  
    3737lowResModel  = new VertexArrayModel();
    3838
    39 this->load(i1,j1,i2,j2,hm,highResModel,2);
     39this->load(i1,j1,i2,j2,hm,highResModel,4);
    4040this->load(i1,j1,i2,j2,hm,lowResModel, 8);
    4141}
     
    5757                                                                //FIXME
    5858    float cameraDistance = (State::getCamera()->getAbsCoor() - Vector(0.0,100.0,0.0)).len();
    59     if (cameraDistance > 5000 )
     59    if (cameraDistance > 10000 )
    6060    {
    6161   
    6262    }
    63     else if (cameraDistance > 1000 )
     63    else if (cameraDistance >= 50000 )
    6464    {
    6565      this->drawLowRes();
     
    9898        int sampleRate = Res;
    9999       
    100          float height = 0;
     100        float height = 0;
    101101        int offset = 0;
    102102       
     
    128128                model->addVertex(scaleX*(heightMap->h -i)+ shiftX,shiftY,scaleZ*(w)+ shiftZ); // Top Right
    129129                model->addNormal(normalVectorField[i][w].y,normalVectorField[i][w].z,normalVectorField[i][w].x);
    130                 model->addTexCoor((((w -sampleRate)/sampleRate)%4)/4.0,(((i-sampleRate)/sampleRate)%4)/4.0);
     130                model->addTexCoor((float)(j1-sampleRate) /(texRate), (float)(i %heightMap->h)/(texRate));
    131131                model->addColor(r/255.0,g/255.0,b/255.0);
    132132               
     
    147147                height +=  (float)(unsigned char)hm->heights[j +sampleRate+ (i+2)*(heightMap->w )];
    148148                height +=  (float)(unsigned char)hm->heights[j+sampleRate + (i)*(heightMap->w )];
    149                
    150149                height=height/5.0;
    151150               
    152151                model->addVertex(scaleX*(heightMap->h -i) + shiftX ,((double)(height)*scaleY) + shiftY ,scaleZ*(j) + shiftZ); // Top Right     
    153152                model->addNormal(normalVectorField[i][j].y,normalVectorField[i][j].z,normalVectorField[i][j].x);
    154                 model->addTexCoor((float)j /(texRate), (float)(i %heightMap->h)/(texRate));
     153                model->addTexCoor((float)(j) /(texRate), (float)(i %heightMap->h)/(texRate));
    155154               
    156155                //PRINTF(0)("TexCoord:  %f %f \n",(float)j / 100.0, (float)(i %heightMap->h)/100.0);
     
    163162                model->addVertex(scaleX*(heightMap->h -i)+ shiftX,shiftY,scaleZ*(w)+ shiftZ); // Top Right
    164163                model->addNormal(normalVectorField[i][w].y,normalVectorField[i][w].z,normalVectorField[i][w].x);
    165                 model->addTexCoor((((w+sampleRate)/sampleRate))/4.0,(((i+ sampleRate)/sampleRate))/4.0);
     164                model->addTexCoor((float)(j2+sampleRate) /(texRate), (float)(i %heightMap->h)/(texRate));
    166165                model->addColor(r/255.0,g/255.0,b/255.0);
    167166               
     
    208207                model->addVertex(scaleX*(heightMap->h -i) + shiftX , shiftY ,scaleZ*(j) + shiftZ); // Top Right
    209208                model->addNormal(normalVectorField[i][j].y,normalVectorField[i][j].z,normalVectorField[i][j].x);
    210                 model->addTexCoor(((j/sampleRate))/texRatef,(((i - sampleRate)/sampleRate))/texRatef);
     209                model->addTexCoor((float)j /(texRate), (float)((i - sampleRate) %heightMap->h)/(texRate));
    211210                model->addColor(r/255.0,g/255.0,b/255.0);               
    212211       
     
    225224                model->addVertex(scaleX*(heightMap->h -i) + shiftX , ((double)(height)*scaleY) +shiftY ,scaleZ*(j) + shiftZ); // Top Right     
    226225                model->addNormal(normalVectorField[i][j].y,normalVectorField[i][j].z,normalVectorField[i][j].x);
    227                 model->addTexCoor(((j/sampleRate))/texRatef,(((i)/sampleRate))/texRatef);
     226                model->addTexCoor((float)j /(texRate), (float)(i %heightMap->h)/(texRate));
    228227                model->addColor(r/255.0,g/255.0,b/255.0);
    229228           
     
    246245                model->addVertex(scaleX*(heightMap->h -i) + shiftX , shiftY ,scaleZ*(j) + shiftZ); // Top Right
    247246                model->addNormal(normalVectorField[i][j].y,normalVectorField[i][j].z,normalVectorField[i][j].x);
    248                 model->addTexCoor(((j/sampleRate)%texRate)/texRatef,(((i- sampleRate)/sampleRate)%texRate)/texRatef);
     247                model->addTexCoor((float)j /(texRate), (float)((i+ sampleRate) %heightMap->h)/(texRate));
    249248                model->addColor(r/255.0,g/255.0,b/255.0);               
    250249       
     
    255254            {
    256255                int i = i2;
    257                         height = (float)(unsigned char) hm->heights[j +sampleRate+ i*(heightMap->w )];
     256                height = (float)(unsigned char) hm->heights[j +sampleRate+ i*(heightMap->w )];
    258257                height += (float)(unsigned char) hm->heights[j+ 1 + sampleRate + (i+1)*(heightMap->w )];
    259258                height +=  (float) (unsigned char) hm->heights[j -1+ sampleRate   + (i+1)*(heightMap->w )];
     
    263262                model->addVertex(scaleX*(heightMap->h -i) + shiftX , ((double)(height)*scaleY) +shiftY ,scaleZ*(j) + shiftZ); // Top Right     
    264263                model->addNormal(normalVectorField[i][j].y,normalVectorField[i][j].z,normalVectorField[i][j].x);
    265                 model->addTexCoor(((j/sampleRate)%texRate)/texRatef,((i/sampleRate)%texRate)/texRatef);
     264                model->addTexCoor((float)j /(texRate), (float)(i %heightMap->h)/(texRate));
    266265                model->addColor(r/255.0,g/255.0,b/255.0);
    267266           
     
    452451        for(int j = 1; j < j_max ; j++)
    453452        {
    454                
    455453         tiles[i][j]->draw();
    456454        }       
     
    500498
    501499
    502 
    503 
    504 
    505500void HeightMap::scale(Vector v)
    506501{
     
    510505}
    511506
    512 void HeightMap::shift(Vector v)
    513 {
    514  shiftX = v.x;
    515  shiftY = v.y;
    516  shiftZ = v.z;
    517 }
    518 
    519 
    520 float HeightMap::getHeight(float x, float y)
    521 {
     507void HeightMap::setAbsCoor(Vector v)
     508{
     509 offsetX = v.x;
     510 offsetY = v.y;
     511 offsetZ  = v.z;
     512}
     513
     514
     515float HeightMap::getHeight(float x, float y)
     516{
     517
     518 //x -= offsetX;
     519 //y -= offsetZ;
     520 
     521 
    522522 int xInt = (int)x / scaleX;  x -= (float)xInt*scaleX; xInt = heightMap->h - xInt;
    523  int yInt = (int)y / scaleZ;    y -= (float)yInt*scaleZ;
    524  if(xInt <= 0 || xInt >= heightMap->h || yInt <= 0 || yInt >= heightMap->w  ) return 0.0f;
     523 int yInt = (int)y / scaleZ;    y -= (float)yInt*scaleZ; /*yInt = heightMap->w - yInt;*/
     524 
     525 if(xInt <= 0 || xInt >= heightMap->h || yInt <= 0 || yInt >= heightMap->w  ) return shiftY;
     526 
    525527 float height = heights[yInt + (xInt)*heightMap->w]*scaleY;
     528 
    526529 float a = normalVectorField[(xInt)][yInt].x;
    527530 float b = normalVectorField [(xInt)][yInt].z;
    528531 float c = normalVectorField [(xInt)][yInt].y;
    529   height -= ( (a/c)*(x) + (b/c)*(y))*scaleY;
    530  return height;
    531 }
     532 
     533 height -= ( (a/c)*(x) + (b/c)*(y);
     534 
     535 return (height );
     536}
  • branches/height_map_merge/src/lib/graphics/importer/height_map.h

    r6603 r6727  
    1010
    1111   ### File Specific:
    12    main-programmer:
     12   main-programmer: bottac@ee.ethz.ch
    1313*/
    1414
     
    1717
    1818
    19 #define texRate      64
     19#define texRate      32
    2020#define texRatef     4.0f
    21 #define tileSize     64
     21#define tileSize     128
    2222
    2323class SDL_Surface;
     
    5858void load(const char*, int Mode);
    5959void scale( Vector V);
    60 void shift (Vector V);
     60void setAbsCoor(Vector V);
    6161float getHeight(float x, float y);
     62float getNormal(float x, float y);
    6263HeightMap();
    6364HeightMap(const char*);
     
    7879Vector  **  normalVectorField ;
    7980Tile    ***  tiles;
    80 Vector     camCoords;
     81Vector    camCoords;
     82Vector offsetCoords; 
    8183Material * tmp_mat;
    8284Material* red_mat;
     
    8688float scaleY ;
    8789float scaleZ ;
    88 float shiftX ;
    89 float shiftY ;
    90 float shiftZ ;
     90float shiftX ; // to be removed
     91float shiftY ; // to be removed
     92float shiftZ ; // to be removed
     93float offsetX;
     94float offsetY;
     95float offsetZ;
    9196int   cmScaleX;
    9297int   cmScaleY;
  • branches/height_map_merge/src/world_entities/terrain.cc

    r6603 r6727  
    3030
    3131#include "glincl.h"
     32
     33#include "state.h"
    3234
    3335using namespace std;
     
    154156
    155157  this->heightMap = new HeightMap(hmName, hmColorName);
    156   heightMap->scale(Vector(23.0f,3.5f,23.0f));
    157   heightMap->shift(Vector(-1000.0,-90.0,-4000.0));
     158  heightMap->scale(Vector(23.0f,1.1f,23.0f));
     159  heightMap->setAbsCoor(this->getAbsCoor());
    158160  heightMap->load();
    159161  delete[] hmName;
     
    166168{
    167169  if (this->heightMapMaterial != NULL)
    168     delete this->heightMapMaterial;
     170      delete this->heightMapMaterial;
    169171
    170172
     
    214216void Terrain::draw () const
    215217{
     218 
     219   
     220 
    216221  glMatrixMode(GL_MODELVIEW);
    217222  glPushMatrix();
    218223
    219224  /* translate */
    220   glTranslatef (this->getAbsCoor ().x,
     225 /* glTranslatef (this->getAbsCoor ().x,
    221226                this->getAbsCoor ().y,
    222227                this->getAbsCoor ().z);
     228        */     
    223229  /* rotate */
    224   Vector tmpRot = this->getAbsDir().getSpacialAxis();
    225   glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
     230 // Vector tmpRot = this->getAbsDir().getSpacialAxis();
     231  //glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
    226232
    227233  if (this->objectList)
     
    237243        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    238244        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    239    
    240          glEnable(GL_LIGHTING);
     245        glEnable(GL_LIGHTING);
    241246        glColorMaterial ( GL_FRONT_AND_BACK, GL_EMISSION ) ;
    242247        glEnable (GL_COLOR_MATERIAL) ;
     
    245250  glPopMatrix();
    246251
    247 
    248 
     252 glMatrixMode(GL_MODELVIEW);
     253glPushMatrix();
     254glLoadIdentity();
     255 Vector camera =   State::getCamera()->getAbsCoor(); // Go on here ..........!!!
     256    float height =    heightMap->getHeight(camera.x, camera.z);
     257   
     258  glEnable (GL_COLOR_MATERIAL) ;
     259    glBegin(GL_QUADS);            // Draw The Cube Using quads
     260    glColor3f(0.0f,1.0f,0.0f);  // Color Blue
     261    glVertex3f(camera.x + 13.0f,height+13.0f,camera.z-13.0f);      // Top Right Of The Quad (Top)
     262    glVertex3f(camera.x-13.0f, height+13.0f,camera.z-13.0f);      // Top Left Of The Quad (Top)
     263    glVertex3f(camera.x-13.0f, height+13.0f, camera.z+13.0f);      // Bottom Left Of The Quad (Top)
     264    glVertex3f(camera.x+ 13.0f, height+13.0f, camera.z+13.0f);      // Bottom Right Of The Quad (Top)
     265   glEnd();                      // End Drawing The Plan
     266   
     267   
     268glPopMatrix();
    249269  /* THIS IS ONLY FOR DEBUGGING INFORMATION */
    250270  if (this->ssp != NULL)
     
    457477{
    458478}
     479
     480float Terrain::getHeight(float x, float y)
     481{
     482        if(this->heightMap != NULL)
     483                return (this->heightMap->getHeight(x, y));
     484        return 0;
     485}
  • branches/height_map_merge/src/world_entities/terrain.h

    r6495 r6727  
    4646
    4747  void buildDebugTerrain(DebugTerrain debugTerrain);
     48 
     49  float getHeight(float x, float y);
    4850  virtual void draw() const;
    4951
Note: See TracChangeset for help on using the changeset viewer.