Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7014 in orxonox.OLD


Ignore:
Timestamp:
Feb 3, 2006, 2:14:22 PM (18 years ago)
Author:
bensch
Message:

trunk: new algorithm for the Camera-Distance

Location:
trunk/src
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/graphics/effects/lense_flare.cc

    r7009 r7014  
    202202
    203203    //set the frustum plane
    204   Vector psTarget = (State::getCameraTarget())->getAbsCoor();
    205   Vector psCamera = (State::getCamera())->getAbsCoor();
     204  Vector psTarget = (State::getCameraTargetNode())->getAbsCoor();
     205  Vector psCamera = (State::getCameraNode())->getAbsCoor();
    206206  Vector psCameraDir = psCamera - psTarget;
    207207  //PRINTF(0)("camera Dir: %f %f %f, camera: %f %f %f\n", psCameraDir.x, psCameraDir.y, psCameraDir.z, psCamera.x, psCamera.y, psCamera.z);
  • trunk/src/lib/graphics/importer/height_map.cc

    r6956 r7014  
    3030#endif
    3131
    32 Tile::Tile(int i1, int j1, int i2, int j2, HeightMap* hm ) 
     32Tile::Tile(int i1, int j1, int i2, int j2, HeightMap* hm )
    3333{
    3434
     
    5454void Tile::draw()
    5555{
    56         // This Draws the LOD's
    57                                                                 //FIXME
    58     float cameraDistance = (State::getCamera()->getAbsCoor() - Vector(this->x, hmref->offsetY , this->z) ).len();
    59         if(cameraDistance < 0) cameraDistance = -cameraDistance;
     56        // This Draws the LOD's
     57                                                                //FIXME
     58    float cameraDistance = (State::getCameraNode()->getAbsCoor() - Vector(this->x, hmref->offsetY , this->z) ).len();
     59        if(cameraDistance < 0) cameraDistance = -cameraDistance;
    6060    if(cameraDistance > 5000 )
    6161    {
     
    6666      this->drawLowRes();
    6767    }
    68     else 
     68    else
    6969    {
    7070      this->drawHighRes();
     
    8686void Tile::load(int i1, int j1, int i2, int j2, HeightMap* hm, VertexArrayModel* model, int Res)
    8787{
    88        
    89         #define heightMap hm->heightMap
    90         #define colours   hm->colours
    91         #define scaleX hm->scaleX
    92         #define scaleY hm->scaleY
    93         #define scaleZ hm->scaleZ
    94         #define shiftX hm->shiftX
    95         #define shiftY hm->shiftY
    96         #define shiftZ hm->shiftZ
    97         #define normalVectorField hm->normalVectorField
    98        
    99         hmref = hm; // FIXME
    100        
    101         this->x = hm->offsetX + (heightMap->h - ((i1+i2)/2))*scaleX;
    102         this->z = hm->offsetZ + ((j1 + j2 )/2 ) * scaleZ;
    103        
    104         int sampleRate = Res;
    105        
    106         float height = 0;
    107         int offset = 0;
    108        
    109         float r = 0.0;
    110         float g = 0.0;
    111         float b = 0.0;
    112 
    113  
    114 
    115  
     88
     89        #define heightMap hm->heightMap
     90        #define colours   hm->colours
     91        #define scaleX hm->scaleX
     92        #define scaleY hm->scaleY
     93        #define scaleZ hm->scaleZ
     94        #define shiftX hm->shiftX
     95        #define shiftY hm->shiftY
     96        #define shiftZ hm->shiftZ
     97        #define normalVectorField hm->normalVectorField
     98
     99        hmref = hm; // FIXME
     100
     101        this->x = hm->offsetX + (heightMap->h - ((i1+i2)/2))*scaleX;
     102        this->z = hm->offsetZ + ((j1 + j2 )/2 ) * scaleZ;
     103
     104        int sampleRate = Res;
     105
     106        float height = 0;
     107        int offset = 0;
     108
     109        float r = 0.0;
     110        float g = 0.0;
     111        float b = 0.0;
     112
     113
     114
     115
    116116 if(heightMap != NULL && heightMap->format->BitsPerPixel == 8 )
    117        
    118         SDL_LockSurface(heightMap);
    119         SDL_LockSurface(hm->colourMap);
    120        
    121         for(int i = i1 ; i <= i2  ; i +=sampleRate)
    122         {
    123                 int w = 0;
    124 
    125                
    126                
    127                 if(hm->hasColourMap)
    128                 {
    129                 r = colours[(3*w+2 + 3*i*(heightMap->w )) ];
    130                 g = colours[(3*w+1 + 3*i*(heightMap->w)) ];
    131                 b = colours[(3*w+0 + 3*i*(heightMap->w))];
    132                 }
    133                
    134                 w = j1;
    135                 model->addVertex(scaleX*(heightMap->h -i)+ shiftX,shiftY,scaleZ*(w)+ shiftZ); // Top Right
    136                 model->addNormal(normalVectorField[i % heightMap->h][w % heightMap->w].y,normalVectorField[i % heightMap->h][w % heightMap->w].z,normalVectorField[i % heightMap->h][w % heightMap->w].x);
    137                 model->addTexCoor((float)(j1-sampleRate) /(texRate), (float)(i %heightMap->h)/(texRate));
    138                
    139                 model->addColor(r/255.0,g/255.0,b/255.0);
    140                
    141             for(int j = j1  ; j <= j2    ;  j += sampleRate)
    142             {
    143            
    144            
    145                 // To be fixed
    146                 if(hm->hasColourMap)
    147                 {
    148                 r = colours[(3*j+2 + 3*i*(heightMap->w )) ];
    149                 g =  colours[(3*j+1 + 3*i*(heightMap->w)) ];
    150                 b =  colours[(3*j+0 + 3*i*(heightMap->w))];
    151                 }
    152                 height = (float)(unsigned char) hm->heights[(j +sampleRate+ i*(heightMap->w )) ];
    153                 height += (float)(unsigned char) hm->heights[(j+ 1 + sampleRate + (i+1)*(heightMap->w )) ];
    154                 height +=  (float) (unsigned char) hm->heights[(j -1+ sampleRate   + (i+1)*(heightMap->w ))];
    155                 height +=  (float)(unsigned char)hm->heights[(j +sampleRate+ (i+2)*(heightMap->w )) ];
    156                 height +=  (float)(unsigned char)hm->heights[(j+sampleRate + (i)*(heightMap->w )) ];
    157                 height=height/5.0;
    158                
    159                 model->addVertex(scaleX*(heightMap->h -i) + shiftX ,((double)(height)*scaleY) + shiftY ,scaleZ*(j) + shiftZ); // Top Right     
    160                 model->addNormal(normalVectorField[i % heightMap->h][j % heightMap->w].y,normalVectorField[i % heightMap->h][j % heightMap->w].z,normalVectorField[i % heightMap->h][j % heightMap->w].x);
    161                 model->addTexCoor((float)(j) /(texRate), (float)(i %heightMap->h)/(texRate));
    162                
    163                 //PRINTF(0)("TexCoord:  %f %f \n",(float)j / 100.0, (float)(i %heightMap->h)/100.0);
    164                
    165                 model->addColor(r/255.0,g/255.0,b/255.0);
    166                 w = j;
    167             }
    168                
    169                
    170                 model->addVertex(scaleX*(heightMap->h -i)+ shiftX,shiftY,scaleZ*(w)+ shiftZ); // Top Right
    171                 model->addNormal(normalVectorField[i % heightMap->h][w % heightMap->w].y,normalVectorField[i % heightMap->h][w % heightMap->w].z,normalVectorField[i% heightMap->h][w % heightMap->w].x);
    172                 model->addTexCoor((float)(j2+sampleRate) /(texRate), (float)(i %heightMap->h)/(texRate));
    173                 model->addColor(r/255.0,g/255.0,b/255.0);
    174                
    175         }
    176        
    177        
    178        
    179 
    180 
    181         SDL_UnlockSurface(heightMap);
    182         int cnt = 0;
    183         for(int i = i1   ; i < i2  ; i +=sampleRate)
    184         {
    185                
    186             for(int j = j1-sampleRate  ; j < j2  + 2*sampleRate  ;  j += sampleRate)
    187             {
    188                
    189                 model->addIndice(cnt);
    190                 model->addIndice(cnt  + (j2 -j1 + 3* sampleRate  )/ sampleRate );
    191                 cnt++;
    192                
    193             }
    194                
    195                
    196                
    197                  model->newStripe();   
    198                
    199                
    200         }
    201         cnt += (j2 -j1 + 3* sampleRate)/ sampleRate;
    202        
    203                 for(int j = j1 ; j <= j2    ;  j += sampleRate)
    204             {
    205                 int i = i1;
    206            
    207                 // To be fixed
    208                 if(hm->hasColourMap)
    209                 {
    210                 r = (float)colours[(3*j+2 + 3*i*(heightMap->w )) ];
    211                 g = (float)colours[(3*j+1 + 3*i*(heightMap->w)) ];
    212                 b = (float)colours[(3*j+0 + 3*i*(heightMap->w))];
    213                 }
    214                
    215                 model->addVertex(scaleX*(heightMap->h -i) + shiftX , shiftY ,scaleZ*(j) + shiftZ); // Top Right
    216                 model->addNormal(normalVectorField[i % heightMap->h][j % heightMap->w].y,normalVectorField[i % heightMap->h][j % heightMap->w].z,normalVectorField[i % heightMap->h][j % heightMap->w].x);
    217                 model->addTexCoor((float)j /(texRate), (float)((i - sampleRate) %heightMap->h)/(texRate));
    218                 model->addColor(r/255.0,g/255.0,b/255.0);               
    219        
    220             }
    221 
    222                 for(int j = j1  ; j <= j2    ;  j += sampleRate)
    223             {
    224                 int i = i1;
    225                 height = (float)(unsigned char) hm->heights[(j +sampleRate+ i*(heightMap->w )) ];
    226                 height += (float)(unsigned char) hm->heights[(j+ 1 + sampleRate + (i+1)*(heightMap->w )) ];
    227                 height +=  (float) (unsigned char) hm->heights[(j -1+ sampleRate   + (i+1)*(heightMap->w ))];
    228                 height +=  (float)(unsigned char)hm->heights[(j +sampleRate+ (i+2)*(heightMap->w )) ];
    229                 height +=  (float)(unsigned char)hm->heights[(j+sampleRate + (i)*(heightMap->w )) ];
    230                 height=height/5.0;
    231                
    232                 model->addVertex(scaleX*(heightMap->h -i) + shiftX , ((double)(height)*scaleY) +shiftY ,scaleZ*(j) + shiftZ); // Top Right     
    233                 model->addNormal(normalVectorField[i % heightMap->h][j % heightMap->w].y,normalVectorField[i % heightMap->h][j% heightMap->w].z,normalVectorField[i%heightMap->h][j%heightMap->w].x);
    234                 model->addTexCoor((float)j /(texRate), (float)(i %heightMap->h)/(texRate));
    235                 model->addColor(r/255.0,g/255.0,b/255.0);
    236            
    237             }
    238            
    239                
    240            
    241             for(int j = j1  ; j <= j2    ;  j += sampleRate)
    242             {
    243                 int i = i2;
    244            
    245                 // To be fixed
    246                 if(hm->hasColourMap)
    247                 {
    248                 r = (float)colours[3*j+2 + 3*i*(heightMap->w )];
    249                 g = (float)colours[3*j+1 + 3*i*(heightMap->w)];
    250                 b = (float)colours[3*j+0 + 3*i*(heightMap->w)];
    251                 }
    252                
    253                 model->addVertex(scaleX*(heightMap->h -i) + shiftX , shiftY ,scaleZ*(j) + shiftZ); // Top Right
    254                 model->addNormal(normalVectorField[i%heightMap->h][j%heightMap->w].y,normalVectorField[i%heightMap->h][j%heightMap->w].z,normalVectorField[i%heightMap->h][j%heightMap->w].x);
    255                 model->addTexCoor((float)j /(texRate), (float)((i+ sampleRate) %heightMap->h)/(texRate));
    256                 model->addColor(r/255.0,g/255.0,b/255.0);               
    257        
    258             }
    259                    
    260            
    261             for(int j = j1 ; j <= j2    ;  j += sampleRate)
    262             {
    263                 int i = i2;
    264                 height = (float)(unsigned char) hm->heights[(j +sampleRate+ i*(heightMap->w )) ];
    265                 height += (float)(unsigned char) hm->heights[(j+ 1 + sampleRate + (i+1)*(heightMap->w )) ];
    266                 height +=  (float) (unsigned char) hm->heights[(j -1+ sampleRate   + (i+1)*(heightMap->w ))];
    267                 height +=  (float)(unsigned char)hm->heights[(j +sampleRate+ (i+2)*(heightMap->w ))];
    268                 height +=  (float)(unsigned char)hm->heights[(j+sampleRate + (i)*(heightMap->w )) ];
    269                 height=height/5.0;
    270                 model->addVertex(scaleX*(heightMap->h -i) + shiftX , ((double)(height)*scaleY) +shiftY ,scaleZ*(j) + shiftZ); // Top Right     
    271                 model->addNormal(normalVectorField[i%heightMap->h][j%heightMap->w].y,normalVectorField[i%heightMap->h][j%heightMap->w].z,normalVectorField[i%heightMap->h][j%heightMap->w].x);
    272                 model->addTexCoor((float)j /(texRate), (float)(i %heightMap->h)/(texRate));
    273                 model->addColor(r/255.0,g/255.0,b/255.0);
    274            
    275             }
    276            
    277 
    278        
    279        
    280         // link Boarder Stripe
    281             for(int j = j1-sampleRate  ; j < j2    ;  j += sampleRate)
    282             {
    283                
    284                 model->addIndice(cnt);
    285                 model->addIndice(cnt  + (j2 -j1 +  sampleRate  )/ sampleRate );
    286                 cnt++;
    287                
    288             }
    289                
    290                 cnt++;
    291                
    292                  model->newStripe();   
    293                
    294                
    295        
    296        
    297        
    298         cnt += (j2-j1)/ sampleRate;
    299        
    300         // link 2nd BoarderStripe
    301             for(int j = j1-sampleRate  ; j < j2    ;  j += sampleRate)
    302             {
    303                
    304                 model->addIndice(cnt);
    305                 model->addIndice(cnt  + (j2 -j1 +  sampleRate  )/ sampleRate );
    306                 cnt++;
    307                
    308             }
    309          
    310            
    311             SDL_UnlockSurface(hm->colourMap);
    312        
    313         model->finalize();
    314          
    315          
    316          
    317          
    318         #undef heightMap
    319         #undef colours   
    320         #undef scaleX
    321         #undef scaleY
    322         #undef scaleZ
    323         #undef shiftX
    324         #undef shiftY
    325         #undef shiftZ
    326         #undef normalVectorField
    327          
     117
     118        SDL_LockSurface(heightMap);
     119        SDL_LockSurface(hm->colourMap);
     120
     121        for(int i = i1 ; i <= i2  ; i +=sampleRate)
     122        {
     123                int w = 0;
     124
     125
     126
     127                if(hm->hasColourMap)
     128                {
     129                r = colours[(3*w+2 + 3*i*(heightMap->w )) ];
     130                g = colours[(3*w+1 + 3*i*(heightMap->w)) ];
     131                b = colours[(3*w+0 + 3*i*(heightMap->w))];
     132                }
     133
     134                w = j1;
     135                model->addVertex(scaleX*(heightMap->h -i)+ shiftX,shiftY,scaleZ*(w)+ shiftZ); // Top Right
     136                model->addNormal(normalVectorField[i % heightMap->h][w % heightMap->w].y,normalVectorField[i % heightMap->h][w % heightMap->w].z,normalVectorField[i % heightMap->h][w % heightMap->w].x);
     137                model->addTexCoor((float)(j1-sampleRate) /(texRate), (float)(i %heightMap->h)/(texRate));
     138
     139                model->addColor(r/255.0,g/255.0,b/255.0);
     140
     141            for(int j = j1  ; j <= j2    ;  j += sampleRate)
     142            {
     143
     144
     145                // To be fixed
     146                if(hm->hasColourMap)
     147                {
     148                r = colours[(3*j+2 + 3*i*(heightMap->w )) ];
     149                g =  colours[(3*j+1 + 3*i*(heightMap->w)) ];
     150                b =  colours[(3*j+0 + 3*i*(heightMap->w))];
     151                }
     152                height = (float)(unsigned char) hm->heights[(j +sampleRate+ i*(heightMap->w )) ];
     153                height += (float)(unsigned char) hm->heights[(j+ 1 + sampleRate + (i+1)*(heightMap->w )) ];
     154                height +=  (float) (unsigned char) hm->heights[(j -1+ sampleRate   + (i+1)*(heightMap->w ))];
     155                height +=  (float)(unsigned char)hm->heights[(j +sampleRate+ (i+2)*(heightMap->w )) ];
     156                height +=  (float)(unsigned char)hm->heights[(j+sampleRate + (i)*(heightMap->w )) ];
     157                height=height/5.0;
     158
     159                model->addVertex(scaleX*(heightMap->h -i) + shiftX ,((double)(height)*scaleY) + shiftY ,scaleZ*(j) + shiftZ); // Top Right
     160                model->addNormal(normalVectorField[i % heightMap->h][j % heightMap->w].y,normalVectorField[i % heightMap->h][j % heightMap->w].z,normalVectorField[i % heightMap->h][j % heightMap->w].x);
     161                model->addTexCoor((float)(j) /(texRate), (float)(i %heightMap->h)/(texRate));
     162
     163                //PRINTF(0)("TexCoord:  %f %f \n",(float)j / 100.0, (float)(i %heightMap->h)/100.0);
     164
     165                model->addColor(r/255.0,g/255.0,b/255.0);
     166                w = j;
     167            }
     168
     169
     170                model->addVertex(scaleX*(heightMap->h -i)+ shiftX,shiftY,scaleZ*(w)+ shiftZ); // Top Right
     171                model->addNormal(normalVectorField[i % heightMap->h][w % heightMap->w].y,normalVectorField[i % heightMap->h][w % heightMap->w].z,normalVectorField[i% heightMap->h][w % heightMap->w].x);
     172                model->addTexCoor((float)(j2+sampleRate) /(texRate), (float)(i %heightMap->h)/(texRate));
     173                model->addColor(r/255.0,g/255.0,b/255.0);
     174
     175        }
     176
     177
     178
     179
     180
     181        SDL_UnlockSurface(heightMap);
     182        int cnt = 0;
     183        for(int i = i1   ; i < i2  ; i +=sampleRate)
     184        {
     185
     186            for(int j = j1-sampleRate  ; j < j2  + 2*sampleRate  ;  j += sampleRate)
     187            {
     188
     189                model->addIndice(cnt);
     190                model->addIndice(cnt  + (j2 -j1 + 3* sampleRate  )/ sampleRate );
     191                cnt++;
     192
     193            }
     194
     195
     196
     197                 model->newStripe();
     198
     199
     200        }
     201        cnt += (j2 -j1 + 3* sampleRate)/ sampleRate;
     202
     203                for(int j = j1 ; j <= j2    ;  j += sampleRate)
     204            {
     205                int i = i1;
     206
     207                // To be fixed
     208                if(hm->hasColourMap)
     209                {
     210                r = (float)colours[(3*j+2 + 3*i*(heightMap->w )) ];
     211                g = (float)colours[(3*j+1 + 3*i*(heightMap->w)) ];
     212                b = (float)colours[(3*j+0 + 3*i*(heightMap->w))];
     213                }
     214
     215                model->addVertex(scaleX*(heightMap->h -i) + shiftX , shiftY ,scaleZ*(j) + shiftZ); // Top Right
     216                model->addNormal(normalVectorField[i % heightMap->h][j % heightMap->w].y,normalVectorField[i % heightMap->h][j % heightMap->w].z,normalVectorField[i % heightMap->h][j % heightMap->w].x);
     217                model->addTexCoor((float)j /(texRate), (float)((i - sampleRate) %heightMap->h)/(texRate));
     218                model->addColor(r/255.0,g/255.0,b/255.0);
     219
     220            }
     221
     222                for(int j = j1  ; j <= j2    ;  j += sampleRate)
     223            {
     224                int i = i1;
     225                height = (float)(unsigned char) hm->heights[(j +sampleRate+ i*(heightMap->w )) ];
     226                height += (float)(unsigned char) hm->heights[(j+ 1 + sampleRate + (i+1)*(heightMap->w )) ];
     227                height +=  (float) (unsigned char) hm->heights[(j -1+ sampleRate   + (i+1)*(heightMap->w ))];
     228                height +=  (float)(unsigned char)hm->heights[(j +sampleRate+ (i+2)*(heightMap->w )) ];
     229                height +=  (float)(unsigned char)hm->heights[(j+sampleRate + (i)*(heightMap->w )) ];
     230                height=height/5.0;
     231
     232                model->addVertex(scaleX*(heightMap->h -i) + shiftX , ((double)(height)*scaleY) +shiftY ,scaleZ*(j) + shiftZ); // Top Right
     233                model->addNormal(normalVectorField[i % heightMap->h][j % heightMap->w].y,normalVectorField[i % heightMap->h][j% heightMap->w].z,normalVectorField[i%heightMap->h][j%heightMap->w].x);
     234                model->addTexCoor((float)j /(texRate), (float)(i %heightMap->h)/(texRate));
     235                model->addColor(r/255.0,g/255.0,b/255.0);
     236
     237            }
     238
     239
     240
     241            for(int j = j1  ; j <= j2    ;  j += sampleRate)
     242            {
     243                int i = i2;
     244
     245                // To be fixed
     246                if(hm->hasColourMap)
     247                {
     248                r = (float)colours[3*j+2 + 3*i*(heightMap->w )];
     249                g = (float)colours[3*j+1 + 3*i*(heightMap->w)];
     250                b = (float)colours[3*j+0 + 3*i*(heightMap->w)];
     251                }
     252
     253                model->addVertex(scaleX*(heightMap->h -i) + shiftX , shiftY ,scaleZ*(j) + shiftZ); // Top Right
     254                model->addNormal(normalVectorField[i%heightMap->h][j%heightMap->w].y,normalVectorField[i%heightMap->h][j%heightMap->w].z,normalVectorField[i%heightMap->h][j%heightMap->w].x);
     255                model->addTexCoor((float)j /(texRate), (float)((i+ sampleRate) %heightMap->h)/(texRate));
     256                model->addColor(r/255.0,g/255.0,b/255.0);
     257
     258            }
     259
     260
     261            for(int j = j1 ; j <= j2    ;  j += sampleRate)
     262            {
     263                int i = i2;
     264                height = (float)(unsigned char) hm->heights[(j +sampleRate+ i*(heightMap->w )) ];
     265                height += (float)(unsigned char) hm->heights[(j+ 1 + sampleRate + (i+1)*(heightMap->w )) ];
     266                height +=  (float) (unsigned char) hm->heights[(j -1+ sampleRate   + (i+1)*(heightMap->w ))];
     267                height +=  (float)(unsigned char)hm->heights[(j +sampleRate+ (i+2)*(heightMap->w ))];
     268                height +=  (float)(unsigned char)hm->heights[(j+sampleRate + (i)*(heightMap->w )) ];
     269                height=height/5.0;
     270                model->addVertex(scaleX*(heightMap->h -i) + shiftX , ((double)(height)*scaleY) +shiftY ,scaleZ*(j) + shiftZ); // Top Right
     271                model->addNormal(normalVectorField[i%heightMap->h][j%heightMap->w].y,normalVectorField[i%heightMap->h][j%heightMap->w].z,normalVectorField[i%heightMap->h][j%heightMap->w].x);
     272                model->addTexCoor((float)j /(texRate), (float)(i %heightMap->h)/(texRate));
     273                model->addColor(r/255.0,g/255.0,b/255.0);
     274
     275            }
     276
     277
     278
     279
     280        // link Boarder Stripe
     281            for(int j = j1-sampleRate  ; j < j2    ;  j += sampleRate)
     282            {
     283
     284                model->addIndice(cnt);
     285                model->addIndice(cnt  + (j2 -j1 +  sampleRate  )/ sampleRate );
     286                cnt++;
     287
     288            }
     289
     290                cnt++;
     291
     292                 model->newStripe();
     293
     294
     295
     296
     297
     298        cnt += (j2-j1)/ sampleRate;
     299
     300        // link 2nd BoarderStripe
     301            for(int j = j1-sampleRate  ; j < j2    ;  j += sampleRate)
     302            {
     303
     304                model->addIndice(cnt);
     305                model->addIndice(cnt  + (j2 -j1 +  sampleRate  )/ sampleRate );
     306                cnt++;
     307
     308            }
     309
     310
     311            SDL_UnlockSurface(hm->colourMap);
     312
     313        model->finalize();
     314
     315
     316
     317
     318        #undef heightMap
     319        #undef colours
     320        #undef scaleX
     321        #undef scaleY
     322        #undef scaleZ
     323        #undef shiftX
     324        #undef shiftY
     325        #undef shiftZ
     326        #undef normalVectorField
     327
    328328}
    329329
     
    339339   if(heightMap!=NULL) {
    340340
    341                 PRINTF(0)("loading Image %s\n", height_map_name);
    342                 PRINTF(0)("width : %i\n", heightMap->w);
    343                 PRINTF(0)("height : %i\n", heightMap->h);
    344                 PRINTF(0)("%i Byte(s) per Pixel \n", heightMap->format->BytesPerPixel);
    345                 PRINTF(0)("Rshift : %i\n", heightMap->format->Rshift);
    346                 PRINTF(0)("Bshift: %i\n", heightMap->format->Bshift);
    347                 PRINTF(0)("Gshift: %i\n", heightMap->format->Gshift);
    348                 PRINTF(0)("Rmask: %i\n", heightMap->format->Rmask);
    349                 PRINTF(0)("Gmask: %i\n", heightMap->format->Gmask);
    350                 }
     341                PRINTF(0)("loading Image %s\n", height_map_name);
     342                PRINTF(0)("width : %i\n", heightMap->w);
     343                PRINTF(0)("height : %i\n", heightMap->h);
     344                PRINTF(0)("%i Byte(s) per Pixel \n", heightMap->format->BytesPerPixel);
     345                PRINTF(0)("Rshift : %i\n", heightMap->format->Rshift);
     346                PRINTF(0)("Bshift: %i\n", heightMap->format->Bshift);
     347                PRINTF(0)("Gshift: %i\n", heightMap->format->Gshift);
     348                PRINTF(0)("Rmask: %i\n", heightMap->format->Rmask);
     349                PRINTF(0)("Gmask: %i\n", heightMap->format->Gmask);
     350                }
    351351
    352352     else       PRINTF(4)("oops! couldn't load %s for some reason.\n", height_map_name);
    353353
    354        
     354
    355355  generateNormalVectorField();
    356356
     
    368368   if(heightMap!=NULL) {
    369369
    370                 PRINTF(0)("loading Image %s\n", height_map_name);
    371                 PRINTF(0)("width : %i\n", heightMap->w);
    372                 PRINTF(0)("height : %i\n", heightMap->h);
    373                 PRINTF(0)("%i Byte(s) per Pixel \n", heightMap->format->BytesPerPixel);
    374                 PRINTF(0)("Rshift : %i\n", heightMap->format->Rshift);
    375                 PRINTF(0)("Bshift: %i\n", heightMap->format->Bshift);
    376                 PRINTF(0)("Gshift: %i\n", heightMap->format->Gshift);
    377                 PRINTF(0)("Rmask: %i\n", heightMap->format->Rmask);
    378                 PRINTF(0)("Gmask: %i\n", heightMap->format->Gmask);
    379                 }
     370                PRINTF(0)("loading Image %s\n", height_map_name);
     371                PRINTF(0)("width : %i\n", heightMap->w);
     372                PRINTF(0)("height : %i\n", heightMap->h);
     373                PRINTF(0)("%i Byte(s) per Pixel \n", heightMap->format->BytesPerPixel);
     374                PRINTF(0)("Rshift : %i\n", heightMap->format->Rshift);
     375                PRINTF(0)("Bshift: %i\n", heightMap->format->Bshift);
     376                PRINTF(0)("Gshift: %i\n", heightMap->format->Gshift);
     377                PRINTF(0)("Rmask: %i\n", heightMap->format->Rmask);
     378                PRINTF(0)("Gmask: %i\n", heightMap->format->Gmask);
     379                }
    380380
    381381     else       PRINTF(4)("oops! couldn't load %s for some reason.\n", height_map_name);
     
    389389  colourMap = IMG_Load(colour_map_name);
    390390  }
    391  
     391
    392392  if(colourMap != NULL)
    393                 {
    394                 PRINTF(0)("loading Image %s\n", colour_map_name);
    395                 PRINTF(0)("width : %i\n", colourMap->w);
    396                 PRINTF(0)("height : %i\n", colourMap->h);
    397                 PRINTF(0)("%i Byte(s) per Pixel \n", colourMap->format->BytesPerPixel);
    398                 PRINTF(0)("Rshift : %i\n", colourMap->format->Rshift);
    399                 PRINTF(0)("Bshift: %i\n", colourMap->format->Bshift);
    400                 PRINTF(0)("Gshift: %i\n", colourMap->format->Gshift);
    401                 PRINTF(0)("Rmask: %i\n", colourMap->format->Rmask);
    402                 PRINTF(0)("Gmask: %i\n", colourMap->format->Gmask);
    403                 }
    404                 else       PRINTF(0)("oops! couldn't load colorMap for some reason.\n");
    405 
    406                  
    407                    
     393                {
     394                PRINTF(0)("loading Image %s\n", colour_map_name);
     395                PRINTF(0)("width : %i\n", colourMap->w);
     396                PRINTF(0)("height : %i\n", colourMap->h);
     397                PRINTF(0)("%i Byte(s) per Pixel \n", colourMap->format->BytesPerPixel);
     398                PRINTF(0)("Rshift : %i\n", colourMap->format->Rshift);
     399                PRINTF(0)("Bshift: %i\n", colourMap->format->Bshift);
     400                PRINTF(0)("Gshift: %i\n", colourMap->format->Gshift);
     401                PRINTF(0)("Rmask: %i\n", colourMap->format->Rmask);
     402                PRINTF(0)("Gmask: %i\n", colourMap->format->Gmask);
     403                }
     404                else       PRINTF(0)("oops! couldn't load colorMap for some reason.\n");
     405
     406
     407
    408408  if(colourMap != NULL)
    409409  {
     
    412412  }
    413413  else hasColourMap = false;
    414  
    415        
     414
     415
    416416  heights  = (unsigned char*) heightMap->pixels;
    417417  shiftX = 0;
     
    423423HeightMap::~HeightMap()
    424424{
    425         delete heightMap;
    426         delete colourMap;
    427        
    428 
    429         for(int i=0;i <    heightMap->h/tileSize ; i++)
    430         {
    431         for(int j = 0; j < heightMap->w/ tileSize; j++)
    432         {
    433         delete tiles [i][j];
    434         }
    435         }
    436         for(int i=0;i <    heightMap->h/tileSize ; i++)
    437         delete[] tiles[i];
    438         delete[] tiles;
    439        
    440        
    441        
     425        delete heightMap;
     426        delete colourMap;
     427
     428
     429        for(int i=0;i <    heightMap->h/tileSize ; i++)
     430        {
     431        for(int j = 0; j < heightMap->w/ tileSize; j++)
     432        {
     433        delete tiles [i][j];
     434        }
     435        }
     436        for(int i=0;i <    heightMap->h/tileSize ; i++)
     437        delete[] tiles[i];
     438        delete[] tiles;
     439
     440
     441
    442442
    443443
     
    449449
    450450
    451        
    452        
    453        
     451
     452
     453
    454454}
    455455
     
    465465for(int i = 0; i < (heightMap->h  )/ tileSize; i ++)
    466466{
    467         for(int j = 0; j < (heightMap->w )/ tileSize; j ++)
    468         {
    469          
    470         tiles[i][j] =    new Tile( i*tileSize ,  j*tileSize , (i+1)*tileSize, (j+1)*tileSize , this ) ;
    471         }
    472 }
    473 
    474 }
    475 
    476 
    477 void HeightMap::draw() 
    478 {
    479 const PNode* camera = State::getCamera();
     467        for(int j = 0; j < (heightMap->w )/ tileSize; j ++)
     468        {
     469
     470        tiles[i][j] =    new Tile( i*tileSize ,  j*tileSize , (i+1)*tileSize, (j+1)*tileSize , this ) ;
     471        }
     472}
     473
     474}
     475
     476
     477void HeightMap::draw()
     478{
     479const PNode* camera = State::getCameraNode();
    480480Vector v = camera->getAbsCoor();
    481481
     
    487487
    488488
    489 for(int i = 0; i <  i_max        ; i ++)
    490 {
    491         for(int j = 0; j < j_max ; j++)
    492         {
    493         tiles[i][j]->draw();
    494         }       
    495 } 
     489for(int i = 0; i <  i_max        ; i ++)
     490{
     491        for(int j = 0; j < j_max ; j++)
     492        {
     493        tiles[i][j]->draw();
     494        }
     495}
    496496
    497497}
     
    509509
    510510
    511 // Initialize 
     511// Initialize
    512512for(int i=0; i< heightMap->h; i++)
    513513{
    514         for(int j = 0; j> heightMap->w; j++)
    515         {
    516         Vector v = Vector(0.0, 1.0, 0.0);
    517         normalVectorField[i][j] = v;
    518         }
     514        for(int j = 0; j> heightMap->w; j++)
     515        {
     516        Vector v = Vector(0.0, 1.0, 0.0);
     517        normalVectorField[i][j] = v;
     518        }
    519519}
    520520
     
    522522
    523523if(heightMap != NULL && heightMap->format->BitsPerPixel == 8 )
    524         {
    525         SDL_LockSurface(heightMap);
    526         for(int i = 0 ; i < heightMap->h - 1  ; i ++)
    527         {
    528             for(int j = 0; j < heightMap->w  - 1  ;  j ++)
    529             {
    530 
    531 
    532                 delta = (int)heights[j + (i+1)*(heightMap->w )] -  (int) heights[j + i*(heightMap->w )];
    533                 Vector a =  Vector(-scaleX,(float)delta*scaleY  ,0.0f);
    534 
    535                 delta = (int)heights[j+1 + i*(heightMap->w )] - (int)heights[j + i*(heightMap->w )];
    536                 Vector b =  Vector(0.0f,(float) delta*scaleY ,scaleZ);
    537 
    538 
    539                 normalVectorField[i][j] = b.cross(a);
    540                 normalVectorField[i][j].normalize();
    541                  
    542              }
    543         }
    544         SDL_UnlockSurface(heightMap);
    545 
    546 }
    547 
    548        
     524        {
     525        SDL_LockSurface(heightMap);
     526        for(int i = 0 ; i < heightMap->h - 1  ; i ++)
     527        {
     528            for(int j = 0; j < heightMap->w  - 1  ;  j ++)
     529            {
     530
     531
     532                delta = (int)heights[j + (i+1)*(heightMap->w )] -  (int) heights[j + i*(heightMap->w )];
     533                Vector a =  Vector(-scaleX,(float)delta*scaleY  ,0.0f);
     534
     535                delta = (int)heights[j+1 + i*(heightMap->w )] - (int)heights[j + i*(heightMap->w )];
     536                Vector b =  Vector(0.0f,(float) delta*scaleY ,scaleZ);
     537
     538
     539                normalVectorField[i][j] = b.cross(a);
     540                normalVectorField[i][j].normalize();
     541
     542             }
     543        }
     544        SDL_UnlockSurface(heightMap);
     545
     546}
     547
     548
    549549
    550550
     
    568568
    569569
    570 float HeightMap::getHeight(float x, float y) 
     570float HeightMap::getHeight(float x, float y)
    571571{
    572572
    573573 x -= offsetX;
    574  y -= offsetZ; 
    575  
    576  
     574 y -= offsetZ;
     575
     576
    577577 int xInt = (int)x / scaleX;  x -= (float)((int)x); xInt = heightMap->h - xInt;
    578578 int yInt = (int)y / scaleZ;    y -= (float) ((int) y); /*yInt = heightMap->w - yInt;*/
    579  
     579
    580580 //PRINTF(0)("xInt: %i, yInt: %i, x: %f, y: %f\n", xInt, yInt, x, y);
    581  
     581
    582582 if(xInt <= 0 || xInt >= heightMap->h || yInt <= 0 || yInt >= heightMap->w  ) return 0;
    583583 if( y >= 0.5*x)
    584584 {
    585         // Check for ...
     585        // Check for ...
    586586 }
    587587
    588588 float height = heights[yInt + (xInt)*heightMap->w]*scaleY;
    589  
    590  
     589
     590
    591591 float a = normalVectorField[(xInt)][yInt].x;
    592592 float b = normalVectorField [(xInt)][yInt].z;
    593593 float c = normalVectorField [(xInt)][yInt].y;
    594  
     594
    595595 PRINTF(0)("a: %f \n" ,a);
    596596  PRINTF(0)("b: %f \n" ,b);
    597597   PRINTF(0)("c: %f \n" ,c);
    598  
     598
    599599 height -= ( (a/c)*(x) + (b/c)*(y));
    600  
     600
    601601 PRINTF(0)("height: %f \n" ,height );
    602602 return (height + offsetZ);
  • trunk/src/lib/particles/sprite_particles.cc

    r6846 r7014  
    135135    //! @todo implement a faster code for the look-at Camera algorithm.
    136136
    137     const PNode* camera = State::getCamera();  //!< @todo MUST be different
     137    const PNode* camera = State::getCameraNode();  //!< @todo MUST be different
    138138    Vector cameraPos = camera->getAbsCoor();
    139     Vector cameraTargetPos = State::getCameraTarget()->getAbsCoor();
     139    Vector cameraTargetPos = State::getCameraTargetNode()->getAbsCoor();
    140140    Vector view = cameraTargetPos - cameraPos;
    141141    Vector up = Vector(0, 1, 0);
  • trunk/src/story_entities/multi_player_world_data.cc

    r6986 r7014  
    265265
    266266
    267   PNode* cam = State::getCameraTarget();
     267  PNode* cam = State::getCameraTargetNode();
    268268  PRINT(0)("Camera has target - class: %s, name: %s, uid: %i\n", cam->getClassName(), cam->getName(), cam->getUniqueID());
    269269
  • trunk/src/util/state.cc

    r6874 r7014  
    1818#include "state.h"
    1919
     20
     21#include "camera.h"
     22
    2023#ifndef NULL
    2124#define NULL 0
     
    2629
    2730
    28 PNode* State::camera = NULL;
    29 PNode* State::cameraTarget = NULL;
     31Camera* State::camera = NULL;
     32CameraTarget* State::cameraTarget = NULL;
     33
     34PNode* State::cameraNode = NULL;
     35PNode* State::cameraTargetNode = NULL;
    3036
    3137SkyBox* State::skyBox = NULL;
     
    4955 *  sets camera and target of the current Camera
    5056*/
    51 void State::setCamera(PNode* camera, PNode* cameraTarget)
     57void State::setCamera(Camera* camera, CameraTarget* cameraTarget)
    5258{
    5359  State::camera = camera;
    5460  State::cameraTarget = cameraTarget;
     61  State::cameraNode = camera;
     62  State::cameraTargetNode = cameraTarget;
    5563}
  • trunk/src/util/state.h

    r6874 r7014  
    1010// FORWARD DECLARATION
    1111class PNode;
     12class Camera;
     13class CameraTarget;
    1214class WorldEntity;
    1315class Player;
     
    3032   //////////////
    3133  /** @param camera the PNode to the Camera, @param cameraTarget the PNode to the Camera's target */
    32   static void setCamera(PNode* camera, PNode* cameraTarget);
     34  static void setCamera(Camera* camera, CameraTarget* cameraTarget);
     35  static inline Camera* getCamera() { return State::camera; };
     36  static inline CameraTarget* getCameraTarget() { return State::cameraTarget; };
    3337  /** @returns a Pointer to the PNode of the Camera */
    34   static inline PNode* getCamera() { return State::camera; };
     38  static inline PNode* getCameraNode() { return State::cameraNode; };
    3539  /** @returns a Pointer to the CameraTarget */
    36   static inline PNode* getCameraTarget() { return State::cameraTarget; };
     40  static inline PNode* getCameraTargetNode() { return State::cameraTargetNode; };
    3741
    3842  ////////////////
     
    9599  State();
    96100
    97   static PNode*                 camera;             //!< A reference to the camera
    98   static PNode*                 cameraTarget;       //!< A reference to the cameraTarget
     101  static Camera*                camera;             //!< The current Camera.
     102  static CameraTarget*          cameraTarget;       //!< The Camera Target.
     103  static PNode*                 cameraNode;         //!< A reference to the camera
     104  static PNode*                 cameraTargetNode;   //!< A reference to the cameraTarget
    99105  static PNode*                 nullParent;         //!< A reference to the Null-PNode.
    100106  static ObjectManager*         objectManager;      //!< A reference to the current ObjectManager
  • trunk/src/world_entities/camera.cc

    r7013 r7014  
    6565 * @returns The PNode of the Target (from there you can get position and so on
    6666*/
    67 PNode* Camera::getTarget()
     67PNode* Camera::getTargetNode() const
    6868{
    6969  return (PNode*)this->target;
     
    146146{
    147147  //update frustum plane
    148   this->viewVector = (this->getAbsCoor() -  this->target->getAbsCoor()).getNormalized();
    149   this->frustumPlane = Plane(this->viewVector, this->getAbsCoor() + this->viewVector * 3.0);
     148  this->viewVector = (this->target->getAbsCoor() - this->getAbsCoor()).getNormalized();
     149  this->frustumPlane = Plane(this->viewVector, this->getAbsCoor() + this->viewVector * 0.1);
    150150
    151151  this->upVector =  this->getAbsDirV();
  • trunk/src/world_entities/camera.h

    r7013 r7014  
    3737
    3838  void lookAt(PNode* target);
    39   PNode* getTarget();
     39  CameraTarget* getTarget() const { return this->target; };
     40  PNode* getTargetNode() const;
    4041
    4142  void setAspectRatio(float aspectRatio);
  • trunk/src/world_entities/creatures/md2_creature.cc

    r6990 r7014  
    119119  this->cameraConnNode.setName("CameraConnectorNode");
    120120  this->addChild(&this->cameraConnNode);
    121   this->cameraConnNode.addChild(State::getCameraTarget());
    122   this->cameraConnNode.addChild(State::getCamera());
    123   State::getCameraTarget()->setRelCoor(10,0,0);
     121  this->cameraConnNode.addChild(State::getCameraTargetNode());
     122  this->cameraConnNode.addChild(State::getCameraNode());
     123  State::getCameraTargetNode()->setRelCoor(10,0,0);
    124124
    125125  travelSpeed = 15.0;
  • trunk/src/world_entities/playable.cc

    r7010 r7014  
    285285void  Playable::attachCamera()
    286286{
    287   State::getCamera()->setParentSoft(this);
    288   State::getCameraTarget()->setParentSoft(this);
     287  State::getCameraNode()->setParentSoft(this);
     288  State::getCameraTargetNode()->setParentSoft(this);
    289289
    290290}
  • trunk/src/world_entities/space_ships/helicopter.cc

    r6997 r7014  
    203203{
    204204  dynamic_cast<Element2D*>(this->getWeaponManager()->getFixedTarget())->setVisibility( true);
    205   State::getCamera()->setParentSoft(this->getWeaponManager()->getFixedTarget());
    206   State::getCameraTarget()->setParentSoft(this->getWeaponManager()->getFixedTarget());
     205  State::getCameraNode()->setParentSoft(this->getWeaponManager()->getFixedTarget());
     206  State::getCameraTargetNode()->setParentSoft(this->getWeaponManager()->getFixedTarget());
    207207}
    208208
  • trunk/src/world_entities/space_ships/hover.cc

    r6999 r7014  
    192192  dynamic_cast<Element2D*>(this->getWeaponManager()->getFixedTarget())->setVisibility( true);
    193193
    194   State::getCamera()->setParentSoft(&this->cameraNode);
    195   State::getCamera()->setRelCoorSoft(-10, 0,0);
    196   State::getCameraTarget()->setParentSoft(&this->cameraNode);
     194  State::getCameraNode()->setParentSoft(&this->cameraNode);
     195  State::getCameraNode()->setRelCoorSoft(-10, 0,0);
     196  State::getCameraTargetNode()->setParentSoft(&this->cameraNode);
    197197}
    198198
  • trunk/src/world_entities/space_ships/turbine_hover.cc

    r7004 r7014  
    222222  dynamic_cast<Element2D*>(this->getWeaponManager()->getFixedTarget())->setVisibility( true);
    223223
    224   State::getCamera()->setParentSoft(&this->cameraNode);
    225   State::getCamera()->setRelCoorSoft(-10, 0,0);
    226   State::getCameraTarget()->setParentSoft(&this->cameraNode);
     224  State::getCameraNode()->setParentSoft(&this->cameraNode);
     225  State::getCameraNode()->setRelCoorSoft(-10, 0,0);
     226  State::getCameraTargetNode()->setParentSoft(&this->cameraNode);
    227227}
    228228
  • trunk/src/world_entities/terrain.cc

    r6956 r7014  
    241241glPushMatrix();
    242242glLoadIdentity();
    243  Vector camera =   State::getCamera()->getAbsCoor(); // Go on here ..........!!!
     243 Vector camera =   State::getCameraNode()->getAbsCoor(); // Go on here ..........!!!
    244244
    245245    /*
  • trunk/src/world_entities/world_entity.cc

    r6959 r7014  
    3030
    3131#include "state.h"
     32#include "camera.h"
    3233
    3334using namespace std;
     
    319320
    320321    // This Draws the LOD's
    321     float cameraDistance = (State::getCamera()->getAbsCoor() - this->getAbsCoor()).len();
     322    float cameraDistance = State::getCamera()->distance(this);
     323    printf("%s::%s, distance %f\n", this->getClassName(), this->getName(), cameraDistance);
    322324    if (cameraDistance > 30 && this->models.size() >= 3 && this->models[2] != NULL)
    323325    {
Note: See TracChangeset for help on using the changeset viewer.