Changeset 8745 in orxonox.OLD for branches/terrain
- Timestamp:
- Jun 23, 2006, 4:26:49 PM (18 years ago)
- Location:
- branches/terrain/src/lib/graphics/importer/terrain
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/terrain/src/lib/graphics/importer/terrain/terrain.cc
r8744 r8745 33 33 pagesZ = (heightfield.height/(pageSize-1) ); 34 34 35 //TODO: Determine layer visibility!36 for ( unsigned int i = 0; i < layers.size(); ++i ) {37 38 }39 35 40 36 pages = new pTerrainPage[pagesX*pagesZ]; … … 52 48 53 49 root = createQuadTree( 0, 0, pagesX, pagesZ ); 50 51 for ( unsigned int i = 0; i < layers.size(); ++i ) { 52 determineLayerVisibility( i ); 53 } 54 54 activePages = NULL; 55 55 } … … 321 321 } 322 322 323 323 inline Uint8 getAlpha( const SDL_Surface *_s, int _x, int _y ) 324 { 325 printf( "getalpha: %d, %d\n", _x, _y ); 326 int bpp = _s->format->BytesPerPixel; 327 Uint8 *p = (Uint8 *)_s->pixels + _y*_s->pitch + _x * bpp; 328 Uint32 pixel = 0; 329 switch( bpp ) { 330 case 1: 331 pixel = *p; 332 break; 333 case 2: 334 pixel = *(Uint16 *)p; 335 break; 336 case 3: 337 if(SDL_BYTEORDER == SDL_BIG_ENDIAN) 338 pixel = p[0] << 16 | p[1] << 8 | p[2]; 339 else 340 pixel = p[0] | p[1] << 8 | p[2] << 16; 341 break; 342 case 4: 343 pixel = *(Uint32 *)p; 344 break; 345 default: 346 return 0; /* shouldn't happen, but avoids warnings */ 347 } 348 Uint8 r,g,b,a; 349 SDL_GetRGBA( pixel, _s->format, &r, &g, &b, &a ); 350 return a; 351 } 352 353 void Terrain::determineLayerVisibility( int _layer ) 354 { 355 LayerInfo * layer = layers[_layer]; 356 if ( !layer->alpha ) { 357 int numPages = pagesX*pagesZ; 358 for ( int i = 0; i < numPages; ++i ) 359 pages[i]->setLayerVisibility( _layer, LV_FULL ); 360 361 return; 362 } 363 SDL_Surface *alpha = const_cast<SDL_Surface*>( layer->alpha->getStoredImage() ); 364 SDL_LockSurface( alpha ); 365 float du = ( (float)alpha->w)/pagesX; 366 float dv = ( (float)alpha->h)/pagesZ; 367 float u = 0.0f, v = 0.0f; 368 for ( int pageX = 0; pageX < pagesX; ++pageX ) { 369 v = 0.0f; 370 for ( int pageZ = 0; pageZ < pagesZ; ++pageZ ) { 371 bool full = true; bool has = false; 372 for ( int x = 0; x < (int)PAGE_SIZE; ++x ) { 373 for ( int z = 0; z < (int)PAGE_SIZE; ++z ) { 374 Uint8 a = getAlpha( alpha, (int)u, (int)v ); 375 if ( a ) 376 has = true; 377 if ( a < 250 ) 378 full = false; 379 } 380 } 381 LayerVisibility lv; 382 if ( has ) { 383 if ( full ) 384 lv = LV_FULL; 385 else 386 lv = LV_PARTIAL; 387 } 388 else { 389 lv = LV_NO; 390 } 391 getPage( pageX, pageZ )->setLayerVisibility( _layer, lv ); 392 v+= dv; 393 } 394 u+= du; 395 } 396 SDL_UnlockSurface( alpha ); 397 } 324 398 325 399 void Terrain::getAltitude( Triple& _alt, Triple& _normal ) -
branches/terrain/src/lib/graphics/importer/terrain/terrain.h
r8744 r8745 33 33 typedef Terrain *pTerrain; 34 34 35 struct Heightfield {36 int width;37 int height;38 int pitch;39 UByte *data;40 };41 42 struct LayerInfo {43 44 int envmode;45 float repeatX,46 repeatZ;47 Texture *alpha;48 Texture *detail;49 50 };51 52 struct BufferInfo {53 54 BufferInfo( unsigned int _vb, unsigned int _ib,55 unsigned int _numV, unsigned int _numI )56 {57 vbIdentifier = _vb; ibIdentifier = _ib;58 numIndices = _numI; numVertices =_numV;59 60 }61 62 BufferInfo()63 {64 vbIdentifier = ibIdentifier = numIndices = numVertices = 0;65 }66 unsigned int vbIdentifier,67 ibIdentifier,68 numIndices,69 numVertices;70 };71 72 73 35 class Terrain { 74 36 public: 75 const static int PAGE_SIZE= 17;76 const static int MAX_VERTICES = PAGE_SIZE*PAGE_SIZE;77 const static int MAX_INDICES = 2*( PAGE_SIZE*PAGE_SIZE + PAGE_SIZE -2 );37 const static unsigned int PAGE_SIZE = 17; 38 const static unsigned int MAX_VERTICES = PAGE_SIZE*PAGE_SIZE; 39 const static unsigned int MAX_INDICES = 2*( PAGE_SIZE*PAGE_SIZE + PAGE_SIZE -2 ); 78 40 /** 79 41 * The amount of geometry rendered is largely depending on this constant. So chose a … … 209 171 * frustum of the camera. 210 172 */ 211 void determineVisiblePages( pTerrainQuad _node ); 173 void determineVisiblePages( pTerrainQuad _node ); 174 void determineLayerVisibility( int _layer ); 212 175 213 176 #ifdef USE_VBO -
branches/terrain/src/lib/graphics/importer/terrain/terrain_page.cc
r8744 r8745 40 40 previous = NULL; 41 41 currentLOD = -1; 42 hasfull = false; 42 43 forceTesselation = true; 43 44 vbIdentifier = 0; ibIdentifier = 0; … … 773 774 _vertex.z = position.z+scale.z*_z/( owner->getPageSize()-1 ); 774 775 } 775 776 void TerrainPage::setLayerVisibility( int _layer, LayerVisibility _lv ) 777 { 778 if ( hasfull ) return; 779 if ( _lv == LV_FULL ) { 780 for ( int i = 0; i < 8; ++i ) 781 layerVisibility[i] = LV_NO; 782 if ( _layer ) 783 hasfull = true; 784 } 785 printf( "setting layer %d vis to %d\n", _lv ); 786 layerVisibility[_layer] = _lv; 787 } 788 789 bool TerrainPage::hasMaterial( int _layer ) 790 { 791 return ( layerVisibility[_layer] != LV_NO ); 792 } 776 793 void TerrainPage::calculateErrors() 777 794 { -
branches/terrain/src/lib/graphics/importer/terrain/terrain_page.h
r8741 r8745 24 24 class TerrainPage; 25 25 class Terrain; 26 27 26 typedef TerrainPage *pTerrainPage; 28 27 … … 185 184 */ 186 185 inline pTerrainPage getNext() { return next; } 187 186 void setLayerVisibility( int _layer, LayerVisibility _lv ); 187 bool hasMaterial( int _layer ); 188 188 /** 189 189 * Returns the previous active page … … 206 206 */ 207 207 void activate(); 208 inline bool hasMaterial( int _i ) 209 { 210 return true; 211 } 208 212 209 inline void setWantedLOD( int _lod ) 213 210 { … … 286 283 int numIndices; 287 284 int numVertices; 288 285 LayerVisibility layerVisibility[8]; 286 bool hasfull; 289 287 #ifdef USE_VBO 290 288 GLuint ibIdentifier, -
branches/terrain/src/lib/graphics/importer/terrain/types.h
r8697 r8745 20 20 #endif 21 21 #include <math.h> 22 22 #include "texture.h" 23 23 24 24 struct Triple { … … 139 139 } 140 140 typedef unsigned char UByte; 141 struct Heightfield { 142 int width; 143 int height; 144 int pitch; 145 UByte *data; 146 }; 147 148 struct LayerInfo { 149 150 int envmode; 151 float repeatX, 152 repeatZ; 153 Texture *alpha; 154 Texture *detail; 155 156 }; 157 typedef enum { LV_FULL, LV_PARTIAL, LV_NO } LayerVisibility; 158 159 struct BufferInfo { 160 161 BufferInfo( unsigned int _vb, unsigned int _ib, 162 unsigned int _numV, unsigned int _numI ) 163 { 164 vbIdentifier = _vb; ibIdentifier = _ib; 165 numIndices = _numI; numVertices =_numV; 166 167 } 168 169 BufferInfo() 170 { 171 vbIdentifier = ibIdentifier = numIndices = numVertices = 0; 172 } 173 unsigned int vbIdentifier, 174 ibIdentifier, 175 numIndices, 176 numVertices; 177 }; 141 178 #endif
Note: See TracChangeset
for help on using the changeset viewer.