source: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreBiTerrainPageSource.cpp @ 2348

Revision 2348, 6.6 KB checked in by vizrt_christian_seidl, 18 years ago (diff)

Added: BIHierarchy SceneManager?

BITerrain SceneManager?

Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4(Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2005 The OGRE Team
8Also see acknowledgements in Readme.html
9
10This program is free software; you can redistribute it and/or modify it under
11the terms of the GNU Lesser General Public License as published by the Free Software
12Foundation; either version 2 of the License, or (at your option) any later
13version.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public License along with
20this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22http://www.gnu.org/copyleft/lesser.txt.
23-----------------------------------------------------------------------------
24*/
25/*
26-----------------------------------------------------------------------------
27This source file is part of the GameTools Project
28http://www.gametools.org
29
30Author: Martin Szydlowski
31-----------------------------------------------------------------------------
32*/
33
34#include <OgreSceneNode.h>
35#include "OgreBiTerrainPage.h"
36#include "OgreBiTerrainRenderable.h"
37#include "OgreBiTerrainPageSource.h"
38#include "OgreBiTerrainSceneManager.h"
39
40#pragma warning(disable : 4267)
41
42namespace Ogre {
43
44    //-----------------------------------------------------------------------
45    template<> BiTerrainPageSourceListenerManager* Singleton<BiTerrainPageSourceListenerManager>::ms_Singleton = 0;
46    BiTerrainPageSourceListenerManager* BiTerrainPageSourceListenerManager::getSingletonPtr(void)
47    {
48        return ms_Singleton;
49    }
50    BiTerrainPageSourceListenerManager& BiTerrainPageSourceListenerManager::getSingleton(void)
51    { 
52        assert( ms_Singleton );  return ( *ms_Singleton ); 
53    }
54    //-------------------------------------------------------------------------
55        void BiTerrainPageSourceListenerManager::addListener(BiTerrainPageSourceListener* pl)
56        {
57        mPageSourceListeners.push_back(pl);
58        }
59    //-------------------------------------------------------------------------
60        void BiTerrainPageSourceListenerManager::removeListener(BiTerrainPageSourceListener* pl)
61        {
62        BiPageSourceListenerList::iterator i, iend;
63        iend = mPageSourceListeners.end();
64        for(i = mPageSourceListeners.begin(); i != iend; ++i)
65        {
66            if (*i == pl)
67            {
68                mPageSourceListeners.erase(i);
69                break;
70            }
71        }
72        }
73    //-------------------------------------------------------------------------
74        void BiTerrainPageSourceListenerManager::firePageConstructed(
75                BiTerrainSceneManager* sm, uint pagex, uint pagez, Real* heightData)
76        {
77        BiPageSourceListenerList::iterator i, iend;
78        iend = mPageSourceListeners.end();
79        for(i = mPageSourceListeners.begin(); i != iend; ++i)
80        {
81            (*i)->pageConstructed(sm, pagex, pagez, heightData);
82        }
83        }
84        //-------------------------------------------------------------------------
85        BiTerrainPageSource::BiTerrainPageSource() : mSceneManager(0), mAsyncLoading(false) {
86        }
87        //-------------------------------------------------------------------------
88        BiTerrainPage* BiTerrainPageSource::buildPage(Real* heightData, const MaterialPtr& pMaterial)
89    {
90        String name;
91
92        // Create a Terrain Page
93        BiTerrainPage* page = new BiTerrainPage((mPageSize-1) / (mTileSize-1));
94        // Create a node for all tiles to be attached to
95        // Note we sequentially name since page can be attached at different points
96        // so page x/z is not appropriate
97                StringUtil::StrStreamType page_str;
98                uint pageIndex = mSceneManager->_getPageCount();
99                page_str << pageIndex;
100        name = "page[";
101        name += page_str.str() + "]";
102        page->pageSceneNode = mSceneManager->createSceneNode(name);
103       
104        size_t q = 0;
105        for ( size_t j = 0; j < mPageSize - 1; j += ( mTileSize - 1 ) )
106        {
107            size_t p = 0;
108
109            for ( size_t i = 0; i < mPageSize - 1; i += ( mTileSize - 1 ) )
110            {
111                                StringUtil::StrStreamType new_name_str;
112                               
113                // Create scene node for the tile and the TerrainRenderable
114                new_name_str << "tile[" << pageIndex << "][" << (int)p << "," << (int)q << "]";
115                                name = new_name_str.str();
116
117                SceneNode *c = page->pageSceneNode->createChildSceneNode( name );
118                BiTerrainRenderable *tile = new BiTerrainRenderable(name, mSceneManager);
119                                // set queue
120                                tile->setRenderQueueGroup(mSceneManager->getWorldGeometryRenderQueue());
121                // Initialise the tile
122                tile->setMaterial(pMaterial);
123                tile->initialise(i, j, heightData);
124                // Attach it to the page
125                page->tiles[ p ][ q ] = tile;
126                // Attach it to the node
127                c ->attachObject( tile );
128                p++;
129            }
130
131            q++;
132
133        }
134
135        pageIndex++;
136
137        // calculate neighbours for page
138        page->linkNeighbours();
139
140                if(mSceneManager->getOptions().lit)
141                {
142                        q = 0;
143                        for ( size_t j = 0; j < mPageSize - 1; j += ( mTileSize - 1 ) )
144                        {
145                                size_t p = 0;
146
147                                for ( size_t i = 0; i < mPageSize - 1; i += ( mTileSize - 1 ) )
148                                {
149                                        page->tiles[ p ][ q ]->_calculateNormals();
150                                        p++;
151                                }
152                                q++;
153                        }
154                }
155
156        return page;
157    }
158    //-------------------------------------------------------------------------
159    void BiTerrainPageSource::firePageConstructed(size_t pagex, size_t pagez, Real* heightData)
160    {
161                BiTerrainPageSourceListenerManager::getSingleton().firePageConstructed(
162                        mSceneManager, pagex, pagez, heightData);
163    }
164    //-------------------------------------------------------------------------
165    void BiTerrainPageSource::addListener(BiTerrainPageSourceListener* pl)
166    {
167                BiTerrainPageSourceListenerManager::getSingleton().addListener(pl);
168    }
169    //-------------------------------------------------------------------------
170    void BiTerrainPageSource::removeListener(BiTerrainPageSourceListener* pl)
171    {
172                BiTerrainPageSourceListenerManager::getSingleton().removeListener(pl);
173
174    }
175    //-------------------------------------------------------------------------
176
177}
Note: See TracBrowser for help on using the repository browser.