Changeset 8741 in orxonox.OLD for branches/terrain/src
- Timestamp:
- Jun 23, 2006, 11:29:40 AM (18 years ago)
- Location:
- branches/terrain/src
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/terrain/src/lib/collision_detection/cd_engine.cc
r8715 r8741 119 119 if ( tl == NULL ) 120 120 return; 121 float offset = 8.0f; 121 122 for ( ti = tl->begin(); ti != tl->end(); ++ti ) { 122 123 TerrainEntity* terrain = dynamic_cast<TerrainEntity*>( *ti ); 123 124 for( entityIterator = list1.begin(); entityIterator != list1.end(); entityIterator++ ) 124 125 { 125 const Vector& pos = (*entityIterator)->getAbsCoor(); 126 127 float height = terrain->getHeight( pos.x, pos.z ); 128 printf( "pos.y-height: %f\n", pos.y-height ); 129 if ( height > pos.y ) { 130 (*entityIterator)->setAbsCoor( pos.x, height, pos.z ); 126 Vector pos( (*entityIterator)->getAbsCoor() ); 127 Vector normal; 128 float height = pos.y; 129 terrain->getAltitude( pos, normal ); 130 if ( height-offset < pos.y ) { 131 ( *entityIterator )->registerCollision( 132 *entityIterator, terrain, pos, normal ); 131 133 } 132 134 } -
branches/terrain/src/lib/graphics/importer/terrain/terrain.cc
r8697 r8741 29 29 memcpy( heightfield.data, tmpData->pixels, sizeof(UByte)*dataSize ); 30 30 SDL_FreeSurface( tmpData ); 31 //TODO: Perform some checks... 31 //TODO: Perform some checks... size, bits and so on 32 32 pagesX = (heightfield.width/(pageSize-1) ); 33 33 pagesZ = (heightfield.height/(pageSize-1) ); 34 //tex = (Texture*)MANAGER->load( lightmapSource );35 34 //TODO: Determine layer visibility! 36 35 for ( unsigned int i = 0; i < materials.size(); ++i ) { 37 36 38 37 } 39 40 printf( " * creating terrain pages ( %d, %d )...", pagesX, pagesZ );41 38 pages = new pTerrainPage[pagesX*pagesZ]; 42 39 for ( int x = 0; x < pagesX; ++x ) 43 40 for ( int z = 0; z < pagesZ; ++z ) 44 41 pages[z*pagesX+x] = createPage( x, z ); 45 printf( "looks good\n" );46 printf( " * inform pages about the adjacent pages..." );47 42 //Inform each page about its neighbors. 48 43 for ( int x = 0; x < pagesX; ++x ) … … 54 49 z > 0 ? getPage( x+0, z-1 ) : NULL ); 55 50 56 printf( "looks good\n" );57 printf( " * creating quad_tree data structure..." );58 51 root = createQuadTree( 0, 0, pagesX, pagesZ ); 59 52 activePages = NULL; 60 printf( "looks good\n" );61 53 } 62 54 … … 104 96 glBufferDataARB( GL_ELEMENT_ARRAY_BUFFER_ARB, MAX_INDICES*sizeof( short ), 105 97 indices, GL_DYNAMIC_DRAW_ARB ); 106 //printf( "uploaded %d verts and %d indices\n", bi.numIndices, bi.numVertices );107 98 BufferInfo newInfo; 108 99 broker->acquire( newInfo.vbIdentifier, newInfo.ibIdentifier ); … … 114 105 memcpy( &vertices[bi.numVertices], _vertices, 115 106 _numVertices*sizeof( Vertex ) ); 116 bi.numVertices+=_numVertices;117 107 //The indices need to be updated with an offset :( 118 unsigned short *end = _indices+_numIndices; 119 unsigned short *dst = indices+bi.numIndices; 120 int offset = bi.numIndices; 121 if ( bi.numIndices > 0 ) { 122 indices[bi.numIndices] = indices[bi.numIndices-1]; 123 indices[bi.numIndices+1] = _indices[0]+offset; 124 dst+=2; 125 bi.numIndices+=2; 126 } 127 for ( unsigned short *i = _indices; i < end; ++i, ++dst ) { 128 *dst = *i+offset; 108 unsigned short *dst= &indices[bi.numIndices]; 109 unsigned short offset = bi.numVertices; 110 unsigned short *src= _indices; 111 unsigned short *end= src+_numIndices; 112 bi.numVertices+=_numVertices; 113 if ( bi.numIndices ) { 114 dst[0] = *(dst-1); 115 dst[1] = *src+offset; 116 dst+=2; bi.numIndices+=2; 117 } 118 while ( src < end ) { 119 *dst= *src+offset; 120 dst++; 121 src++; 129 122 } 130 123 bi.numIndices+=_numIndices; … … 167 160 frustum->extractPlanes(); 168 161 169 /* *162 /* 170 163 * Enable texture and vertex arrays for the first and the second texture 171 164 * units and disable the normal arrays. … … 181 174 glDisableClientState( GL_NORMAL_ARRAY ); 182 175 glDisable( GL_CULL_FACE ); 176 glCullFace( GL_BACK ); 183 177 glDisable( GL_LIGHTING ); 184 178 glColor3f( 1.0f, 1.0f, 1.0f ); … … 230 224 page = activePages; 231 225 while ( page ) { 226 assert( page->isActive() ); 232 227 page->updateTesselation(); 233 228 page = page->getNext(); … … 236 231 if ( buffers[current].numIndices != 0 ) { 237 232 BufferInfo bi = buffers[current]; 238 glBindBufferARB( GL_ARRAY_BUFFER_ARB, 239 bi.vbIdentifier ); 233 glBindBufferARB( GL_ARRAY_BUFFER_ARB, bi.vbIdentifier ); 240 234 glBufferDataARB( GL_ARRAY_BUFFER_ARB, MAX_VERTICES*sizeof( Vertex ), 241 235 vertices, GL_DYNAMIC_DRAW_ARB ); 242 glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, 243 bi.ibIdentifier ); 236 glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, bi.ibIdentifier ); 244 237 glBufferDataARB( GL_ELEMENT_ARRAY_BUFFER_ARB, MAX_INDICES*sizeof( short ), 245 238 indices, GL_DYNAMIC_DRAW_ARB ); 246 239 } 247 s = 200.0f;248 240 glPushAttrib( GL_COLOR_BUFFER_BIT ); 249 241 for ( unsigned int i = 0; i < materials.size(); ++i ) { … … 258 250 glMatrixMode( GL_TEXTURE ); 259 251 glLoadIdentity(); 260 glScalef( s, s, s);252 glScalef( pagesX, pagesZ, 1.0f ); 261 253 262 254 glClientActiveTextureARB( GL_TEXTURE0_ARB ); … … 264 256 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); 265 257 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); 258 glEnable( GL_CULL_FACE ); 266 259 for ( unsigned j = 0; j < buffers.size(); ++j ) { 267 260 BufferInfo bi = buffers[j]; -
branches/terrain/src/lib/graphics/importer/terrain/terrain.h
r8697 r8741 76 76 * reasonable value... 77 77 */ 78 inline float getDetail() { return 0.0 5f; }78 inline float getDetail() { return 0.02f; } 79 79 80 80 -
branches/terrain/src/lib/graphics/importer/terrain/terrain_page.cc
r8697 r8741 44 44 } 45 45 46 void TerrainPage::tesselateRow( int _z, int _xStride, int _zStride, bool _adaptLeft, bool _adaptRight ) 46 void TerrainPage::tesselateRow( int _z, int _xStride, int _zStride, 47 bool _adaptLeft, bool _adaptRight ) 47 48 { 48 49 … … 51 52 assert( _xStride > 0 ); assert( _zStride > 0 ); 52 53 if ( _z ) { 53 addAgain( 54 addAgain(); 54 55 addIndex( getIndex( 0, _z ) ); 55 56 } … … 77 78 if ( _adaptRight ) { 78 79 assert( halfStride > 0 ); 79 addIndex( getIndex( w-_xStride, _z ) );80 addIndex( getIndex( xEnd-1, _z ) ); 80 81 addAgain(); 81 82 addIndex( getIndex( w, _z ) ); 82 addIndex( getIndex( w-_xStride, _z+_zStride ) );83 addIndex( getIndex( xEnd-1, _z+_zStride ) ); 83 84 addIndex( getIndex( w, _z+halfStride ) ); 84 85 addIndex( getIndex( w, _z+_zStride ) ); … … 92 93 _adapt[0] = _adapt[1] = _adapt[2] = _adapt[3] = false; 93 94 94 if ( left && left->is Visible )95 if ( left && left->isActive() ) { 95 96 _adapt[TP_LEFT] = ( wantedLOD - left->getWantedLOD() ) > 0; 96 97 if ( right && right->isVisible ) 97 assert( std::abs( wantedLOD - left->wantedLOD ) < 2 ); 98 } 99 if ( right && right->isActive() ) { 98 100 _adapt[TP_RIGHT] = ( wantedLOD - right->getWantedLOD() ) > 0; 99 100 if ( top && top->isVisible ) 101 assert( std::abs( wantedLOD - right->wantedLOD ) < 2 ); 102 } 103 104 if ( top && top->isActive() ) { 101 105 _adapt[TP_TOP] = ( wantedLOD - top->getWantedLOD() ) > 0; 102 103 if ( bottom && bottom->isVisible ) 106 assert( std::abs( wantedLOD - top->wantedLOD ) < 2 ); 107 } 108 if ( bottom && bottom->isActive() ) { 104 109 _adapt[TP_BOTTOM] = ( wantedLOD - bottom->getWantedLOD() ) > 0; 110 assert( std::abs( wantedLOD - bottom->wantedLOD ) < 2 ); 111 } 105 112 } 106 113 … … 246 253 iChanged = wantedLOD != currentLOD; 247 254 248 return ( leftChanged || rightChanged || topChanged || bottomChanged || forceTesselation || iChanged ); 255 return ( leftChanged || rightChanged || topChanged || bottomChanged || 256 forceTesselation || iChanged ); 249 257 } 250 258 … … 256 264 } 257 265 currentLOD = wantedLOD; 266 258 267 //Check if the page is a level four page. If yes, copy the vertex and index data into 259 // 268 //the shared level four page buffers. 260 269 if ( currentLOD == TerrainPage::MAX_LODS-1 ) { 261 270 owner->addLevelFourPage( numVertices, vertices, … … 263 272 } 264 273 forceTesselation = false; 274 } 275 276 void TerrainPage::tesselateTopRow( int _z, int _stride, 277 bool _adaptLeft, bool _adaptRight ) 278 { 279 int halfStride = _stride/2; 280 int xStart = 0, xEnd= owner->getPageSize()-1; 281 int size = xEnd; 282 int z = xEnd-_stride ; 283 addAgain(); 284 addIndex( getIndex( 0, z ) ); 285 assert(halfStride>=1); 286 287 if( _adaptLeft ) { 288 addIndex( getIndex( 0, z ) ); 289 addIndex( getIndex( 0, z+halfStride ) ); 290 addIndex( getIndex( _stride, z ) ); 291 addIndex( getIndex( 0, size ) ); 292 addIndex( getIndex( halfStride, size ) ); 293 addAgain(); 294 addIndex( getIndex( _stride, z ) ); 295 addIndex( getIndex( _stride, size ) ); 296 xStart = _stride; 297 } 298 299 if ( _adaptRight ) 300 xEnd -= _stride; 301 for ( int x = xStart; x < xEnd; x+=_stride ) { 302 addIndex( getIndex( x, z ) ); 303 addIndex( getIndex( x, size ) ); 304 addIndex( getIndex( x+_stride, z ) ); 305 addIndex( getIndex( x+halfStride, size ) ); 306 addIndex( getIndex( x+_stride, size ) ); 307 addAgain(); 308 } 309 310 if ( _adaptRight ) { 311 addIndex( getIndex( xEnd, z ) ); 312 addIndex( getIndex( xEnd, size ) ); 313 addIndex( getIndex( size, z ) ); 314 addIndex( getIndex( xEnd+halfStride, size ) ); 315 addIndex( getIndex( size, size-halfStride ) ); 316 addIndex( getIndex( size, size ) ); 317 } 318 319 } 320 void TerrainPage::tesselateBottomRow( int _z, int _stride, 321 bool _adaptLeft, bool _adaptRight ) 322 { 323 int halfStride = _stride/2; 324 int xStart=0, xEnd=owner->getPageSize()-1; 325 int size = xEnd; 326 assert( halfStride>=1 ); 327 328 if ( _adaptLeft ) { 329 addIndex( getIndex( 0, 0 ) ); 330 addIndex( getIndex( 0, halfStride ) ); 331 addIndex( getIndex( halfStride, 0 ) ); 332 addIndex( getIndex( 0, _stride ) ); 333 addIndex( getIndex( _stride, 0 ) ); 334 addIndex( getIndex( _stride, _stride ) ); 335 xStart = _stride; 336 } 337 338 339 if ( _adaptRight ) 340 xEnd -= _stride; 341 342 for ( int x = xStart; x < xEnd; x+=_stride ) { 343 addIndex( getIndex( x, 0 ) ); 344 addAgain(); 345 addIndex( getIndex( x+halfStride, 0 ) ); 346 addIndex( getIndex( x, _stride ) ); 347 addIndex( getIndex( x+_stride ,0 ) ); 348 addIndex( getIndex( x+_stride, _stride ) ); 349 } 350 351 352 if( _adaptRight ) { 353 addIndex( getIndex( xEnd,0 ) ); 354 addIndex( getIndex( xEnd,_stride ) ); 355 addIndex( getIndex( xEnd+halfStride, 0 ) ); 356 addIndex( getIndex( size ,0 ) ); 357 addAgain(); 358 addIndex( getIndex( xEnd, _stride ) ); 359 addIndex( getIndex( size, halfStride ) ); 360 addIndex( getIndex( size, _stride ) ); 361 } 265 362 } 266 363 … … 294 391 addIndex( getIndex( 0, stride ) ); 295 392 addIndex( getIndex( stride, stride ) ); 296 addAgain( 393 addAgain( ); 297 394 break; 298 395 … … 303 400 addIndex( getIndex( stride, 0 ) ); 304 401 addIndex( getIndex( 0, 0 ) ); 305 addAgain( 402 addAgain( ); 306 403 break; 307 404 … … 317 414 case ADAPT_B: 318 415 addIndex( getIndex( 0, 0 ) ); 319 addAgain( 416 addAgain(); 320 417 addIndex( getIndex( halfStride, 0 ) ); 321 418 addIndex( getIndex( 0, stride ) ); … … 513 610 514 611 if ( adapt[TP_BOTTOM] ) { 515 tesselate Row( 0, stride / 2, stride, adapt[TP_LEFT], adapt[TP_RIGHT] );612 tesselateBottomRow( 0, stride, adapt[TP_LEFT], adapt[TP_RIGHT] ); 516 613 zStart+= stride; 517 614 } … … 525 622 526 623 if ( adapt[TP_TOP] ) { 527 addAgain( ); 528 addIndex( getIndex( 0, owner->getPageSize()-1-stride ) ); 529 tesselateRow( owner->getPageSize()-1-stride, stride / 2, 624 tesselateTopRow( owner->getPageSize()-stride-1, 530 625 stride, adapt[TP_LEFT], adapt[TP_RIGHT] ); 531 626 } … … 621 716 active = false; 622 717 CHECK_GL_ERROR( "1" ); 623 624 718 #ifdef USE_VBO 625 719 -
branches/terrain/src/lib/graphics/importer/terrain/terrain_page.h
r8697 r8741 233 233 */ 234 234 void tesselateRow( int _z, int _xStride, int _zStride, bool _adaptLeft, bool _adaptRight ); 235 235 void tesselateTopRow( int _z, int _stride, bool _adaptLeft, bool _adaptRight ); 236 void tesselateBottomRow( int _z, int _stride, bool _adaptLeft, bool _adaptRight ); 236 237 /** 237 238 * @brief Returns four boolean values in the oder -
branches/terrain/src/world_entities/terrain_entity.cc
r8697 r8741 144 144 mat->setAmbient( 1.0f, 1.0f, 1.0f ); 145 145 mat->setDiffuseMap( _lightFile, GL_TEXTURE_2D, 0 ); 146 mat->setDiffuseMap( std::string( " maps/gras_128.jpg" ), GL_TEXTURE_2D, 1 );146 mat->setDiffuseMap( std::string( "pictures/debug.png" ), GL_TEXTURE_2D, 1 ); 147 147 terrain->addMaterial( mat ); 148 148 } … … 382 382 } 383 383 } 384 void TerrainEntity::getAltitude( Vector& _position, Vector& _normal ) 385 { 386 Triple altitude( _position.x-getAbsCoor().x, 0.0f, _position.z-getAbsCoor().z ), 387 normal( 0.0f, 0.0f, 0.0f ); 388 if ( terrain ) 389 terrain->getAltitude( altitude, normal ); 390 391 _position.y = altitude.y+getAbsCoor().y; 392 _normal.z = normal.z; _normal.y = normal.y; _normal.z = normal.z; 393 } 384 394 385 395 float TerrainEntity::getHeight( float x, float z ) -
branches/terrain/src/world_entities/terrain_entity.h
r8697 r8741 45 45 46 46 float getHeight(float x, float y); 47 void getAltitude( Vector& _position, Vector& _normal ); 47 48 virtual void draw() const; 48 49
Note: See TracChangeset
for help on using the changeset viewer.