Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6270 in orxonox.OLD


Ignore:
Timestamp:
Dec 23, 2005, 11:55:53 AM (18 years ago)
Author:
bottac
Message:

fixed height_map.

File:
1 edited

Legend:

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

    r6268 r6270  
    137137  //red_mat->specularTexture = NULL;
    138138
    139   if(colour_map_name != NULL)
     139  if(false /*colour_map_name != NULL*/)
    140140  {
    141141  colourMap = IMG_Load(colour_map_name);
     
    154154                 else       PRINTF(4)("oops! couldn't load %s for some reason.\n", colour_map_name);
    155155
    156   const  char* texture_name = "pictures/ground1.tga";
     156  const  char* texture_name = "pictures/ground.tga";
    157157  tmp_mat->setDiffuseMap(texture_name);
    158158  if(colourMap != NULL)
    159159  {
    160   colours = (unsigned char *) colourMap->pixels;
    161   hasColourMap = true;
     160  //colours = (unsigned char *) colourMap->pixels;
     161  hasColourMap = false;
    162162  }
    163163  else
     
    186186{
    187187
    188 this->camera = State::getCamera();
    189 this->camCoords = this->camera->getAbsCoor();
    190 float x = this->camCoords.x + 300;
    191 float y = this->camCoords.z  + 100;
     188
    192189
    193190tmp_mat->select();
     
    203200
    204201
    205  /*
     202 
    206203 if(heightMap != NULL && heightMap->format->BitsPerPixel == 8 )
    207         {}
     204       
    208205        SDL_LockSurface(heightMap);
    209206
     
    222219            for(int j = 0 ; j < heightMap->w -sampleRate  ;  j += sampleRate)
    223220            {
    224                 if(true)
     221                if(false)
    225222                {
    226223                float r = (float)colours[3*j+2  + 3*i*(heightMap->w )];
     
    238235                }
    239236                }
    240 
     237               
     238                this->addVertex(scaleX*(heightMap->h -i),(double)((double)(height)*scaleY),scaleZ*(j+sampleRate)); // Top Right
    241239
    242240                height = heights[j+sampleRate + i*(heightMap->w )];
    243                 this->addNormal(normalVectorField[i][j+sampleRate].y,normalVectorField[i][j+sampleRate].z,normalVectorField[i][j+2].x);
     241                this->addNormal(normalVectorField[i][j+sampleRate].y,normalVectorField[i][j+sampleRate].z,normalVectorField[i][j+sampleRate].x);
    244242                this->addTexCoor(((j/sampleRate)%4)/4.0,((i/sampleRate)%4)/4.0);
    245243
    246                 this->addVertex(scaleX*(heightMap->h -i),(double)((double)(height)*scaleY),scaleZ*(j+sampleRate)); // Top Right
    247 
     244                this->addColor(0.5,0.5,0.5);
    248245
    249246
    250247            }
    251 
    252 
    253 
    254 
    255 
    256 
     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                                       
    257260
    258261
     
    271274            for(int j = 0 ; j < heightMap->w -sampleRate  ;  j += sampleRate)
    272275            {
    273 
     276               
    274277                this->addIndice(cnt);
     278                this->addIndice(cnt+1 + (heightMap->w-sampleRate)/ sampleRate );
    275279                cnt ++;
    276280            }
    277                 if(i%2 == 1)
    278                 {
    279                 this->newStripe();
    280                 }
    281         }
    282 
    283 
    284 
    285 
    286                      */
    287 
    288         this->planeModel(10,10, 10,10);
     281                cnt++;
     282       
     283         this->newStripe();
     284               
     285        }
     286
     287
     288
     289
     290                     
     291
     292        //this->planeModel(100,100, 100,100);
    289293
    290294        this->finalize();
     
    293297}
    294298
    295 /*
    296 void HeightMap::draw()
    297 {
    298 
    299 this->camera = State::getCamera();
    300 this->camCoords = this->camera->getAbsCoor();
    301 float x = this->camCoords.x + 300;
    302 float y = this->camCoords.z  + 100;
    303 
    304 // Draw a red rectangle to test getHeight
    305 
    306 red_mat->select();
    307 glBegin(GL_TRIANGLE_STRIP);
    308 glNormal3f(0,1,0);
    309 glTexCoord2d(1.0,0.0);
    310  glVertex3f(x-10,getHeight(x-10,y+10)+5.0f       ,y+10); // Top Left
    311 
    312 
    313 glNormal3f(0,1,0);
    314 glTexCoord2d(1.0,1.0);
    315  glVertex3f(x+10,getHeight(x+10,y+10)+5.0f ,y+10); // Top Left
    316 
    317 
    318 glNormal3f(0,1,0);
    319 glTexCoord2d(0.0,0.0);
    320  glVertex3f(x-10,getHeight(x-10,y-10)+5.0f ,y-10); // Top Left
    321 
    322 
    323 glNormal3f(0,1,0);
    324 glTexCoord2d(0.0,1.0);
    325  glVertex3f(x+10,getHeight(x+10,y-10)+5.0f ,y-10); // Top Left
    326 
    327 glEnd();
    328 
    329 tmp_mat->select();
    330 
    331 unsigned char height = 0;
    332  int offset = 0;
    333  int g = 0;
    334  float old_r = 0.0f;
    335  float old_g = 0.0f;
    336  float old_b = 0.0f;
    337  heights  = (unsigned char*) heightMap->pixels;
    338 
    339  bool colourChanged = true;
    340 
    341   if(heightMap != NULL && heightMap->format->BitsPerPixel == 8 )
    342         {
    343         SDL_LockSurface(heightMap);
    344 
    345                    glBegin(GL_TRIANGLE_STRIP);
    346         for(int i = 0 ; i < heightMap->h -sampleRate ; i +=sampleRate)
    347         {
    348 
    349 
    350 
    351 
    352                 int j = 0;
    353 
    354 /*
    355                 height = heights[j + i*(heightMap->w )];
    356                 glNormal3f(normalVectorField[i][j].y,normalVectorField[i][j].z,normalVectorField[i][j].x);
    357                 glVertex3f(20*(heightMap->h -(i))-1000,(double)((double)(height)/1-300),20*(j)-1000); // Top Left
    358 
    359                         height = heights[j + (i+2)*(heightMap->w )];
    360                 glNormal3f(normalVectorField[i+2][j].y,normalVectorField[i+2][j].z,normalVectorField[i+2][j].x);
    361                 glVertex3f(20*(heightMap->h -(i+2))-1000,(double)((double)(height)/1-300),20*(j)-1000); // Bottom Left
    362 
    363 */
    364 /*
    365             for(int j = 0 ; j < heightMap->w -sampleRate  ;  j += sampleRate)
    366             {
    367                 if(hasColourMap)
    368                 {
    369                 float r = (float)colours[3*j+2  + 3*i*(heightMap->w )];
    370                 float g = (float)colours[3*j+1 + 3*i*(heightMap->w)];
    371                 float b = (float)colours[3*j+0 + 3*i*(heightMap->w)];
    372                 colourChanged = old_r != r || old_g != g || old_b != b;
    373                 old_r = r;
    374                 old_g = g;
    375                 old_b = b;
    376                 if(colourChanged)
    377                 {
    378                  tmp_mat->setAmbient(r/255.0,g/255.0,b/255.0);
    379                  tmp_mat->setDiffuse(r/255.0,g/255.0,b/255.0);
    380                 tmp_mat->select();
    381                 }
    382                 }
    383                 */
    384                 //if(true/*(abs(-scaleX*i-x+5000) > 1100 || abs(scaleZ*j-y-2000)  > 1100 )*/){ //subdivide??
    385                 /*
    386                 height = heights[j+sampleRate + i*(heightMap->w )];
    387                 glNormal3f(normalVectorField[i][j+sampleRate].y,normalVectorField[i][j+sampleRate].z,normalVectorField[i][j+2].x);
    388                 glTexCoord2f(((j/sampleRate)%4)/4.0,((i/sampleRate)%4)/4.0);
    389 
    390                 glVertex3f(scaleX*(heightMap->h -i),(double)((double)(height)*scaleY),scaleZ*(j+sampleRate)); // Top Right
    391 
    392                 height = heights[j+sampleRate + (i+sampleRate)*(heightMap->w )];
    393                 glNormal3f(normalVectorField[i+sampleRate][j+sampleRate].y,normalVectorField[i+sampleRate][j+sampleRate].z,normalVectorField[i+sampleRate][j+sampleRate].x);
    394                 glTexCoord2f(((j/sampleRate)%4)/4.0,1/4.0+((i/sampleRate)%4)/4.0);
    395                 //glTexCoord2f(0.0,0.0);
    396                 glVertex3f(scaleX*(heightMap->h -(i+sampleRate)),(double)((double)(height)*scaleY),scaleZ*(j+sampleRate)); // Bottom Right
    397 
    398                 }
    399                 else
    400                 {
    401                         //red_mat->select();
    402                         //glEnd();
    403 
    404 
    405 
    406                         glBegin(GL_TRIANGLE_STRIP);
    407 
    408                                 drawRect(j,i+sampleRate/2,j+sampleRate/2,i);
    409                         glEnd();
    410                         glBegin(GL_TRIANGLE_STRIP);
    411 
    412 
    413                                 drawRect(j+sampleRate/2,i+sampleRate/2,j+sampleRate,i);
    414                         glEnd();
    415                         glBegin(GL_TRIANGLE_STRIP);
    416 
    417 
    418                                 drawRect(j,i+sampleRate,j+sampleRate/2,i+sampleRate/2);
    419                         glEnd();
    420                         glBegin(GL_TRIANGLE_STRIP);
    421                                 drawRect(j+sampleRate/2,i+sampleRate,j+sampleRate,i+sampleRate/2);
    422 
    423                         glEnd();
    424 
    425 
    426 
    427 
    428 
    429                         //subdivide
    430                 }
    431 
    432 
    433                 }
    434                 j =  heightMap->w -sampleRate;
    435 
    436 
    437                 glNormal3f(normalVectorField[i+sampleRate][j+sampleRate].y,normalVectorField[i+sampleRate][j+sampleRate].z,normalVectorField[i+sampleRate][j+sampleRate].x);
    438                 //glTexCoord2f(((j/sampleRate)%4)/4.0,1/4.0+((i/sampleRate)%4)/4.0);
    439                 //glTexCoord2f(0.0,0.0);
    440                 glTexCoord2f(((j/sampleRate)%4)/4.0,((i/sampleRate)%4)/4.0);
    441                 glVertex3f(scaleX*(heightMap->h -i),(double)((double)-1000.0),scaleZ*(j+sampleRate)); // Top Right
    442 
    443                 glNormal3f(normalVectorField[i+sampleRate][j+sampleRate].y,normalVectorField[i+sampleRate][j+sampleRate].z,normalVectorField[i+sampleRate][j+sampleRate].x);
    444                                 glTexCoord2f(((j/sampleRate)%4)/4.0,1/4.0+((i/sampleRate)%4)/4.0);
    445 
    446                 glVertex3f(scaleX*(heightMap->h -(i+sampleRate)),(double)-1000.0,scaleZ*(j+sampleRate)); // Bottom Right
    447 
    448 
    449 
    450 
    451 
    452                 //glEnd();
    453 
    454         }
    455         SDL_UnlockSurface(heightMap);
    456         glEnd();
    457 }
    458 
    459 }
    460 */
     299
     300
     301
    461302void HeightMap::generateNormalVectorField()
    462303{
Note: See TracChangeset for help on using the changeset viewer.