Main Page Namespace List Class Hierarchy Alphabetical List Compound List File List Namespace Members Compound Members File Members Related Pages

# OgreTerrainPageSource.cpp

Go to the documentation of this file.

    00001 /*
    00002 -----------------------------------------------------------------------------
    00003 This source file is part of OGRE
    00004 (Object-oriented Graphics Rendering Engine)
    00005 For the latest info, see http://www.ogre3d.org/
    00006
    00007 Copyright © 2000-2004 The OGRE Team
    00008 Also see acknowledgements in Readme.html
    00009
    00010 This program is free software; you can redistribute it and/or modify it under
    00011 the terms of the GNU Lesser General Public License as published by the Free Software
    00012 Foundation; either version 2 of the License, or (at your option) any later
    00013 version.
    00014
    00015 This program is distributed in the hope that it will be useful, but WITHOUT
    00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
    00018
    00019 You should have received a copy of the GNU Lesser General Public License along with
    00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
    00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
    00022 http://www.gnu.org/copyleft/lesser.txt.
    00023 -----------------------------------------------------------------------------
    00024 */
    00025 #include "OgreTerrainPageSource.h"
    00026 #include "OgreTerrainPage.h"
    00027 #include "OgreTerrainRenderable.h"
    00028 #include "OgreSceneNode.h"
    00029 #include "OgreTerrainSceneManager.h"
    00030
    00031 namespace Ogre {
    00032
    00033     //-----------------------------------------------------------------------
    00034     template<> TerrainPageSourceListenerManager* Singleton<TerrainPageSourceListenerManager>::ms_Singleton = 0;
    00035     TerrainPageSourceListenerManager* TerrainPageSourceListenerManager::getSingletonPtr(void)
    00036     {
    00037         return ms_Singleton;
    00038     }
    00039     TerrainPageSourceListenerManager& TerrainPageSourceListenerManager::getSingleton(void)
    00040     {
    00041         assert( ms_Singleton );  return ( *ms_Singleton );
    00042     }
    00043     //-------------------------------------------------------------------------
    00044     void TerrainPageSourceListenerManager::addListener(TerrainPageSourceListener* pl)
    00045     {
    00046         mPageSourceListeners.push_back(pl);
    00047     }
    00048     //-------------------------------------------------------------------------
    00049     void TerrainPageSourceListenerManager::removeListener(TerrainPageSourceListener* pl)
    00050     {
    00051         PageSourceListenerList::iterator i, iend;
    00052         iend = mPageSourceListeners.end();
    00053         for(i = mPageSourceListeners.begin(); i != iend; ++i)
    00054         {
    00055             if (*i == pl)
    00056             {
    00057                 mPageSourceListeners.erase(i);
    00058                 break;
    00059             }
    00060         }
    00061     }
    00062     //-------------------------------------------------------------------------
    00063     void TerrainPageSourceListenerManager::firePageConstructed(size_t pagex, size_t pagez, Real* heightData)
    00064     {
    00065         PageSourceListenerList::iterator i, iend;
    00066         iend = mPageSourceListeners.end();
    00067         for(i = mPageSourceListeners.begin(); i != iend; ++i)
    00068         {
    00069             (*i)->pageConstructed(pagex, pagez, heightData);
    00070         }
    00071     }
    00072     //-------------------------------------------------------------------------
    00073     TerrainPageSource::TerrainPageSource() : mSceneManager(0), mAsyncLoading(false) {
    00074     }
    00075     //-------------------------------------------------------------------------
    00076     TerrainPage* TerrainPageSource::buildPage(Real* heightData, Material* pMaterial)
    00077     {
    00078         String name;
    00079
    00080         // Create a Terrain Page
    00081         TerrainPage* page = new TerrainPage((mPageSize-1) / (mTileSize-1));
    00082         // Create a node for all tiles to be attached to
    00083         // Note we sequentially name since page can be attached at different points
    00084         // so page x/z is not appropriate
    00085         static size_t pageIndex = 0;
    00086         StringUtil::StrStreamType page_str;
    00087         page_str << pageIndex;
    00088         name = "page[";
    00089         name += page_str.str() + "]";
    00090         page->pageSceneNode = mSceneManager->createSceneNode(name);
    00091
    00092         size_t q = 0;
    00093         for ( size_t j = 0; j < mPageSize - 1; j += ( mTileSize - 1 ) )
    00094         {
    00095             size_t p = 0;
    00096
    00097             for ( size_t i = 0; i < mPageSize - 1; i += ( mTileSize - 1 ) )
    00098             {
    00099                 StringUtil::StrStreamType new_name_str;
    00100
    00101                 // Create scene node for the tile and the TerrainRenderable
    00102                 new_name_str << "tile[" << pageIndex << "][" << (int)p << "," << (int)q << "]";
    00103                 name = new_name_str.str();
    00104
    00105                 SceneNode *c = page->pageSceneNode->createChildSceneNode( name );
    00106                 TerrainRenderable *tile = new TerrainRenderable(name);
    00107                 // Initialise the tile
    00108                 tile->setMaterial(pMaterial);
    00109                 tile->initialise(i, j, heightData);
    00110                 // Attach it to the page
    00111                 page->tiles[ p ][ q ] = tile;
    00112                 // Attach it to the node
    00113                 c ->attachObject( tile );
    00114                 p++;
    00115             }
    00116
    00117             q++;
    00118
    00119         }
    00120
    00121         pageIndex++;
    00122
    00123         // calculate neighbours for page
    00124         page->linkNeighbours();
    00125
    00126         return page;
    00127     }
    00128     //-------------------------------------------------------------------------
    00129     void TerrainPageSource::firePageConstructed(size_t pagex, size_t pagez, Real* heightData)
    00130     {
    00131         TerrainPageSourceListenerManager::getSingleton().firePageConstructed(pagex, pagez, heightData);
    00132     }
    00133     //-------------------------------------------------------------------------
    00134     void TerrainPageSource::addListener(TerrainPageSourceListener* pl)
    00135     {
    00136         TerrainPageSourceListenerManager::getSingleton().addListener(pl);
    00137     }
    00138     //-------------------------------------------------------------------------
    00139     void TerrainPageSource::removeListener(TerrainPageSourceListener* pl)
    00140     {
    00141         TerrainPageSourceListenerManager::getSingleton().removeListener(pl);
    00142
    00143     }
    00144     //-------------------------------------------------------------------------
    00145
    00146 }

Copyright © 2002-2003 by The OGRE Team
Last modified Sun Nov 28 19:48:48 2004