Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 21, 2005, 4:24:50 PM (18 years ago)
Author:
bottac
Message:

Uses VertexArrayModel now

File:
1 edited

Legend:

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

    r6227 r6249  
    2121#include "state.h"
    2222#include "resource_manager.h"
    23 
    2423#include "debug.h"
    2524
     
    8887}
    8988
    90 HeightMap::HeightMap(const char* height_map_name = NULL, const char* colour_map_name = NULL)
     89HeightMap::HeightMap(const char* height_map_name = NULL, const char* colour_map_name = NULL) : VertexArrayModel()
    9190{
    9291this->setClassID(CL_HEIGHT_MAP, "HeightMap");
     
    187186{
    188187
    189 }
    190 
    191 
    192 void HeightMap::draw()
    193 {
    194 
    195188this->camera = State::getCamera();
    196189this->camCoords = this->camera->getAbsCoor();
    197190float x = this->camCoords.x + 300;
    198191float y = this->camCoords.z  + 100;
    199 
    200 // Draw a red rectangle to test getHeight
    201 
    202 red_mat->select();
    203 glBegin(GL_TRIANGLE_STRIP);
    204 glNormal3f(0,1,0);
    205 glTexCoord2d(1.0,0.0);
    206  glVertex3f(x-10,getHeight(x-10,y+10)+5.0f       ,y+10); // Top Left
    207  
    208 
    209 glNormal3f(0,1,0);
    210 glTexCoord2d(1.0,1.0);
    211  glVertex3f(x+10,getHeight(x+10,y+10)+5.0f ,y+10); // Top Left
    212  
    213 
    214 glNormal3f(0,1,0);
    215 glTexCoord2d(0.0,0.0);
    216  glVertex3f(x-10,getHeight(x-10,y-10)+5.0f ,y-10); // Top Left
    217  
    218 
    219 glNormal3f(0,1,0);
    220 glTexCoord2d(0.0,1.0);
    221  glVertex3f(x+10,getHeight(x+10,y-10)+5.0f ,y-10); // Top Left
    222  
    223 glEnd();
    224192
    225193tmp_mat->select();
     
    232200 float old_b = 0.0f;
    233201 heights  = (unsigned char*) heightMap->pixels;
    234 
    235202 bool colourChanged = true;
    236203 
     204 
     205 /*
     206 if(heightMap != NULL && heightMap->format->BitsPerPixel == 8 )
     207        {}
     208        SDL_LockSurface(heightMap);
     209       
     210       
     211               
     212        for(int i = 0 ; i < heightMap->h -sampleRate ; i +=sampleRate)
     213        {
     214               
     215                tmp_mat->select();
     216
     217
     218               
     219                int j = 0;
     220       
     221
     222            for(int j = 0 ; j < heightMap->w -sampleRate  ;  j += sampleRate)
     223            {
     224                if(true)
     225                {
     226                float r = (float)colours[3*j+2  + 3*i*(heightMap->w )];
     227                float g = (float)colours[3*j+1 + 3*i*(heightMap->w)];
     228                float b = (float)colours[3*j+0 + 3*i*(heightMap->w)];
     229                colourChanged = old_r != r || old_g != g || old_b != b;
     230                old_r = r;
     231                old_g = g;
     232                old_b = b;
     233                if(colourChanged)
     234                {
     235                tmp_mat->setAmbient(r/255.0,g/255.0,b/255.0);
     236                tmp_mat->setDiffuse(r/255.0,g/255.0,b/255.0);
     237                tmp_mat->select();     
     238                }
     239                }
     240               
     241               
     242                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);
     244                this->addTexCoor(((j/sampleRate)%4)/4.0,((i/sampleRate)%4)/4.0);
     245               
     246                this->addVertex(scaleX*(heightMap->h -i),(double)((double)(height)*scaleY),scaleZ*(j+sampleRate)); // Top Right         
     247                               
     248               
     249               
     250            }
     251               
     252                       
     253                       
     254
     255                       
     256                       
     257       
     258
     259               
     260                }
     261               
     262           
     263       
     264        SDL_UnlockSurface(heightMap);
     265       
     266       
     267        int cnt = 0;
     268        for(int i = 0 ; i < heightMap->h -sampleRate ; i +=sampleRate)
     269        {
     270
     271            for(int j = 0 ; j < heightMap->w -sampleRate  ;  j += sampleRate)
     272            {
     273               
     274                this->addIndice(cnt);   
     275                cnt ++;
     276            }
     277                if(i%2 == 1)
     278                {
     279                this->newStripe();
     280                }
     281        }       
     282       
     283       
     284       
     285       
     286                     */
     287       
     288        this->planeModel();
     289
     290        this->finalize();
     291
     292
     293}
     294
     295/*
     296void HeightMap::draw()
     297{
     298
     299this->camera = State::getCamera();
     300this->camCoords = this->camera->getAbsCoor();
     301float x = this->camCoords.x + 300;
     302float y = this->camCoords.z  + 100;
     303
     304// Draw a red rectangle to test getHeight
     305
     306red_mat->select();
     307glBegin(GL_TRIANGLE_STRIP);
     308glNormal3f(0,1,0);
     309glTexCoord2d(1.0,0.0);
     310 glVertex3f(x-10,getHeight(x-10,y+10)+5.0f       ,y+10); // Top Left
     311 
     312
     313glNormal3f(0,1,0);
     314glTexCoord2d(1.0,1.0);
     315 glVertex3f(x+10,getHeight(x+10,y+10)+5.0f ,y+10); // Top Left
     316 
     317
     318glNormal3f(0,1,0);
     319glTexCoord2d(0.0,0.0);
     320 glVertex3f(x-10,getHeight(x-10,y-10)+5.0f ,y-10); // Top Left
     321 
     322
     323glNormal3f(0,1,0);
     324glTexCoord2d(0.0,1.0);
     325 glVertex3f(x+10,getHeight(x+10,y-10)+5.0f ,y-10); // Top Left
     326 
     327glEnd();
     328
     329tmp_mat->select();
     330
     331unsigned 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 
    237341  if(heightMap != NULL && heightMap->format->BitsPerPixel == 8 )
    238342        {
    239343        SDL_LockSurface(heightMap);
    240344
    241                
     345                   glBegin(GL_TRIANGLE_STRIP); 
    242346        for(int i = 0 ; i < heightMap->h -sampleRate ; i +=sampleRate)
    243347        {
     
    245349
    246350
    247                    glBegin(GL_TRIANGLE_STRIP); 
     351               
    248352                int j = 0;
    249353       
     
    256360                glNormal3f(normalVectorField[i+2][j].y,normalVectorField[i+2][j].z,normalVectorField[i+2][j].x);
    257361                glVertex3f(20*(heightMap->h -(i+2))-1000,(double)((double)(height)/1-300),20*(j)-1000); // Bottom Left
    258 */
    259                
    260 
     362
     363*/             
     364/*
    261365            for(int j = 0 ; j < heightMap->w -sampleRate  ;  j += sampleRate)
    262366            {
     
    277381                }
    278382                }
    279                
    280                 if(true/*(abs(-scaleX*i-x+5000) > 1100 || abs(scaleZ*j-y-2000)  > 1100 )*/){ //subdivide??
    281                
     383                */
     384                //if(true/*(abs(-scaleX*i-x+5000) > 1100 || abs(scaleZ*j-y-2000)  > 1100 )*/){ //subdivide??
     385                /*
    282386                height = heights[j+sampleRate + i*(heightMap->w )];
    283387                glNormal3f(normalVectorField[i][j+sampleRate].y,normalVectorField[i][j+sampleRate].z,normalVectorField[i][j+2].x);
    284388                glTexCoord2f(((j/sampleRate)%4)/4.0,((i/sampleRate)%4)/4.0);
    285                 ///glTexCoord2f(1.0,1.0);
     389               
    286390                glVertex3f(scaleX*(heightMap->h -i),(double)((double)(height)*scaleY),scaleZ*(j+sampleRate)); // Top Right             
    287391                               
     
    292396                glVertex3f(scaleX*(heightMap->h -(i+sampleRate)),(double)((double)(height)*scaleY),scaleZ*(j+sampleRate)); // Bottom Right
    293397 
    294        
    295 
    296         /*
    297                                 height = heights[j+2 + (i+2)*(heightMap->w )];
    298                 glNormal3f(normalVectorField[i+2][j+2].y,normalVectorField[i+2][j+2].z,normalVectorField[i+2][j+2].x);
    299                 glVertex3f(20*(heightMap->h -(i+2)),(double)((double)(height)/1-300),20*(j+2)); // Bottom Right
    300 
    301 
    302                              height = heights[j + i*(heightMap->w )];
    303                 glNormal3f(normalVectorField[i][j].y,normalVectorField[i][j].z,normalVectorField[i][j].x);
    304                 glVertex3f(20*(heightMap->h -(i)),(double)((double)(height)/1-300),20*(j)); // Top Left
    305 
    306         */
    307                 g=j;
    308 
    309 
    310398                }
    311399                else
     
    335423                        glEnd();
    336424                       
    337                         /*glBegin(GL_TRIANGLE_STRIP);
    338 
    339                 height = heights[j+sampleRate + i*(heightMap->w )];
    340                 glNormal3f(normalVectorField[i][j+sampleRate].y,normalVectorField[i][j+sampleRate].z,normalVectorField[i][j+sampleRate].x);
    341                 glVertex3f(scaleX*(heightMap->h -i),(double)((double)(height)*scaleY),scaleZ*(j+sampleRate)); // Top Right             
    342                
    343 
    344                 height = heights[j+sampleRate + (i+sampleRate)*(heightMap->w )];
     425                       
     426
     427                       
     428                       
     429                        //subdivide
     430                }
     431
     432               
     433                }
     434                j =  heightMap->w -sampleRate;
     435               
     436               
    345437                glNormal3f(normalVectorField[i+sampleRate][j+sampleRate].y,normalVectorField[i+sampleRate][j+sampleRate].z,normalVectorField[i+sampleRate][j+sampleRate].x);
    346                 glVertex3f(scaleX*(heightMap->h -(i+sampleRate)),(double)((double)(height)*scaleY),scaleZ*(j+sampleRate)); // Bottom Right
    347                 */     
    348 
    349                        
    350                        
    351                         //subdivide
    352                 }
    353 
    354        
    355 
    356              } 
    357                 glEnd();       
     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();     
    358453           
    359454        }
    360455        SDL_UnlockSurface(heightMap);
    361        
    362 }
    363 
    364 
    365 /*      int c = (heightMap->w)/4 ; // One line
    366         for(int i = 0; i < (heightMap->w)/4  -4  ; i ++)
    367         {
    368             for(int j = 0; j < (heightMap->h)/4 - 4; j++)
    369             {
    370                
    371                 this->addFace (3, VERTEX_ONLY,j + (i+1)*c,j+1+i*c , j + i*c );
    372                 this->addFace (3, VERTEX_ONLY,j + (i+1)*c,j + (i+1)*c +1 ,j+i*c +1 );                           
    373                          
    374                
    375             }
    376                                
    377                        
    378                                
    379         }
    380 
     456        glEnd();
     457}
     458
     459}
    381460*/
    382 }
    383 
    384461void HeightMap::generateNormalVectorField()
    385462{
Note: See TracChangeset for help on using the changeset viewer.