Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 23, 2006, 3:22:53 PM (18 years ago)
Author:
ponder
Message:
  • A few more properties can be specified in the .oxw file for the terrain.
  • several material-layers can be rendered now.
  • there is still one crack appearing now and then.. need to isolate it and send him to hell.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/terrain/src/world_entities/terrain_entity.cc

    r8741 r8744  
    115115void TerrainEntity::loadParams(const TiXmlElement* root)
    116116{
    117         WorldEntity::loadParams(root);
     117        WorldEntity::loadParams( root );
    118118
    119119        LoadParam(root, "scale", this, TerrainEntity, setScale)
    120120                .describe("The scale in x,y,z direction");
    121121       
    122         LoadParam( root, "lightmap", this, TerrainEntity, loadLightmap )
     122        LoadParam( root, "light_map", this, TerrainEntity, loadLightmap )
    123123                .describe("The name of the lightmap.");
    124124               
    125         LoadParam( root, "elevationmap", this, TerrainEntity, loadElevationmap )
     125        LoadParam( root, "elevation_map", this, TerrainEntity, loadElevationmap )
    126126                .describe( "The name of the elevation map. Must be an 8bit image" );
    127                
     127        ResourceManager *manager = ResourceManager::getInstance();
     128        TiXmlElement * layer = (TiXmlElement*)root->FirstChild( "material_layer" );             
     129        while ( layer ) {
     130                LayerInfo *info = new LayerInfo();
     131                TiXmlElement *detail = (TiXmlElement*)layer->FirstChild( "detail_map" );
     132                if ( detail ) {
     133                        string detailmap( detail->Attribute( "file" ) );
     134                        info->detail = (Texture*)manager->load( detailmap,
     135                                IMAGE, RP_GAME, (int)GL_TEXTURE_2D );                   
     136                        if ( !info->detail ) {
     137                                PRINTF(0)( "%s not found\n", detailmap.c_str() );
     138                        }       
     139                        TiXmlElement *repeat = (TiXmlElement*)detail->FirstChild( "repeat" );
     140                        if ( repeat ) {
     141                                repeat->QueryFloatAttribute( "x", &info->repeatX );
     142                                repeat->QueryFloatAttribute( "z", &info->repeatZ );                             
     143                        }
     144                }
     145                else {
     146                        PRINTF(0)( "Please specify a detail-map" );
     147                }
     148                TiXmlElement *alpha = (TiXmlElement*)layer->FirstChild( "alpha" );
     149                if ( alpha ) {
     150                                if ( !alpha->Attribute( "full" ) ) {
     151                                        string alphamap( alpha->Attribute( "file" ) );
     152                                        info->alpha = (Texture*)manager->load( alphamap,
     153                                                IMAGE, RP_GAME, (int)GL_TEXTURE_2D );
     154                                }
     155                }       
     156                terrain->addMaterialLayer( info );
     157                layer = (TiXmlElement*)layer->NextSibling( "material_layer" );
     158        }
    128159}
    129160
     
    140171void TerrainEntity::loadLightmap( const std::string& _lightFile )
    141172{
    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/debug.png" ), GL_TEXTURE_2D, 1 );   
    147         terrain->addMaterial( mat );
     173        ResourceManager *manager = ResourceManager::getInstance();
     174        Texture *lightmap = (Texture*)manager->load( _lightFile,
     175                IMAGE, RP_GAME, (int)GL_TEXTURE_2D );   
     176        if ( lightmap )
     177                terrain->setLightmap( lightmap );
     178        else
     179                PRINTF(0)("no lightmap %s\n", _lightFile.c_str() );
    148180}
    149181
     
    173205        glPushMatrix();
    174206
    175   /* translate */
    176207   glTranslatef( this->getAbsCoor().x,
    177208                 this->getAbsCoor().y,
     
    184215                terrain->draw( );
    185216        }
    186 
    187217        glPopMatrix();
    188   /*
    189     glMatrixMode(GL_MODELVIEW);
    190     glPushMatrix();
    191     glLoadIdentity();
    192     Vector camera =   State::getCameraNode()->getAbsCoor(); // Go on here ..........!!!
    193 
    194     float height =    heightMap->getHeight(camera.x, camera.z);
    195 
    196     glEnable (GL_COLOR_MATERIAL) ;
    197     glBegin(GL_QUADS);            // Draw The Cube Using quads
    198     glColor3f(0.0f,1.0f,0.0f);  // Color Blue
    199     glVertex3f(camera.x + 63.0f,TerrainEntity->getHeight(camera.x+63.0f, camera.z-10.0f)+13.0f,camera.z-10.0f);      // Top Right Of The Quad (Top)
    200     glVertex3f(camera.x-63.0f, getHeight(camera.x+63.0f, camera.z-10.0f)+13.0f,camera.z-10.0f);      // Top Left Of The Quad (Top)
    201     glVertex3f(camera.x-63.0f, getHeight(camera.x+63.0f, camera.z+10.0f)+13.0f, camera.z+10.0f);      // Bottom Left Of The Quad (Top)
    202     glVertex3f(camera.x+ 63.0f, getHeight(camera.x+63.0f, camera.z+10.0f)+13.0f, camera.z+10.0f);      // Bottom Right Of The Quad (Top)
    203     glEnd();                      // End Drawing The Plan
    204 
    205     glPopMatrix();*/
     218
    206219
    207220}
Note: See TracChangeset for help on using the changeset viewer.