Changeset 8548 in orxonox.OLD for branches/terrain
- Timestamp:
- Jun 16, 2006, 11:35:49 PM (18 years ago)
- Location:
- branches/terrain/src
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/terrain/src/lib/graphics/importer/material.h
r8037 r8548 63 63 void setBump(const std::string& bump); 64 64 GLuint getDiffuseTexture(unsigned int i = 0) const { return (this->textures.size() > i)? this->textures[i].getTexture() : 0; }; 65 66 65 static void addTexturePath(const std::string& pathName); 67 66 -
branches/terrain/src/lib/graphics/importer/terrain/terrain.cc
r8349 r8548 5 5 #include "util/loading/resource_manager.h" 6 6 #include "debug.h" 7 7 #include <math.h> 8 8 #ifdef HAVE_SDL_SDL_IMAGE_H 9 9 #include <SDL/SDL_image.h> … … 32 32 pagesX = (heightfield.width/(pageSize-1) ); 33 33 pagesZ = (heightfield.height/(pageSize-1) ); 34 tex = (Texture*)MANAGER->load( lightmapSource ); 35 36 //TODO: Determine layer visibility! 34 //tex = (Texture*)MANAGER->load( lightmapSource ); 35 //TODO: Determine layer visibility! 36 for ( int i = 0; i < materials.size(); ++i ) { 37 38 } 39 37 40 printf( " * creating terrain pages ( %d, %d )...", pagesX, pagesZ ); 38 41 pages = new pTerrainPage[pagesX*pagesZ]; … … 126 129 void Terrain::draw( ) 127 130 { 131 static float s = 0.0f, x = 0.0f; 128 132 glGetError(); 129 133 pTerrainPage page = NULL; 130 134 frustum->extractPlanes(); 131 glEnableClientState( GL_VERTEX_ARRAY ); 132 133 glEnableClientState( GL_TEXTURE_COORD_ARRAY ); 134 glEnable( GL_TEXTURE_2D ); 135 glEnable( GL_DEPTH_TEST ); 136 glDisable( GL_CULL_FACE ); 137 glBindTexture( GL_TEXTURE_2D, tex->getTexture() ); 135 136 /** 137 * Enable texture and vertex arrays for the first and the second texture 138 * units and disable the normal arrays. 139 */ 140 glClientActiveTextureARB( GL_TEXTURE0_ARB ); 141 glEnableClientState( GL_VERTEX_ARRAY ); 142 glEnableClientState( GL_TEXTURE_COORD_ARRAY ); 143 glDisableClientState( GL_NORMAL_ARRAY ); 144 145 glClientActiveTextureARB( GL_TEXTURE1_ARB ); 146 glEnableClientState( GL_VERTEX_ARRAY ); 147 glEnableClientState( GL_TEXTURE_COORD_ARRAY ); 148 glDisableClientState( GL_NORMAL_ARRAY ); 149 138 150 glDisable( GL_LIGHTING ); 139 glEnable( GL_COLOR_MATERIAL );140 151 glColor3f( 1.0f, 1.0f, 1.0f ); 152 //glPolygonMode( GL_FRONT_AND_BACK, GL_LINE ); 141 153 cullCount = 0; 154 142 155 // Lets see which pages are visible. 143 156 determineVisiblePages( root ); 144 145 page = activePages; 157 int wantedLeft, wantedRight, wantedBottom, wantedTop, minLOD; 158 pTerrainPage neighbor = NULL; 159 page = activePages; 160 146 161 while ( page ) { 147 162 if ( !page->isActive() ) { … … 150 165 tmp->setVisibility( false ); 151 166 continue; 152 } 153 page->updateTesselation(); 154 //Draw the page. TODO: It would be nice if all the pages with an LOD of 4 could be merged 155 //in one index buffer. This would give us a speed boost for sure... 156 page->draw(); 167 } 168 wantedLeft = wantedRight = wantedBottom = wantedTop = page->getWantedLOD(); 169 if ( ( neighbor = page->getLeft() ) ) 170 wantedLeft = neighbor->getWantedLOD(); 171 if ( ( neighbor = page->getRight() ) ) 172 wantedRight = neighbor->getWantedLOD(); 173 if ( ( neighbor = page->getTop() ) ) 174 wantedTop = neighbor->getWantedLOD(); 175 if ( ( neighbor = page->getBottom() ) ) 176 wantedBottom = neighbor->getWantedLOD(); 177 178 minLOD = std::min( std::min( wantedBottom, wantedTop ), std::min( wantedLeft, wantedRight ) ); 179 /*if ( minLOD < page->getWantedLOD()-1 ) 180 page->setWantedLOD( minLOD+1 );*/ 181 182 page->updateTesselation(); 157 183 page = page->getNext(); 158 184 } 159 activatedCount = 0; deactivatedCount = 0; 160 //float percentage = (float)cullCount/(float)(pagesX*pagesZ)*100.0f; 161 //printf( "culled %f%% terrain pages away\n", percentage ); 185 s = 50.0f; 186 for ( int i = 0; i < materials.size(); ++i ) { 187 page = activePages; 188 189 //This is a hack! Remove this as soon as possible 190 materials[i]->unselect(); 191 192 materials[i]->select(); 193 194 glActiveTextureARB( GL_TEXTURE1_ARB ); 195 glClientActiveTextureARB( GL_TEXTURE1_ARB ); 196 glMatrixMode( GL_TEXTURE ); 197 glLoadIdentity(); 198 glScalef( s, s, s ); 199 200 glClientActiveTextureARB( GL_TEXTURE0_ARB ); 201 glActiveTextureARB( GL_TEXTURE0_ARB ); 202 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); 203 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); 204 while ( page ) { 205 //Draw the page. TODO: It would be nice if all the pages with an LOD of 4 could be merged 206 //in one index buffer. This would give us a speed boost for sure... 207 if ( page->hasMaterial( i ) ) 208 page->draw(); 209 page = page->getNext(); 210 } 211 activatedCount = 0; deactivatedCount = 0; 212 //printf( "%d of %d pages drawn\n", pagesX*pagesZ-cullCount, pagesX*pagesZ ); 213 //float percentage = (float)cullCount/(float)(pagesX*pagesZ)*100.0f; 214 //printf( "culled %f%% terrain pages away\n", percentage ); 215 } 162 216 } 163 217 … … 182 236 getAltitude( xOff+1, zOff+0 )*scale.y, 183 237 getAltitude( xOff+1, zOff+1 )*scale.y }; 184 _alt.y = (1.0f-u )*(1.0-v)*alt[0]+u*(1.0f-v)*alt[1]+u*v*alt[2];238 _alt.y = (1.0f-u-v)*alt[0]+u*alt[1]+v*alt[2]; 185 239 186 240 //Since we know about the directions of some x and z-coordinates, … … 196 250 getAltitude( xOff+0, zOff+1 )*scale.y, 197 251 getAltitude( xOff+1, zOff+1 )*scale.y }; 198 _alt.y = (1.0f-u )*(1.0-v)*alt[0]+(1.0f-u)*v*alt[1]+u*v*alt[2];252 _alt.y = (1.0f-u-v)*alt[0]+v*alt[1]+u*alt[2]; 199 253 //Since we know about the directions of some x and z-coordinates, 200 254 //not the whole cross products needs to be calculated. Grab yourself -
branches/terrain/src/lib/graphics/importer/terrain/terrain.h
r8328 r8548 22 22 #include <cstdlib> 23 23 #include <string> 24 #include <list> 25 #include "material.h" 24 26 #include "texture.h" 25 27 #include "frustum.h" … … 34 36 35 37 class Terrain; 38 36 39 typedef Terrain *pTerrain; 37 40 … … 107 110 inline float getAltitude( int _x, int _z ) const; 108 111 109 inline void setLightmap( const std::string &_lightmap ) 112 inline void addMaterial( Material *_material ) 113 { 114 materials.push_back( _material ); 115 } 116 117 /*inline void setLightmap( const std::string &_lightmap ) 110 118 { 111 119 lightmapSource = _lightmap; 112 } 120 }*/ 113 121 inline void setHeightmap( const std::string &_heightmap ) 114 122 { … … 122 130 123 131 inline const Triple getScale() const { return scale; } 132 124 133 inline int getPageSize() const 125 134 { 126 135 return pageSize; 127 136 } 137 128 138 inline void getCoord( int _x, int _z, TexCoord& _coord) const 129 139 { … … 160 170 void determineVisiblePages( pTerrainQuad _node ); 161 171 162 pTerrainQuad root; // The quad-tree root node.163 pTerrainPage *pages; // the references to all pages164 std::string heightmapSource;165 std::string lightmapSource;166 Heightfield heightfield;167 Triple scale;168 int pagesX,169 pagesZ;170 int pageSize;171 int cullCount;172 pTerrainQuad root; // The quad-tree root node. 173 pTerrainPage *pages; // the references to all pages 174 std::string heightmapSource; 175 std::string lightmapSource; 176 Heightfield heightfield; 177 Triple scale; 178 int pagesX, 179 pagesZ; 180 int pageSize; 181 int cullCount; 172 182 173 int activatedCount, 174 deactivatedCount; // For debugging and statistics 175 Texture *tex; 176 Triple cameraPosition; 177 pFrustum frustum; 178 pTerrainPage activePages; 183 int activatedCount, 184 deactivatedCount; // For debugging and statistics 185 Texture *tex; 186 Triple cameraPosition; 187 pFrustum frustum; 188 pTerrainPage activePages; 189 std::vector<Material*> materials; 179 190 }; 180 191 -
branches/terrain/src/lib/graphics/importer/terrain/terrain_page.cc
r8349 r8548 19 19 #include <math.h> 20 20 21 21 22 #define CHECK_GL_ERROR( _d ) do { \ 22 23 GLenum __err = glGetError(); \ … … 87 88 //TODO: Perform benchmark to measure if the isVisible test should be included 88 89 //in this method. 89 90 90 void TerrainPage::determineBorderAdaption( bool _adapt[] ) 91 91 { … … 544 544 void TerrainPage::draw( ) 545 545 { 546 //These give an error547 546 assert( glIsEnabled( GL_VERTEX_ARRAY ) ); 548 547 assert( !glIsEnabled( GL_NORMAL_ARRAY ) ); 548 549 549 assert( isVisible ); assert( numIndices > 0 ); 550 550 assert( active ); 551 551 active = false; 552 552 CHECK_GL_ERROR( "1" ); 553 553 554 glVertexPointer( 3, GL_FLOAT, 0, vertices ); 554 555 glTexCoordPointer( 2, GL_FLOAT, 0, coords ); 556 557 glClientActiveTextureARB( GL_TEXTURE1_ARB ); 558 glVertexPointer( 3, GL_FLOAT, 0, vertices ); 559 glTexCoordPointer( 2, GL_FLOAT, 0, coords ); 560 555 561 glDrawElements( GL_TRIANGLE_STRIP, numIndices, 556 562 GL_UNSIGNED_SHORT, indices ); -
branches/terrain/src/lib/graphics/importer/terrain/terrain_page.h
r8349 r8548 199 199 */ 200 200 void activate(); 201 202 protected: 203 204 /** 205 * @brief Tesselates one row of the terrain page. 206 * @param _z The z-offset of the row 207 * @param _xStride Determines the step-size horizontally 208 * @param _zStride Determines the step-size vertically. 209 * @param _adaptRight True if the right neighbor has a coarser 210 * tesselation level. 211 * @param _adaptLeft True if the left neighbor has a coarser 212 * tesselation level. 213 */ 214 void tesselateRow( int _z, int _xStride, int _zStride, bool _adaptLeft, bool _adaptRight ); 215 216 /** 217 * @brief Returns four boolean values in the oder 218 */ 219 void determineBorderAdaption( bool _adapt[] ); 220 221 /** 222 * @brief Adds the given index to the index-array 223 */ 224 inline void addIndex( unsigned short _index ); 225 226 /** 227 * @brief We programmers are very lazy :) This method just adds the last added index 228 * again. 229 */ 230 inline void addAgain(); 231 232 233 void getCoord( int _x, int _z, TexCoord& _coord) const; 234 235 /** 236 * Fills _vertex with the vertex information at index. 237 */ 238 void getVertex( int _x, int _z, Triple& _vertex ) const; 239 240 /** 241 * Use this method to safely get a vertex at location ( _x, _z ). If it wasn't 242 * created before, this method does that for you. 243 */ 244 short getIndex( int _x, int _z ); 245 void tesselateLevelFourPatch( bool _adapt[] ); 246 /** 247 * Generates the tesselation for the given level of detail. 248 */ 249 void tesselate( int _lod ); 250 251 float getAltitude( int _x, int _z ) const; 252 253 int currentLOD, 254 wantedLOD; 255 float tween; 256 pTerrainPage left, 257 right, 258 top, 259 bottom; 260 bool forceTesselation; 261 bool active; 262 Triple *vertices; 263 unsigned short *indices; 264 unsigned short *indexHash; 265 TexCoord *coords; 266 int numIndices; 267 int numVertices; 268 bool isVisible; 269 pTerrainPage next; 270 pTerrainPage previous; 271 LODError *errors; 272 Triple position; 201 inline bool hasMaterial( int _i ) 202 { 203 return true; 204 } 205 206 inline void setWantedLOD( int _lod ) 207 { 208 if ( wantedLOD >= TerrainPage::MAX_LODS ) 209 wantedLOD = 4; 210 else 211 wantedLOD = _lod; 212 } 213 protected: 214 215 /** 216 * @brief Tesselates one row of the terrain page. 217 * @param _z The z-offset of the row 218 * @param _xStride Determines the step-size horizontally 219 * @param _zStride Determines the step-size vertically. 220 * @param _adaptRight True if the right neighbor has a coarser 221 * tesselation level. 222 * @param _adaptLeft True if the left neighbor has a coarser 223 * tesselation level. 224 */ 225 void tesselateRow( int _z, int _xStride, int _zStride, bool _adaptLeft, bool _adaptRight ); 226 227 /** 228 * @brief Returns four boolean values in the oder 229 */ 230 void determineBorderAdaption( bool _adapt[] ); 231 232 /** 233 * @brief Adds the given index to the index-array 234 */ 235 inline void addIndex( unsigned short _index ); 236 237 /** 238 * @brief We programmers are very lazy :) This method just adds the last added index 239 * again. 240 */ 241 inline void addAgain(); 242 243 244 void getCoord( int _x, int _z, TexCoord& _coord) const; 245 246 /** 247 * Fills _vertex with the vertex information at index. 248 */ 249 void getVertex( int _x, int _z, Triple& _vertex ) const; 250 251 /** 252 * Use this method to safely get a vertex at location ( _x, _z ). If it wasn't 253 * created before, this method does that for you. 254 */ 255 short getIndex( int _x, int _z ); 256 void tesselateLevelFourPatch( bool _adapt[] ); 257 /** 258 * Generates the tesselation for the given level of detail. 259 */ 260 void tesselate( int _lod ); 261 262 float getAltitude( int _x, int _z ) const; 263 264 int currentLOD, 265 wantedLOD; 266 float tween; 267 pTerrainPage left, 268 right, 269 top, 270 bottom; 271 bool forceTesselation; 272 bool active; 273 Triple *vertices; 274 unsigned short *indices; 275 unsigned short *indexHash; 276 TexCoord *coords; 277 int numIndices; 278 int numVertices; 279 bool isVisible; 280 pTerrainPage next; 281 pTerrainPage previous; 282 LODError *errors; 283 Triple position; 273 284 }; 274 285 -
branches/terrain/src/world_entities/camera.cc
r8349 r8548 34 34 this->subscribeEvent(ES_GAME, KeyMapper::PEV_VIEW5); 35 35 36 this->setFovy( 90);36 this->setFovy(60.0); 37 37 this->setAspectRatio(1.2f); 38 this->setClipRegion( .1, 100.0f );38 this->setClipRegion( .1, 80.0f ); 39 39 40 40 this->setViewMode(Camera::ViewNormal); -
branches/terrain/src/world_entities/terrain_entity.cc
r8328 r8548 140 140 void TerrainEntity::loadLightmap( const std::string& _lightFile ) 141 141 { 142 terrain->setLightmap( _lightFile ); 142 Material *mat = new Material( "TERR_LM" ); 143 mat->setDiffuse( 1.0f, 1.0f, 1.0f ); 144 mat->setAmbient( 1.0f, 1.0f, 1.0f ); 145 mat->setDiffuseMap( _lightFile, GL_TEXTURE_2D, 0 ); 146 mat->setDiffuseMap( std::string( "pictures/lehm.png" ), GL_TEXTURE_2D, 1 ); 147 terrain->addMaterial( mat ); 143 148 } 144 149
Note: See TracChangeset
for help on using the changeset viewer.