Changeset 9071 in orxonox.OLD for branches/terrain/src/lib
- Timestamp:
- Jul 3, 2006, 10:23:35 PM (18 years ago)
- Location:
- branches/terrain/src/lib/graphics/importer/terrain
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/terrain/src/lib/graphics/importer/terrain/frustum.h
r8775 r9071 20 20 21 21 22 #define MAX_CLIP_DISTANCE 400.0f23 #define m( _ row,_col ) _m[_col*4+_row-5]22 #define MAX_CLIP_DISTANCE 800.0f 23 #define m( _col, _row ) _m[_row*4+_col] 24 24 25 25 #define CHECK_GL_ERROR( _d ) do { \ … … 93 93 inline void setFrustum( float *_m ) 94 94 { 95 planes[NEAR].setCoefficients( 96 m( 3, 1 ) + m( 4, 1 ), 97 m( 3, 2 ) + m( 4, 2 ), 98 m( 3, 3 ) + m( 4, 3 ), 99 m( 3, 4 ) + m( 4, 4 ) ); 100 101 planes[FAR].setCoefficients( 102 -m( 3, 1 ) + m( 4, 1 ), 103 -m( 3, 2 ) + m( 4, 2 ), 104 -m( 3, 3 ) + m( 4, 3 ), 105 -m( 3, 4 ) + m( 4, 4 ) ); 106 107 planes[BOTTOM].setCoefficients( 108 m( 2, 1 ) + m( 4, 1 ), 109 m( 2, 2 ) + m( 4, 2 ), 110 m( 2, 3 ) + m( 4, 3 ), 111 m( 2, 4 ) + m( 4, 4 ) ); 112 113 planes[TOP].setCoefficients( 114 -m( 2, 1 ) + m( 4, 1 ), 115 -m( 2, 2 ) + m( 4, 2 ), 116 -m( 2, 3 ) + m( 4, 3 ), 117 -m( 2, 4 ) + m( 4, 4 ) ); 118 119 planes[LEFT].setCoefficients( 120 m( 1, 1 ) + m( 4, 1 ), 121 m( 1, 2 ) + m( 4, 2 ), 122 m( 1, 3 ) + m( 4, 3 ), 123 m( 1, 4 ) + m( 4, 4 ) ); 124 125 planes[RIGHT].setCoefficients( 126 -m( 1, 1 ) + m( 4, 1 ), 127 -m( 1, 2 ) + m( 4, 2 ), 128 -m( 1, 3 ) + m( 4, 3 ), 129 -m( 1, 4 ) + m( 4, 4 ) ); 95 planes[NEAR].setCoefficients( m(2,0) + m(3,0), 96 m(2,1) + m(3,1), 97 m(2,2) + m(3,2), 98 m(2,3) + m(3,3)); 99 planes[FAR].setCoefficients( -m(2,0) + m(3,0), 100 -m(2,1) + m(3,1), 101 -m(2,2) + m(3,2), 102 -m(2,3) + m(3,3)); 103 planes[BOTTOM].setCoefficients( m(1,0) + m(3,0), 104 m(1,1) + m(3,1), 105 m(1,2) + m(3,2), 106 m(1,3) + m(3,3)); 107 planes[TOP].setCoefficients( -m(1,0) + m(3,0), 108 -m(1,1) + m(3,1), 109 -m(1,2) + m(3,2), 110 -m(1,3) + m(3,3)); 111 planes[LEFT].setCoefficients( m(0,0) + m(3,0), 112 m(0,1) + m(3,1), 113 m(0,2) + m(3,2), 114 m(0,3) + m(3,3)); 115 planes[RIGHT].setCoefficients(-m(0,0) + m(3,0), 116 -m(0,1) + m(3,1), 117 -m(0,2) + m(3,2), 118 -m(0,3) + m(3,3)); 130 119 131 120 if ( planes[NEAR].d +planes[FAR].d > MAX_CLIP_DISTANCE ) { -
branches/terrain/src/lib/graphics/importer/terrain/terrain.cc
r8965 r9071 28 28 SDL_Surface *tmpData = IMG_Load( full.c_str() ); 29 29 if ( !tmpData ) { 30 PRINT F(0)( "I' sorry, I can't load %s\n", full.c_str() );30 PRINT(0)( "I' sorry, I can't load %s\n", full.c_str() ); 31 31 return; 32 32 } 33 33 if ( !validateSize( tmpData->h ) || !validateSize( tmpData->w ) ) { 34 PRINT F(0)( "The size of the elevation map must be 2^n+1x2^m+1. and at least 17x17" );34 PRINT(0)( "The size of the elevation map must be 2^n+1x2^m+1. and at least 17x17" ); 35 35 return; 36 36 } 37 37 if ( tmpData->format->BytesPerPixel != 1 ) { 38 PRINTF(0)( "The elevetation map must be an 8bit image!" ); 38 PRINT(0)( "The elevetation map must be an 8bit image not %d", 39 tmpData->format->BytesPerPixel*8 ); 39 40 return; 40 41 } … … 148 149 switch( _node->cull() ) { 149 150 case Frustum::INTERSECT: 150 //printf( "partially inside frustum\n" );151 151 if ( !_node->isChildless() ) { 152 152 pTerrainQuad *children = _node->getChildren(); … … 160 160 break; 161 161 case Frustum::INSIDE: 162 //printf( "fully inside frustum\n" );163 162 showPages( _node->getXOffset(), 164 163 _node->getZOffset(), … … 167 166 break; 168 167 case Frustum::OUTSIDE: 169 cullCount+= (_node->getWidth()-1)*(_node->getHeight()-1);170 168 break; 171 169 } … … 249 247 //Due to some reason, the OpenGL implementors chose the plane equation 250 248 //to an array of doubles. So we will make them happy. 251 double farPlane[] = { far.n.x, far.n.y, far.n.z, far.d };252 glEnable( GL_CLIP_PLANE0 );253 glClipPlane( GL_CLIP_PLANE0, farPlane );249 //double farPlane[] = { far.n.x, far.n.y, far.n.z, far.d }; 250 //glEnable( GL_CLIP_PLANE0 ); 251 //glClipPlane( GL_CLIP_PLANE0, farPlane ); 254 252 glPushAttrib( GL_ALL_ATTRIB_BITS ); 255 253 glPushClientAttrib( GL_CLIENT_VERTEX_ARRAY_BIT ); … … 273 271 //glPolygonMode( GL_FRONT_AND_BACK, GL_LINE ); 274 272 cullCount = 0; 275 276 /*// Lets see which pages are visible.277 determineVisiblePages( root );278 int wantedLeft, wantedRight, wantedBottom, wantedTop, minLOD;279 pTerrainPage neighbor = NULL;280 page = activePages;281 bool dirty;282 current = 0;283 BufferInfo bi;284 broker->acquire( bi.vbIdentifier, bi.ibIdentifier );285 buffers.push_back( bi );286 int dirtyRounds = 0;287 do {288 dirtyRounds++;289 dirty = false;290 page = activePages;291 while ( page ) {292 if ( !page->isActive() ) {293 pTerrainPage tmp = page;294 page = tmp->getNext();295 tmp->setVisibility( false );296 continue;297 }298 wantedLeft = wantedRight = wantedBottom = wantedTop = page->getWantedLOD();299 if ( ( neighbor = page->getLeft() ) && ( neighbor->isActive() ) )300 wantedLeft = neighbor->getWantedLOD();301 if ( ( neighbor = page->getRight() ) && ( neighbor->isActive() ) )302 wantedRight = neighbor->getWantedLOD();303 if ( ( neighbor = page->getTop() ) && ( neighbor->isActive() ) )304 wantedTop = neighbor->getWantedLOD();305 if ( ( neighbor = page->getBottom() ) && ( neighbor->isActive() ) )306 wantedBottom = neighbor->getWantedLOD();307 308 minLOD = std::min( std::min( wantedBottom, wantedTop ),309 std::min( wantedLeft, wantedRight ) );310 if ( minLOD < page->getWantedLOD()-1 ) {311 page->setWantedLOD( minLOD+1 );312 dirty = true;313 }314 page = page->getNext();315 }316 } while ( dirty );317 318 page = activePages;319 while ( page ) {320 assert( page->isActive() );321 page->updateTesselation();322 page = page->getNext();323 }324 //If there is some data in the buffer, we need to upload the data325 //into the vram...326 if ( buffers[current].numIndices != 0 ) {327 BufferInfo bi = buffers[current];328 glBindBufferARB( GL_ARRAY_BUFFER_ARB, bi.vbIdentifier );329 glBufferDataARB( GL_ARRAY_BUFFER_ARB, MAX_VERTICES*sizeof( Vertex ),330 vertices, GL_DYNAMIC_DRAW_ARB );331 glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, bi.ibIdentifier );332 glBufferDataARB( GL_ELEMENT_ARRAY_BUFFER_ARB, MAX_INDICES*sizeof( short ),333 indices, GL_DYNAMIC_DRAW_ARB );334 }*/335 273 glEnable( GL_BLEND ); 336 274 glDepthFunc( GL_LEQUAL ); … … 389 327 } 390 328 } 391 392 329 glClientActiveTextureARB( GL_TEXTURE1_ARB ); 393 330 glActiveTextureARB( GL_TEXTURE1_ARB ); … … 412 349 break; 413 350 case 2: 414 pixel = *(Uint16 *)p; 351 if ( SDL_BYTEORDER == SDL_BIG_ENDIAN ) 352 pixel = p[0] << 8 | p[1]; 353 else 354 pixel = *(Uint16 *)p; 415 355 break; 416 356 case 3: … … 424 364 break; 425 365 default: 426 return 255; 366 return 255; /* shouldn't happen, but avoids warnings */ 427 367 } 428 368 Uint8 r,g,b,a; -
branches/terrain/src/lib/graphics/importer/terrain/terrain.h
r8929 r9071 92 92 indices = new unsigned short[MAX_INDICES]; 93 93 #ifdef USE_VBO 94 broker = new BufferBroker( 200, MAX_VERTICES*sizeof( Vertex ),94 broker = new BufferBroker( 300, MAX_VERTICES*sizeof( Vertex ), 95 95 MAX_INDICES*sizeof( short ) ); 96 96 #endif -
branches/terrain/src/lib/graphics/importer/terrain/terrain_page.cc
r8929 r9071 237 237 for ( int z = 0; z < size; ++z ) { 238 238 alt = getAltitude( x, z ); 239 min.y = fmin( min.y, alt );240 max.y = fmax( max.y, alt );239 min.y = fmin( min.y, alt-1.0f ); 240 max.y = fmax( max.y, alt+1.0f ); 241 241 } 242 242 } … … 272 272 void TerrainPage::updateTesselation( ) 273 273 { 274 274 assert( wantedLOD < 5 && wantedLOD >= 0 ); 275 275 if ( needsRetesselation() ) { 276 276 tesselate( wantedLOD );
Note: See TracChangeset
for help on using the changeset viewer.