Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9071 in orxonox.OLD


Ignore:
Timestamp:
Jul 3, 2006, 10:23:35 PM (18 years ago)
Author:
ponder
Message:

Cleanup for the terrain

Location:
branches/terrain/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/terrain/src/lib/graphics/importer/terrain/frustum.h

    r8775 r9071  
    2020
    2121
    22 #define MAX_CLIP_DISTANCE 400.0f
    23 #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]
    2424
    2525#define CHECK_GL_ERROR( _d ) do { \
     
    9393                inline void setFrustum( float *_m )
    9494                {
    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));
    130119                                                       
    131120                        if ( planes[NEAR].d +planes[FAR].d  > MAX_CLIP_DISTANCE ) {
  • branches/terrain/src/lib/graphics/importer/terrain/terrain.cc

    r8965 r9071  
    2828        SDL_Surface *tmpData = IMG_Load( full.c_str() );
    2929        if ( !tmpData ) {
    30                 PRINTF(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() );
    3131                return;
    3232        }               
    3333        if ( !validateSize( tmpData->h ) || !validateSize( tmpData->w ) ) {
    34                 PRINTF(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" );
    3535                return;
    3636        }
    3737        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 );
    3940                return;
    4041        }
     
    148149        switch( _node->cull() ) {
    149150                case Frustum::INTERSECT:
    150                         //printf( "partially inside frustum\n" );
    151151                        if ( !_node->isChildless() ) {
    152152                                pTerrainQuad *children = _node->getChildren();
     
    160160                        break;
    161161                case Frustum::INSIDE:
    162                         //printf( "fully inside frustum\n" );                   
    163162                        showPages( _node->getXOffset(),
    164163                                           _node->getZOffset(),
     
    167166                        break;
    168167                case Frustum::OUTSIDE:
    169                         cullCount+= (_node->getWidth()-1)*(_node->getHeight()-1);
    170168                        break;
    171169        }
     
    249247        //Due to some reason, the OpenGL implementors chose the plane equation
    250248        //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 );
    254252        glPushAttrib( GL_ALL_ATTRIB_BITS );
    255253        glPushClientAttrib( GL_CLIENT_VERTEX_ARRAY_BIT );
     
    273271        //glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
    274272        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 data
    325         //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         }*/
    335273        glEnable( GL_BLEND );
    336274        glDepthFunc( GL_LEQUAL );
     
    389327                }
    390328        }
    391                        
    392329        glClientActiveTextureARB( GL_TEXTURE1_ARB );   
    393330        glActiveTextureARB( GL_TEXTURE1_ARB );
     
    412349                break;
    413350    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;
    415355                break;
    416356    case 3:
     
    424364                break;
    425365    default:
    426         return 255;       /* shouldn't happen, but avoids warnings */
     366        return 255; /* shouldn't happen, but avoids warnings */
    427367    }
    428368        Uint8 r,g,b,a;
  • branches/terrain/src/lib/graphics/importer/terrain/terrain.h

    r8929 r9071  
    9292                        indices = new unsigned short[MAX_INDICES];
    9393#ifdef USE_VBO
    94                         broker = new BufferBroker( 200, MAX_VERTICES*sizeof( Vertex ),
     94                        broker = new BufferBroker( 300, MAX_VERTICES*sizeof( Vertex ),
    9595                                MAX_INDICES*sizeof( short ) );
    9696#endif                 
  • branches/terrain/src/lib/graphics/importer/terrain/terrain_page.cc

    r8929 r9071  
    237237                for ( int z = 0; z < size; ++z ) {
    238238                        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 );
    241241                }
    242242        }
     
    272272void TerrainPage::updateTesselation( )
    273273{
    274 
     274        assert( wantedLOD < 5 && wantedLOD >= 0 );
    275275        if ( needsRetesselation() ) {
    276276                tesselate( wantedLOD );
  • branches/terrain/src/world_entities/camera.cc

    r8775 r9071  
    3434  this->subscribeEvent(ES_GAME, KeyMapper::PEV_VIEW5);
    3535
    36   this->setFovy(60.0);
     36  this->setFovy(90.0);
    3737  this->setAspectRatio(1.2f);
    3838  this->setClipRegion( .1, 40.0f );
Note: See TracChangeset for help on using the changeset viewer.