Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6267 in orxonox.OLD


Ignore:
Timestamp:
Dec 22, 2005, 7:31:35 PM (18 years ago)
Author:
bensch
Message:

heightMap: sphere with some info, draw with colors

Location:
branches/height_map/src
Files:
4 edited

Legend:

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

    r6249 r6267  
    3535}
    3636
    37 HeightMap::HeightMap(const char* height_map_name = NULL) 
     37HeightMap::HeightMap(const char* height_map_name = NULL)
    3838{
    3939   this->setClassID(CL_HEIGHT_MAP, "HeightMap");
    4040   heightMap =  IMG_Load(height_map_name);
    4141   if(heightMap!=NULL) {
    42        
     42
    4343                 PRINTF(0)("loading Image %s\n", height_map_name);
    4444                 PRINTF(0)("width : %i\n", heightMap->w);
     
    4949                 PRINTF(0)("Gshift: %i\n", heightMap->format->Gshift);
    5050                 PRINTF(0)("Rmask: %i\n", heightMap->format->Rmask);
    51                  PRINTF(0)("Gmask: %i\n", heightMap->format->Gmask);           
    52                 }
    53                  
     51                 PRINTF(0)("Gmask: %i\n", heightMap->format->Gmask);
     52                }
     53
    5454     else       PRINTF(4)("oops! couldn't load %s for some reason.\n", height_map_name);
    5555
    56                
     56
    5757           generateNormalVectorField();
    58            
    59            
     58
     59
    6060 //Defines 2 Materials (for testing only!)
    61  this->tmp_mat = new Material(); 
     61 this->tmp_mat = new Material();
    6262  tmp_mat->setTransparency(1.0);
    6363  tmp_mat->setIllum(0.3);
     
    7272  tmp_mat->specularTexture = NULL;
    7373
    74  this->red_mat = new Material(); 
     74 this->red_mat = new Material();
    7575  red_mat->setTransparency(1.0);
    7676  red_mat->setIllum(0.3);
     
    9393   heightMap =  IMG_Load(height_map_name);
    9494   if(heightMap!=NULL) {
    95        
     95
    9696                 PRINTF(0)("loading Image %s\n", height_map_name);
    9797                 PRINTF(0)("width : %i\n", heightMap->w);
     
    102102                 PRINTF(0)("Gshift: %i\n", heightMap->format->Gshift);
    103103                 PRINTF(0)("Rmask: %i\n", heightMap->format->Rmask);
    104                  PRINTF(0)("Gmask: %i\n", heightMap->format->Gmask);           
    105                 }
    106                  
     104                 PRINTF(0)("Gmask: %i\n", heightMap->format->Gmask);
     105                }
     106
    107107     else       PRINTF(4)("oops! couldn't load %s for some reason.\n", height_map_name);
    108108
    109                
     109
    110110           generateNormalVectorField();
    111            
    112            
     111
     112
    113113 //Defines 2 Materials (for testing only!)
    114  this->tmp_mat = new Material("tmp"); 
     114 this->tmp_mat = new Material("tmp");
    115115  tmp_mat->setTransparency(1.0);
    116116  tmp_mat->setIllum(0.3);
     
    120120  tmp_mat->setSpecular(0.0,0.00,0.00);
    121121  tmp_mat->setShininess(1.0);
    122  
    123 
    124 
    125 
    126  this->red_mat = new Material("red"); 
     122
     123
     124
     125
     126 this->red_mat = new Material("red");
    127127  red_mat->setTransparency(1.0);
    128128  red_mat->setIllum(3);
     
    136136 // red_mat->ambientTexture = NULL;
    137137  //red_mat->specularTexture = NULL;
    138  
     138
    139139  if(colour_map_name != NULL)
    140140  {
     
    153153                 }
    154154                 else       PRINTF(4)("oops! couldn't load %s for some reason.\n", colour_map_name);
    155                  
     155
    156156  const  char* texture_name = "pictures/ground1.tga";
    157157  tmp_mat->setDiffuseMap(texture_name);
     
    164164  {
    165165  hasColourMap = false;
    166  
    167  
     166
     167
    168168  }
    169  
     169
    170170 // tmp_mat->setAmbientMap(texture_name);
    171171  //tmp_mat->setSpecularMap(texture_name);
    172  
     172
    173173  // red_mat->setDiffuseMap(texture_name);
    174174  // red_mat->setAmbientMap(texture_name);
    175   //red_mat->setSpecularMap(texture_name);                             
     175  //red_mat->setSpecularMap(texture_name);
    176176  }
    177  
    178  
     177
     178
    179179}
    180180HeightMap::~HeightMap()
     
    193193tmp_mat->select();
    194194
    195 unsigned char height = 0; 
     195unsigned char height = 0;
    196196 int offset = 0;
    197197 int g = 0;
     
    201201 heights  = (unsigned char*) heightMap->pixels;
    202202 bool colourChanged = true;
    203  
    204  
     203
     204
    205205 /*
    206206 if(heightMap != NULL && heightMap->format->BitsPerPixel == 8 )
    207207        {}
    208208        SDL_LockSurface(heightMap);
    209        
    210        
    211                
     209
     210
     211
    212212        for(int i = 0 ; i < heightMap->h -sampleRate ; i +=sampleRate)
    213213        {
    214                
     214
    215215                tmp_mat->select();
    216216
    217217
    218                
     218
    219219                int j = 0;
    220        
     220
    221221
    222222            for(int j = 0 ; j < heightMap->w -sampleRate  ;  j += sampleRate)
     
    235235                tmp_mat->setAmbient(r/255.0,g/255.0,b/255.0);
    236236                tmp_mat->setDiffuse(r/255.0,g/255.0,b/255.0);
    237                 tmp_mat->select();     
    238                 }
    239                 }
    240                
    241                
     237                tmp_mat->select();
     238                }
     239                }
     240
     241
    242242                height = heights[j+sampleRate + i*(heightMap->w )];
    243243                this->addNormal(normalVectorField[i][j+sampleRate].y,normalVectorField[i][j+sampleRate].z,normalVectorField[i][j+2].x);
    244244                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                
     245
     246                this->addVertex(scaleX*(heightMap->h -i),(double)((double)(height)*scaleY),scaleZ*(j+sampleRate)); // Top Right
     247
     248
     249
    250250            }
    251                
    252                        
    253                        
    254 
    255                        
    256                        
    257        
    258 
    259                
    260                 }
    261                
    262            
    263        
     251
     252
     253
     254
     255
     256
     257
     258
     259
     260                }
     261
     262
     263
    264264        SDL_UnlockSurface(heightMap);
    265        
    266        
     265
     266
    267267        int cnt = 0;
    268268        for(int i = 0 ; i < heightMap->h -sampleRate ; i +=sampleRate)
     
    271271            for(int j = 0 ; j < heightMap->w -sampleRate  ;  j += sampleRate)
    272272            {
    273                
    274                 this->addIndice(cnt);   
     273
     274                this->addIndice(cnt);
    275275                cnt ++;
    276276            }
     
    279279                this->newStripe();
    280280                }
    281         }       
    282        
    283        
    284        
    285        
     281        }
     282
     283
     284
     285
    286286                     */
    287        
    288         this->planeModel();
     287
     288        this->planeModel(10.0, 10.0, 20, 20);
    289289
    290290        this->finalize();
     
    294294
    295295/*
    296 void HeightMap::draw() 
     296void HeightMap::draw()
    297297{
    298298
     
    309309glTexCoord2d(1.0,0.0);
    310310 glVertex3f(x-10,getHeight(x-10,y+10)+5.0f       ,y+10); // Top Left
    311  
     311
    312312
    313313glNormal3f(0,1,0);
    314314glTexCoord2d(1.0,1.0);
    315315 glVertex3f(x+10,getHeight(x+10,y+10)+5.0f ,y+10); // Top Left
    316  
     316
    317317
    318318glNormal3f(0,1,0);
    319319glTexCoord2d(0.0,0.0);
    320320 glVertex3f(x-10,getHeight(x-10,y-10)+5.0f ,y-10); // Top Left
    321  
     321
    322322
    323323glNormal3f(0,1,0);
    324324glTexCoord2d(0.0,1.0);
    325325 glVertex3f(x+10,getHeight(x+10,y-10)+5.0f ,y-10); // Top Left
    326  
     326
    327327glEnd();
    328328
    329329tmp_mat->select();
    330330
    331 unsigned char height = 0; 
     331unsigned char height = 0;
    332332 int offset = 0;
    333333 int g = 0;
     
    338338
    339339 bool colourChanged = true;
    340  
     340
    341341  if(heightMap != NULL && heightMap->format->BitsPerPixel == 8 )
    342342        {
    343343        SDL_LockSurface(heightMap);
    344344
    345                    glBegin(GL_TRIANGLE_STRIP); 
     345                   glBegin(GL_TRIANGLE_STRIP);
    346346        for(int i = 0 ; i < heightMap->h -sampleRate ; i +=sampleRate)
    347347        {
     
    349349
    350350
    351                
     351
    352352                int j = 0;
    353        
     353
    354354/*
    355355                height = heights[j + i*(heightMap->w )];
     
    361361                glVertex3f(20*(heightMap->h -(i+2))-1000,(double)((double)(height)/1-300),20*(j)-1000); // Bottom Left
    362362
    363 */             
     363*/
    364364/*
    365365            for(int j = 0 ; j < heightMap->w -sampleRate  ;  j += sampleRate)
     
    378378                 tmp_mat->setAmbient(r/255.0,g/255.0,b/255.0);
    379379                 tmp_mat->setDiffuse(r/255.0,g/255.0,b/255.0);
    380                 tmp_mat->select();     
     380                tmp_mat->select();
    381381                }
    382382                }
     
    387387                glNormal3f(normalVectorField[i][j+sampleRate].y,normalVectorField[i][j+sampleRate].z,normalVectorField[i][j+2].x);
    388388                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                                
     389
     390                glVertex3f(scaleX*(heightMap->h -i),(double)((double)(height)*scaleY),scaleZ*(j+sampleRate)); // Top Right
     391
    392392                height = heights[j+sampleRate + (i+sampleRate)*(heightMap->w )];
    393393                glNormal3f(normalVectorField[i+sampleRate][j+sampleRate].y,normalVectorField[i+sampleRate][j+sampleRate].z,normalVectorField[i+sampleRate][j+sampleRate].x);
     
    395395                //glTexCoord2f(0.0,0.0);
    396396                glVertex3f(scaleX*(heightMap->h -(i+sampleRate)),(double)((double)(height)*scaleY),scaleZ*(j+sampleRate)); // Bottom Right
    397  
     397
    398398                }
    399399                else
     
    401401                        //red_mat->select();
    402402                        //glEnd();
    403                        
    404                        
    405                        
    406                         glBegin(GL_TRIANGLE_STRIP);     
    407                        
     403
     404
     405
     406                        glBegin(GL_TRIANGLE_STRIP);
     407
    408408                                drawRect(j,i+sampleRate/2,j+sampleRate/2,i);
    409409                        glEnd();
    410410                        glBegin(GL_TRIANGLE_STRIP);
    411                                
    412                                
     411
     412
    413413                                drawRect(j+sampleRate/2,i+sampleRate/2,j+sampleRate,i);
    414414                        glEnd();
    415415                        glBegin(GL_TRIANGLE_STRIP);
    416                                
    417                        
     416
     417
    418418                                drawRect(j,i+sampleRate,j+sampleRate/2,i+sampleRate/2);
    419419                        glEnd();
    420420                        glBegin(GL_TRIANGLE_STRIP);
    421421                                drawRect(j+sampleRate/2,i+sampleRate,j+sampleRate,i+sampleRate/2);
    422                        
     422
    423423                        glEnd();
    424                        
    425                        
    426 
    427                        
    428                        
     424
     425
     426
     427
     428
    429429                        //subdivide
    430430                }
    431431
    432                
     432
    433433                }
    434434                j =  heightMap->w -sampleRate;
    435                
    436                
     435
     436
    437437                glNormal3f(normalVectorField[i+sampleRate][j+sampleRate].y,normalVectorField[i+sampleRate][j+sampleRate].z,normalVectorField[i+sampleRate][j+sampleRate].x);
    438438                //glTexCoord2f(((j/sampleRate)%4)/4.0,1/4.0+((i/sampleRate)%4)/4.0);
     
    440440                glTexCoord2f(((j/sampleRate)%4)/4.0,((i/sampleRate)%4)/4.0);
    441441                glVertex3f(scaleX*(heightMap->h -i),(double)((double)-1000.0),scaleZ*(j+sampleRate)); // Top Right
    442                
     442
    443443                glNormal3f(normalVectorField[i+sampleRate][j+sampleRate].y,normalVectorField[i+sampleRate][j+sampleRate].z,normalVectorField[i+sampleRate][j+sampleRate].x);
    444444                                glTexCoord2f(((j/sampleRate)%4)/4.0,1/4.0+((i/sampleRate)%4)/4.0);
    445        
     445
    446446                glVertex3f(scaleX*(heightMap->h -(i+sampleRate)),(double)-1000.0,scaleZ*(j+sampleRate)); // Bottom Right
    447447
    448                
    449                
    450                                
    451              
    452                 //glEnd();     
    453            
     448
     449
     450
     451
     452                //glEnd();
     453
    454454        }
    455455        SDL_UnlockSurface(heightMap);
     
    480480            for(int j = 0; j < heightMap->w  -1  ;  j ++)
    481481            {
    482                
     482
    483483
    484484                delta = (int)heights[j + (i+1)*(heightMap->w )] -  (int) heights[j + i*(heightMap->w )];
    485485                Vector a =  Vector(-20.0,(float)delta  ,0.0f);
    486        
     486
    487487                delta = (int)heights[j+1 + i*(heightMap->w )] - (int)heights[j + i*(heightMap->w )];
    488488                Vector b =  Vector(0.0f,(float) delta ,20.0);
    489                
    490        
     489
     490
    491491                 normalVectorField[i][j] = b.cross(a);
    492492                 normalVectorField[i][j].normalize();
    493        
    494              } 
     493
     494             }
    495495        }
    496496        SDL_UnlockSurface(heightMap);
     
    505505        if(true)
    506506        {
    507                
     507
    508508                height = heights[xTop + yTop*(heightMap->w )];
    509509                glNormal3f(normalVectorField[yTop][xTop].y,normalVectorField[yTop][xTop].z,normalVectorField[yTop][xTop].x);
     
    515515                glTexCoord2f(((yBottom/sampleRate)%8)/8.0,((xBottom/sampleRate)%8)/8.0+0.125);
    516516                glVertex3f(scaleX*(heightMap->h -(yTop)),(double)((double)(height)*scaleY),scaleZ*(xBottom)); // Top Left
    517                
     517
    518518                height = heights[xTop + (yBottom)*(heightMap->w )];
    519519                glNormal3f(normalVectorField[yBottom][xTop].y,normalVectorField[yBottom][xTop].z,normalVectorField[yBottom][xTop].x);
    520520                glTexCoord2f(((yBottom/sampleRate)%8)/8.0+0.125,((yBottom/sampleRate)%8)/8.0);
    521521                glVertex3f(scaleX*(heightMap->h -(yBottom)),(double)((double)(height)*scaleY),scaleZ*(xTop)); // Bottom Right
    522                
     522
    523523height = heights[xBottom + (yBottom)*(heightMap->w )];
    524524                glNormal3f(normalVectorField[yBottom][xBottom].y,normalVectorField[yBottom][xBottom].z,normalVectorField[yBottom][xBottom].x);
     
    526526                glVertex3f(scaleX*(heightMap->h -(yBottom)),(double)((double)(height)*scaleY),scaleZ*(xBottom)); // Bottom Left
    527527
    528                
     528
    529529
    530530        }
     
    533533                // subdivide
    534534        }
    535        
     535
    536536}
    537537
     
    541541
    542542        int height = 0;
    543        
     543
    544544        for(int i= xTopRight; i < xBottomLeft ; i+= sampleRate)
    545545        {
    546        
     546
    547547        glBegin(GL_TRIANGLES);
    548                        
     548
    549549                        height = heights[yBottomLeft + (i + sampleRate)*(heightMap->w )];
    550550                        glNormal3f(0,1,0);
    551551                        glVertex3f(scaleX*(heightMap->h -i-sampleRate),scaleY*height,scaleZ*(yBottomLeft));
    552                        
     552
    553553                        height = heights[yBottomLeft + i*(heightMap->w )];
    554554                        glNormal3f(0,1,0);
    555                         glVertex3f(scaleX*(heightMap->h -i),scaleY*height,scaleZ*(yBottomLeft)); 
    556                        
     555                        glVertex3f(scaleX*(heightMap->h -i),scaleY*height,scaleZ*(yBottomLeft));
     556
    557557                        height = heights[yBottomLeft + (i + sampleRate/2)*(heightMap->w )];
    558558                        glNormal3f(0,1,0);
    559                         glVertex3f(scaleX*(heightMap->h -i - sampleRate/2),scaleY*height,scaleZ*(yBottomLeft)); 
    560                        
    561                          
    562                        
     559                        glVertex3f(scaleX*(heightMap->h -i - sampleRate/2),scaleY*height,scaleZ*(yBottomLeft));
     560
     561
     562
    563563                        glEnd();
    564                                
    565                        
    566                                
    567        
     564
     565
     566
     567
    568568        }
    569569        for(int j= yBottomLeft; j < yTopRight; j+= sampleRate)
     
    572572                        height = heights[j + (xBottomLeft+sampleRate)*(heightMap->w )];
    573573                        glNormal3f(-1,0,0);
    574                         glVertex3f(scaleX*(heightMap->h -xBottomLeft -sampleRate),scaleY*height,scaleZ*(j)); 
    575                        
     574                        glVertex3f(scaleX*(heightMap->h -xBottomLeft -sampleRate),scaleY*height,scaleZ*(j));
     575
    576576                        height = heights[j + sampleRate/2  + (xBottomLeft + sampleRate)*(heightMap->w )];
    577577                        glNormal3f(-1,0,0);
    578                         glVertex3f(scaleX*(heightMap->h -xBottomLeft - sampleRate),scaleY*height,scaleZ*(j+sampleRate/2)); 
    579                        
     578                        glVertex3f(scaleX*(heightMap->h -xBottomLeft - sampleRate),scaleY*height,scaleZ*(j+sampleRate/2));
     579
    580580                        height = heights[j + sampleRate + (xBottomLeft + sampleRate)*(heightMap->w )];
    581581                        glNormal3f(-1,0,0);
    582                         glVertex3f(scaleX*(heightMap->h -xBottomLeft-sampleRate),scaleY*height,scaleZ*(j+sampleRate)); 
    583                        
     582                        glVertex3f(scaleX*(heightMap->h -xBottomLeft-sampleRate),scaleY*height,scaleZ*(j+sampleRate));
     583
    584584                        glEnd();
    585585        }
     
    597597{
    598598 int xInt = (int)x / scaleX;  x -= (float)xInt*scaleX; xInt = heightMap->h - xInt;
    599  int yInt = (int)y / scaleZ;    y -= (float)yInt*scaleZ; 
     599 int yInt = (int)y / scaleZ;    y -= (float)yInt*scaleZ;
    600600 if(xInt <= 0 || xInt >= heightMap->h || yInt <= 0 || yInt >= heightMap->w  ) return 0.0f;
    601601 float height = heights[yInt + (xInt)*heightMap->w]*scaleY;
  • branches/height_map/src/lib/graphics/importer/vertex_array_model.cc

    r6266 r6267  
    181181  // finalize the Arrays
    182182  this->newStripe();
    183 
    184   /*
    185     glEnableClientState(GL_VERTEX_ARRAY |
    186     GL_TEXTURE_COORD_ARRAY |
    187     GL_NORMAL_ARRAY);
    188   */
    189 
    190183  this->bFinalized = true;
    191184}
     185
    192186
    193187
     
    201195* This will inject a Cube, because this is the most basic model.
    202196*/
    203 void VertexArrayModel::planeModel()
    204 {
    205   GLuint sizeX = 20;
    206   GLuint sizeY = 20;
    207 
     197void VertexArrayModel::planeModel(float sizeX, float sizeY, unsigned int resolutionX, unsigned int resolutionY)
     198{
    208199  GLuint i, j;
    209   for (i = 0; i < sizeY; i++)
    210     {
    211       for (j = 0; j < sizeX; j++)
     200  for (i = 0; i < resolutionY; i++)
     201    {
     202      for (j = 0; j < resolutionX; j++)
    212203        {
    213           this->addVertex((float)i - (float)sizeY/2.0, sin((float)i/(float)sizeY*5.0)*cos((float)j/(float)sizeX*5.0)*5.0, (float)j - (float)sizeX/2.0);
     204          this->addVertex((float)i - (float)sizeY/2.0, 0.0, (float)j - (float)sizeX/2.0);
    214205          this->addNormal(0.0, 1, 0.0);
    215           this->addTexCoor((float)i/(float)sizeY, (float)j/(float)sizeY);
     206          this->addTexCoor((float)i/(float)resolutionY, (float)j/(float)resolutionY);
    216207          this->addColor((float)i/20.0, 0.0, (float)j/20.0);
    217208        }
    218209    }
    219210
    220   for (i = 0; i < sizeY-1; i++)
    221   {
    222     for (j = 0; j < sizeX; j++)
    223     {
    224       this->addIndice( sizeY*i + j );
    225       this->addIndice( sizeY*(i+1) + j );
     211  for (i = 0; i < resolutionY-1; i++)
     212  {
     213    for (j = 0; j < resolutionX; j++)
     214    {
     215      this->addIndice( resolutionY*i + j );
     216      this->addIndice( resolutionY*(i+1) + j );
    226217    }
    227218    this->newStripe();
     
    231222#include <cmath>
    232223
     224/**
     225 * @brief builds a Triangle Stripped sphere
     226 * @param radius: radius
     227 * @param loops: the count of loops
     228 * @param segmentsPerLoop how many Segments per loop
     229 */
    233230void VertexArrayModel::spiralSphere(const float radius, const unsigned int loops, const unsigned int segmentsPerLoop)
    234231{
     
    283280
    284281
    285 
     282/**
     283 * @brief print out some nice debug information about this VertexArrayModel.
     284 */
    286285void VertexArrayModel::debug() const
    287286{
  • branches/height_map/src/lib/graphics/importer/vertex_array_model.h

    r6265 r6267  
    4545
    4646  //
    47   void planeModel();
     47  void planeModel(float sizeX, float sizeY, unsigned int resolutionX, unsigned int resolutionY);
    4848  void spiralSphere(const float radius, const unsigned int loops, const unsigned int segmentsPerLoop);
    4949
  • branches/height_map/src/story_entities/world.cc

    r6266 r6267  
    393393
    394394  VertexArrayModel* mod = new VertexArrayModel;
    395   mod->spiralSphere( 10,0,0);
     395  mod->planeModel(10.0, 10.0, 20, 20);
    396396  mod->finalize();
    397397  mod->debug();
Note: See TracChangeset for help on using the changeset viewer.