Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6329 in orxonox.OLD


Ignore:
Timestamp:
Dec 28, 2005, 1:51:28 PM (18 years ago)
Author:
bottac
Message:

Fixed some bugs.

Location:
branches/height_map/src
Files:
3 edited

Legend:

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

    r6270 r6329  
    3535}
    3636
    37 HeightMap::HeightMap(const char* height_map_name = NULL)
     37HeightMap::HeightMap(const char* height_map_name = NULL) : VertexArrayModel()
    3838{
    3939   this->setClassID(CL_HEIGHT_MAP, "HeightMap");
     
    4343                 PRINTF(0)("loading Image %s\n", height_map_name);
    4444                 PRINTF(0)("width : %i\n", heightMap->w);
    45                  PRINTF(0)("hight : %i\n", heightMap->h);
     45                 PRINTF(0)("height : %i\n", heightMap->h);
    4646                 PRINTF(0)("%i Byte(s) per Pixel \n", heightMap->format->BytesPerPixel);
    4747                 PRINTF(0)("Rshift : %i\n", heightMap->format->Rshift);
     
    5454     else       PRINTF(4)("oops! couldn't load %s for some reason.\n", height_map_name);
    5555
    56 
    57            generateNormalVectorField();
    58 
    59 
    60  //Defines 2 Materials (for testing only!)
    61  this->tmp_mat = new Material();
    62   tmp_mat->setTransparency(1.0);
    63   tmp_mat->setIllum(0.3);
    64   tmp_mat->setDiffuse(0.55,0.4,0.2);
    65   tmp_mat->setAmbient(0.6,0.4,0.2);
    66   tmp_mat->setSpecular(0.02,0.02,0.02);
    67   tmp_mat->setShininess(.1);
    68   tmp_mat->setTransparency(1.0);
    69 
    70   tmp_mat->diffuseTexture = NULL;
    71   tmp_mat->ambientTexture = NULL;
    72   tmp_mat->specularTexture = NULL;
    73 
    74  this->red_mat = new Material();
    75   red_mat->setTransparency(1.0);
    76   red_mat->setIllum(0.3);
    77   red_mat->setDiffuse(0.55,0.1,0.1);
    78   red_mat->setAmbient(0.55,0.1,0.1);
    79   red_mat->setSpecular(0.02,0.02,0.02);
    80   red_mat->setShininess(.1);
    81   red_mat->setTransparency(1.0);
    82 
    83   red_mat->diffuseTexture = NULL;
    84   red_mat->ambientTexture = NULL;
    85   red_mat->specularTexture = NULL;
     56       
     57  generateNormalVectorField();
     58
     59  shiftX = 0;
     60  shiftY = 0;
     61  shiftZ = 0;
    8662
    8763}
     
    9672                 PRINTF(0)("loading Image %s\n", height_map_name);
    9773                 PRINTF(0)("width : %i\n", heightMap->w);
    98                  PRINTF(0)("hight : %i\n", heightMap->h);
     74                 PRINTF(0)("height : %i\n", heightMap->h);
    9975                 PRINTF(0)("%i Byte(s) per Pixel \n", heightMap->format->BytesPerPixel);
    10076                 PRINTF(0)("Rshift : %i\n", heightMap->format->Rshift);
     
    10884
    10985
    110            generateNormalVectorField();
    111 
    112 
    113  //Defines 2 Materials (for testing only!)
    114  this->tmp_mat = new Material("tmp");
    115   tmp_mat->setTransparency(1.0);
    116   tmp_mat->setIllum(0.3);
    117   tmp_mat->setDiffuse(1.0,1.0,1.0);
    118  tmp_mat->setAmbient(1.0,1.0,1.0);
    119 
    120   tmp_mat->setSpecular(0.0,0.00,0.00);
    121   tmp_mat->setShininess(1.0);
    122 
    123 
    124 
    125 
    126  this->red_mat = new Material("red");
    127   red_mat->setTransparency(1.0);
    128   red_mat->setIllum(3);
    129   red_mat->setDiffuse(0.55,0.1,0.1);
    130   red_mat->setAmbient(0.55,0.1,0.1);
    131   red_mat->setSpecular(0.0,0.0,0.0);
    132   red_mat->setShininess(1.0);
    133   red_mat->setTransparency(1.0);
    134 
    135  // red_mat->diffuseTexture = NULL;
    136  // red_mat->ambientTexture = NULL;
    137   //red_mat->specularTexture = NULL;
    138 
    139   if(false /*colour_map_name != NULL*/)
     86    generateNormalVectorField();
     87
     88
     89  if(colour_map_name != NULL)
    14090  {
    14191  colourMap = IMG_Load(colour_map_name);
     
    14494                 PRINTF(0)("loading Image %s\n", colour_map_name);
    14595                 PRINTF(0)("width : %i\n", colourMap->w);
    146                  PRINTF(0)("hight : %i\n", colourMap->h);
     96                 PRINTF(0)("height : %i\n", colourMap->h);
    14797                 PRINTF(0)("%i Byte(s) per Pixel \n", colourMap->format->BytesPerPixel);
    14898                 PRINTF(0)("Rshift : %i\n", colourMap->format->Rshift);
     
    154104                 else       PRINTF(4)("oops! couldn't load %s for some reason.\n", colour_map_name);
    155105
    156   const  char* texture_name = "pictures/ground.tga";
    157   tmp_mat->setDiffuseMap(texture_name);
     106                 
     107                   
    158108  if(colourMap != NULL)
    159109  {
    160   //colours = (unsigned char *) colourMap->pixels;
    161   hasColourMap = false;
     110  colours = (unsigned char *) colourMap->pixels;
     111  hasColourMap = true;
    162112  }
    163   else
    164   {
    165   hasColourMap = false;
    166 
    167 
     113  else hasColourMap = false;
     114 
     115       
     116  shiftX = 0;
     117  shiftY = 0;
     118  shiftZ = 0;
    168119  }
    169120
    170  // tmp_mat->setAmbientMap(texture_name);
    171   //tmp_mat->setSpecularMap(texture_name);
    172 
    173   // red_mat->setDiffuseMap(texture_name);
    174   // red_mat->setAmbientMap(texture_name);
    175   //red_mat->setSpecularMap(texture_name);
    176   }
    177 
    178121
    179122}
     
    185128void HeightMap::load()
    186129{
    187 
    188 
    189 
    190 tmp_mat->select();
    191130
    192131unsigned char height = 0;
    193132 int offset = 0;
    194133 int g = 0;
    195  float old_r = 0.0f;
    196  float old_g = 0.0f;
    197  float old_b = 0.0f;
     134 
     135
     136 
    198137 heights  = (unsigned char*) heightMap->pixels;
    199  bool colourChanged = true;
     138
    200139
    201140
     
    205144        SDL_LockSurface(heightMap);
    206145
    207 
    208 
     146     
    209147        for(int i = 0 ; i < heightMap->h -sampleRate ; i +=sampleRate)
    210148        {
    211 
    212                 tmp_mat->select();
    213 
    214 
    215 
    216149                int j = 0;
    217150
    218 
     151                float r;
     152                float g;
     153                float b;
    219154            for(int j = 0 ; j < heightMap->w -sampleRate  ;  j += sampleRate)
    220155            {
    221                 if(false)
    222                 {
    223                 float r = (float)colours[3*j+2  + 3*i*(heightMap->w )];
    224                 float g = (float)colours[3*j+1 + 3*i*(heightMap->w)];
    225                 float b = (float)colours[3*j+0 + 3*i*(heightMap->w)];
    226                 colourChanged = old_r != r || old_g != g || old_b != b;
    227                 old_r = r;
    228                 old_g = g;
    229                 old_b = b;
    230                 if(colourChanged)
    231                 {
    232                 tmp_mat->setAmbient(r/255.0,g/255.0,b/255.0);
    233                 tmp_mat->setDiffuse(r/255.0,g/255.0,b/255.0);
    234                 tmp_mat->select();
    235                 }
    236                 }
    237                
    238                 this->addVertex(scaleX*(heightMap->h -i),(double)((double)(height)*scaleY),scaleZ*(j+sampleRate)); // Top Right
    239 
    240                 height = heights[j+sampleRate + i*(heightMap->w )];
     156                 // To be fixed
     157                 r = (float)colours[3*j+2 + 3*i*(heightMap->w )];
     158                 g = (float)colours[3*j+1 + 3*i*(heightMap->w)];
     159                 b = (float)colours[3*j+0 + 3*i*(heightMap->w)];
     160               
     161                        height =  heights[j+sampleRate + i*(heightMap->w )];
     162                this->addVertex(scaleX*(heightMap->h -i) + shiftX ,((double)(height)*scaleY) + shiftY ,scaleZ*(j+sampleRate) + shiftZ); // Top Right
     163
     164       
     165                this->addNormal(normalVectorField[i][j+sampleRate].y,normalVectorField[i][j+sampleRate].z,normalVectorField[i][j+sampleRate].x);
     166                this->addTexCoor(((j/sampleRate)%texRate)/texRatef,((i/sampleRate)%texRate)/texRatef);
     167
     168                this->addColor(r/255.0,g/255.0,b/255.0);
     169
     170
     171            }
     172               
     173           
     174                 j = (heightMap->w/sampleRate - sampleRate);
     175
     176                this->addVertex(scaleX*(heightMap->h -i)+ shiftX,-1000.0,scaleZ*(j+sampleRate)+ shiftZ); // Top Right
     177
    241178                this->addNormal(normalVectorField[i][j+sampleRate].y,normalVectorField[i][j+sampleRate].z,normalVectorField[i][j+sampleRate].x);
    242179                this->addTexCoor(((j/sampleRate)%4)/4.0,((i/sampleRate)%4)/4.0);
    243 
    244                 this->addColor(0.5,0.5,0.5);
    245 
    246 
     180                this->addColor(0.1,0.1,0.9);
     181                                       
     182
     183               
     184
     185                }
     186
     187        SDL_UnlockSurface(heightMap);
     188
     189
     190        int cnt = 0;
     191        for(int i = 0 ; i < heightMap->h - 2*sampleRate ; i +=sampleRate)
     192        {
     193               
     194            for(int j = 0 ; j < heightMap->w - sampleRate  ;  j += sampleRate)
     195            {
     196               
     197                this->addIndice(cnt);
     198                this->addIndice(cnt  + (heightMap->w)/ sampleRate );
     199                cnt++;
     200               
    247201            }
    248                
    249                  j = (heightMap->w/sampleRate);
    250 
    251                 this->addVertex(scaleX*(heightMap->h -i),(double)(double)(-1000),scaleZ*(j+sampleRate)); // Top Right
    252 
    253                 height = heights[j+sampleRate + i*(heightMap->w )];
    254                 this->addNormal(normalVectorField[i][j+sampleRate].y,normalVectorField[i][j+sampleRate].z,normalVectorField[i][j+sampleRate].x);
    255                 this->addTexCoor(((j/sampleRate)%4)/4.0,((i/sampleRate)%4)/4.0);
    256 
    257                 this->addColor(0.5,0.5,0.5);
    258 
    259                                        
    260 
    261 
    262 
    263                 }
    264 
    265 
    266 
    267         SDL_UnlockSurface(heightMap);
    268 
    269 
    270         int cnt = 0;
    271         for(int i = 0 ; i < heightMap->h -sampleRate ; i +=sampleRate)
    272         {
    273 
    274             for(int j = 0 ; j < heightMap->w -sampleRate  ;  j += sampleRate)
    275             {
    276                
    277                 this->addIndice(cnt);
    278                 this->addIndice(cnt+1 + (heightMap->w-sampleRate)/ sampleRate );
    279                 cnt ++;
    280             }
    281                 cnt++;
    282        
    283          this->newStripe();
     202               
     203                cnt++;
     204                 this->newStripe();     
     205               
    284206               
    285207        }
    286 
    287 
    288 
    289 
    290                      
    291 
    292         //this->planeModel(100,100, 100,100);
    293208
    294209        this->finalize();
     
    317232        {
    318233        SDL_LockSurface(heightMap);
    319         for(int i = 0 ; i < heightMap->h -1  ; i ++)
    320         {
    321             for(int j = 0; j < heightMap->w  -1  ;  j ++)
     234        for(int i = 0 ; i < heightMap->h - 1  ; i ++)
     235        {
     236            for(int j = 0; j < heightMap->w  - 1  ;  j ++)
    322237            {
    323238
    324239
    325240                delta = (int)heights[j + (i+1)*(heightMap->w )] -  (int) heights[j + i*(heightMap->w )];
    326                 Vector a =  Vector(-20.0,(float)delta  ,0.0f);
     241                Vector a =  Vector(-scaleX,(float)delta*scaleY  ,0.0f);
    327242
    328243                delta = (int)heights[j+1 + i*(heightMap->w )] - (int)heights[j + i*(heightMap->w )];
    329                 Vector b =  Vector(0.0f,(float) delta ,20.0);
     244                Vector b =  Vector(0.0f,(float) delta*scaleY ,scaleZ);
    330245
    331246
    332247                 normalVectorField[i][j] = b.cross(a);
    333248                 normalVectorField[i][j].normalize();
    334 
     249                 
    335250             }
    336251        }
     
    341256}
    342257
    343 void HeightMap::drawRect(int xBottom, int yBottom, int xTop, int yTop )
    344 {
    345         int height = 0;
    346         if(true)
    347         {
    348 
    349                 height = heights[xTop + yTop*(heightMap->w )];
    350                 glNormal3f(normalVectorField[yTop][xTop].y,normalVectorField[yTop][xTop].z,normalVectorField[yTop][xTop].x);
    351                 glTexCoord2f(((yBottom/sampleRate)%8)/8.0+0.125,((xBottom/sampleRate)%8)/8.0+0.125);
    352                 glVertex3f(scaleX*(heightMap->h - yTop),(double)((double)(height)*scaleY),scaleZ*(xTop)); // Top Right
    353 
    354                 height = heights[xBottom + yTop*(heightMap->w )];
    355                 glNormal3f(normalVectorField[yTop][xBottom].y,normalVectorField[yTop][xBottom].z,normalVectorField[yTop][xBottom].x);
    356                 glTexCoord2f(((yBottom/sampleRate)%8)/8.0,((xBottom/sampleRate)%8)/8.0+0.125);
    357                 glVertex3f(scaleX*(heightMap->h -(yTop)),(double)((double)(height)*scaleY),scaleZ*(xBottom)); // Top Left
    358 
    359                 height = heights[xTop + (yBottom)*(heightMap->w )];
    360                 glNormal3f(normalVectorField[yBottom][xTop].y,normalVectorField[yBottom][xTop].z,normalVectorField[yBottom][xTop].x);
    361                 glTexCoord2f(((yBottom/sampleRate)%8)/8.0+0.125,((yBottom/sampleRate)%8)/8.0);
    362                 glVertex3f(scaleX*(heightMap->h -(yBottom)),(double)((double)(height)*scaleY),scaleZ*(xTop)); // Bottom Right
    363 
    364 height = heights[xBottom + (yBottom)*(heightMap->w )];
    365                 glNormal3f(normalVectorField[yBottom][xBottom].y,normalVectorField[yBottom][xBottom].z,normalVectorField[yBottom][xBottom].x);
    366                 glTexCoord2f(((yBottom/sampleRate)%8)/8.0,((yBottom/sampleRate)%8)/8.0);
    367                 glVertex3f(scaleX*(heightMap->h -(yBottom)),(double)((double)(height)*scaleY),scaleZ*(xBottom)); // Bottom Left
    368 
    369 
    370 
    371         }
    372         else
    373         {
    374                 // subdivide
    375         }
    376 
    377 }
    378 
    379 
    380 void HeightMap::fixBoarder(int xBottomLeft, int yBottomLeft, int xTopRight, int yTopRight)
    381 {
    382 
    383         int height = 0;
    384 
    385         for(int i= xTopRight; i < xBottomLeft ; i+= sampleRate)
    386         {
    387 
    388         glBegin(GL_TRIANGLES);
    389 
    390                         height = heights[yBottomLeft + (i + sampleRate)*(heightMap->w )];
    391                         glNormal3f(0,1,0);
    392                         glVertex3f(scaleX*(heightMap->h -i-sampleRate),scaleY*height,scaleZ*(yBottomLeft));
    393 
    394                         height = heights[yBottomLeft + i*(heightMap->w )];
    395                         glNormal3f(0,1,0);
    396                         glVertex3f(scaleX*(heightMap->h -i),scaleY*height,scaleZ*(yBottomLeft));
    397 
    398                         height = heights[yBottomLeft + (i + sampleRate/2)*(heightMap->w )];
    399                         glNormal3f(0,1,0);
    400                         glVertex3f(scaleX*(heightMap->h -i - sampleRate/2),scaleY*height,scaleZ*(yBottomLeft));
    401 
    402 
    403 
    404                         glEnd();
    405 
    406 
    407 
    408 
    409         }
    410         for(int j= yBottomLeft; j < yTopRight; j+= sampleRate)
    411         {
    412                    glBegin(GL_TRIANGLES);
    413                         height = heights[j + (xBottomLeft+sampleRate)*(heightMap->w )];
    414                         glNormal3f(-1,0,0);
    415                         glVertex3f(scaleX*(heightMap->h -xBottomLeft -sampleRate),scaleY*height,scaleZ*(j));
    416 
    417                         height = heights[j + sampleRate/2  + (xBottomLeft + sampleRate)*(heightMap->w )];
    418                         glNormal3f(-1,0,0);
    419                         glVertex3f(scaleX*(heightMap->h -xBottomLeft - sampleRate),scaleY*height,scaleZ*(j+sampleRate/2));
    420 
    421                         height = heights[j + sampleRate + (xBottomLeft + sampleRate)*(heightMap->w )];
    422                         glNormal3f(-1,0,0);
    423                         glVertex3f(scaleX*(heightMap->h -xBottomLeft-sampleRate),scaleY*height,scaleZ*(j+sampleRate));
    424 
    425                         glEnd();
    426         }
    427 }
     258
     259
     260
    428261
    429262void HeightMap::scale(Vector v)
     
    434267}
    435268
    436 // Accepts Coordinates relative to HeightMap
     269void HeightMap::shift(Vector v)
     270{
     271 shiftX = v.x;
     272 shiftY = v.y;
     273 shiftZ = v.z;
     274}
     275
     276
    437277float HeightMap::getHeight(float x, float y)
    438278{
  • branches/height_map/src/lib/graphics/importer/height_map.h

    r6249 r6329  
    1717
    1818#define sampleRate 4
     19#define texRate   4
     20#define texRatef   4.0f
    1921
    2022class SDL_Surface;
     
    3234void load(const char*, int Mode);
    3335void scale( Vector V);
    34 float getHeight(float x, float y); // x,y relative to HeightMap
     36void shift (Vector V);
     37float getHeight(float x, float y);
    3538HeightMap();
    3639HeightMap(const char*);
     
    5659float scaleY ;
    5760float scaleZ ;
     61float shiftX ;
     62float shiftY ;
     63float shiftZ ;
    5864int   cmScaleX;
    5965int   cmScaleY;
    6066bool  hasColourMap;
     67
    6168inline int abs(int val)
    6269{
  • branches/height_map/src/world_entities/terrain.cc

    r6268 r6329  
    4444  this->tmp_mat = new Material();
    4545  tmp_mat->setTransparency(1.0);
    46   tmp_mat->setIllum(0.3);
     46  tmp_mat->setIllum(0.2);
    4747/*  tmp_mat->setDiffuse(0.55,0.4,0.2);
    4848  tmp_mat->setAmbient(0.6,0.4,0.2);
     
    5151  tmp_mat->setAmbient(1.0,1.0,1.0 );
    5252  tmp_mat->setSpecular(1.0,1.0,1.0);
    53   tmp_mat->setShininess(.1);
     53  tmp_mat->setShininess(.5);
    5454  tmp_mat->setTransparency(1.0);
    5555
    5656  tmp_mat->diffuseTexture = NULL;
    5757  tmp_mat->ambientTexture = NULL;
    58  // tmp_mat->specularTexture = NULL;
     58  tmp_mat->specularTexture = NULL;
    5959 
     60    const  char* texture_name = "pictures/ground1.tga";
     61  tmp_mat->setDiffuseMap(texture_name);
     62  tmp_mat->setAmbientMap(texture_name);
     63   tmp_mat->setSpecularMap(texture_name);
    6064  // this->loadParams(root);
    6165
     
    6367 char* colourmapName = ResourceManager::getFullName("pictures/heightmapHelloCM.bmp");
    6468 hm = new HeightMap(heightmapName, colourmapName);
    65  hm->scale(Vector(23.0f,1.7f,23.0f));
     69 hm->scale(Vector(43.0f,1.10f,43.0f));
     70 hm->shift(Vector(-1000.0,-1500.0,-1000.0));
    6671 hm->load();
    6772 this->model=hm;
     
    217222  glPushMatrix();
    218223
     224 
    219225  /* translate */
    220   glTranslatef (this->getAbsCoor ().x - 1000,
    221                 this->getAbsCoor ().y - 400,
    222                 this->getAbsCoor ().z - 1000)   ;
     226 glTranslatef (this->getAbsCoor ().x ,
     227               this->getAbsCoor ().y ,
     228               this->getAbsCoor ().z)   ;
     229 
    223230  /* rotate */
    224   Vector tmpRot = this->getAbsDir().getSpacialAxis();
    225   glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
    226        
    227    //this->tmp_mat->select();
    228        
    229 
    230   hm->draw();
     231 Vector tmpRot = this->getAbsDir().getSpacialAxis();
     232 glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
     233 
     234        
     235 
     236 this->tmp_mat->select();
     237 hm->draw();
    231238 /* if (this->objectList)
    232239    glCallList(this->objectList);
Note: See TracChangeset for help on using the changeset viewer.