~ubuntu-branches/debian/sid/ember/sid

« back to all changes in this revision

Viewing changes to src/components/ogre/SceneManagers/EmberPagingSceneManager/src/OgrePagingLandScapeSceneManager.cpp

  • Committer: Package Import Robot
  • Author(s): Olek Wojnar, Stephen M. Webb, Olek Wojnar
  • Date: 2016-08-06 18:39:19 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20160806183919-4g72j3flj7xe2stj
Tags: 0.7.2+dfsg-1
[ Stephen M. Webb ]
* debian/control: updated build-depends to newer minimum versions
  (closes: #704786)
* debian/control: updated Standards-Version to 3.9.4 (updated VCS-* fields)
* debian/patches/0001-ember.in-test-expr.patch: removed (fixed upstream)
* debian/patches/0002-add-update_lua_bindings.patch: removed (fixed upstream)
* debian/patches/0003-add-atlas-pkg.patch: removed (fixed upstream)
* debian/patches/0004-domain-bindings-lua-makefile.patch: refreshed
* debian/patches/0005-ember.in-prefix.patch: removed (fixed upstream)
* debian/patches/0006-spellcheck-similiar.patch: removed (fixed upstream)
* debian/patches/0007-revert-libwfut-version.patch: refreshed
* debian/patches/0008-replace-fastdeletegate-with-sigc++.patch: removed
 (fixed upstream)
* debian/patches/0009-spelling-bach.patch: removed (fixed upstream)
* debian/patches/0010-fix-ember-script-args.patch: removed (fixed upstream)
* debian/patches/0011-qualify-template-functions.patch: removed (fixed
  upstream)
* debian/patches/0012-fix-osdir-headers.patch: removed (fixed upstream)
* debian/patches/0013-remove-invalid-linker-flags.patch: removed (fixed
  upstream)
* debian/patches/0014-add-missing-ogrelodstrategy.patch: new
* debian/control: fixed Vcs-Browser URL
* debian/patches/0015-verbose-configure-errors.patch: new
* debian/patches/0016-boost-1.53.patch: new
* debian/control: bump boost build dependeny to 1.53

[ Olek Wojnar ]
* New upstream release (Closes: #799748)
* Add myself as new uploader
  - Remove Stephen Webb per his request
  - Thanks for all the contributions, Stephen!
* d/patches/0007-revert-libwfut-version.patch: removed (unnecessary)
* d/control
  - Remove pre-dependency on dpkg
  - Update standards to 3.9.8 (no changes)
  - Update Vcs lines for secure URIs
* Import patch from the wfmath package to replace MersenneTwister.h
  -- Avoids problems from ambiguous copyright of the original file
* Update dependencies for version 0.7.2
* Enable all hardening options
* Add three lintian overrides
  -- Ignore install into usr/bin (binary)
  -- Ignore .rc files needed for WIN32 build (source)
  -- Ignore false positive of spelling error (binary)
* d/copyright: Update contributors and dates
* d/rules
  -- Do not remove "sounddefinitions" directory
  -- Enable parallel build
  -- Do not install into games directories
  -- Remove dh_builddeb override since xz is now the default
* d/watch: update file extensions
* Remove three patches, add eight patches, update remaining patches
  -- 0004-domain-bindings-lua-makefile.patch (implemented upstream)
  -- 0014-add-missing-ogrelodstrategy.patch (implemented upstream)
  -- 0016-boost-1.53.patch (patch target file removed upstream)
  -- 0018-enable-subdir-objects.patch (Fix automake 1.14 warnings)
  -- 0019-update-boost-m4.patch (Fix invalid boost_major_version)
  -- 0020-remove-obsolete-includes.patch (Fix obsolete includes)
  -- 0021-GraphicalChangeAdapter-fix-for-newer-compilers.patch (Added)
  -- 0022-fix-typos.patch (Fix typos identified by lintian)
  -- 0023-add-keywords-to-desktop-file.patch (Add Keywords to .desktop file)
  -- 0024-fix-icon-location (Make icon location Icon Theme Spec-compliant)
  -- 0025-fix-duplicate-script-install.patch (Was causing build failures)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
        OgrePagingLandScapeSceneManager.cpp  -  description
3
 
        -------------------
4
 
        begin                : Mon May 12 2003
5
 
        copyright            : (C) 2003-2006 by Jose A Milan && Tuan Kuranes
6
 
        email                : spoke2@supercable.es && tuan.kuranes@free.fr
7
 
***************************************************************************/
8
 
 
9
 
/***************************************************************************
10
 
*                                                                         *
11
 
*   This program is free software; you can redistribute it and/or modify  *
12
 
*   it under the terms of the GNU Lesser General Public License as        *
13
 
*   published by the Free Software Foundation; either version 2 of the    *
14
 
*   License, or (at your option) any later version.                       *
15
 
*                                                                         *
16
 
***************************************************************************/
17
 
 
18
 
#include "OgrePagingLandScapePrecompiledHeaders.h"
19
 
 
20
 
 
21
 
 
22
 
#include "OgreRoot.h"
23
 
#include "OgreSceneManager.h"
24
 
#include "OgreVector2.h"
25
 
#include "OgreVector3.h"
26
 
#include "OgreColourValue.h"
27
 
#include "OgreMovableObject.h"
28
 
#include "OgreAxisAlignedBox.h"
29
 
#include "OgreCamera.h"
30
 
#include "OgreStringConverter.h"
31
 
#include "OgreSceneNode.h"
32
 
#include "OgreSimpleRenderable.h"
33
 
 
34
 
#include "OgrePagingLandScapeOptions.h"
35
 
#include "OgrePagingLandScapeCamera.h"
36
 
#include "OgrePagingLandScapeData2DManager.h"
37
 
#include "OgrePagingLandScapeRenderableManager.h"
38
 
#include "OgrePagingLandScapeTextureCoordMan.h"
39
 
#include "OgrePagingLandScapeRenderable.h"
40
 
#include "OgrePagingLandScapeTextureManager.h"
41
 
#include "OgrePagingLandScapeTexture.h"
42
 
#include "OgrePagingLandScapePageManager.h"
43
 
#include "OgrePagingLandScapeTile.h"
44
 
#include "OgrePagingLandScapeTileInfo.h"
45
 
#include "OgrePagingLandScapeTileManager.h"
46
 
#include "OgrePagingLandScapeRenderable.h"
47
 
#include "OgrePagingLandScapeRenderableManager.h"
48
 
#include "OgrePagingLandScapeAABSQ.h"
49
 
#include "OgrePagingLandScapeRaySceneQuery.h"
50
 
#include "OgrePagingLandScapeCamera.h"
51
 
#include "OgrePagingLandScapeMeshDecal.h"
52
 
 
53
 
#include "OgrePagingLandScapeListenerManager.h"
54
 
 
55
 
#include "OgrePagingLandScapeSceneManager.h"
56
 
 
57
 
#include "OgrePagingLandScapeHorizon.h"
58
 
 
59
 
namespace Ogre
60
 
{
61
 
 
62
 
    //-----------------------------------------------------------------------
63
 
    const String PagingLandScapeSceneManagerFactory::FACTORY_TYPE_NAME = "PagingLandScapeSceneManager";
64
 
    //-----------------------------------------------------------------------
65
 
    void PagingLandScapeSceneManagerFactory::initMetaData(void) const
66
 
    {
67
 
           mMetaData.typeName = FACTORY_TYPE_NAME;
68
 
           mMetaData.description = "Scene manager organising the scene on the basis of an octree, and paging heightmap when needed.";
69
 
           mMetaData.sceneTypeMask = ST_EXTERIOR_REAL_FAR; // support all types
70
 
           mMetaData.worldGeometrySupported = true;
71
 
    }
72
 
    //-----------------------------------------------------------------------
73
 
    SceneManager* PagingLandScapeSceneManagerFactory::createInstance(
74
 
           const String& instanceName)
75
 
    {
76
 
           return new PagingLandScapeSceneManager(instanceName);
77
 
    }
78
 
    //-----------------------------------------------------------------------
79
 
    void PagingLandScapeSceneManagerFactory::destroyInstance(SceneManager* instance)
80
 
    {
81
 
           delete instance;
82
 
    }
83
 
    //-----------------------------------------------------------------------
84
 
    PagingLandScapeSceneManager::PagingLandScapeSceneManager(const String& name) : 
85
 
            PagingLandScapeOctreeSceneManager(name),
86
 
            mData2DManager (0),
87
 
                mTextureManager (0),
88
 
                mTileManager (0),
89
 
                        mRenderableManager (0),
90
 
                        mIndexesManager (0),
91
 
                        mTexCoordManager (0),
92
 
                mPageManager (0),
93
 
            mHorizon (0),
94
 
                mNeedOptionsUpdate (false),
95
 
                //JEFF
96
 
                mWorldGeomIsSetup (false),
97
 
            // TK
98
 
            mWorldGeomIsInit (false),
99
 
            mBrushSize (5),
100
 
            mBrushScale (0.2f),
101
 
            mImpactInfo (0),
102
 
            mBrushCenter (Vector3::ZERO),
103
 
            mBrushArray (0), mCraterArray(0),
104
 
            mBrushArrayHeight (0),
105
 
            mBrushArrayWidth (0),
106
 
            mListenerManager(0),
107
 
            mOptions(0),
108
 
                        textureFormatChanged (false)
109
 
    {
110
 
            //showBoundingBoxes(true);
111
 
            //setDisplaySceneNodes(true);       
112
 
 
113
 
                mMeshDecalFactory = new PagingLandScapeMeshDecalFactory;
114
 
                if( !(Root::getSingleton().hasMovableObjectFactory("PagingLandScapeMeshDecal")) )
115
 
                        Root::getSingleton().addMovableObjectFactory( mMeshDecalFactory ); 
116
 
    }
117
 
    //-------------------------------------------------------------------------
118
 
    const String& PagingLandScapeSceneManager::getTypeName(void) const
119
 
    {
120
 
        return PagingLandScapeSceneManagerFactory::FACTORY_TYPE_NAME;
121
 
    }
122
 
    //-----------------------------------------------------------------------
123
 
    void PagingLandScapeSceneManager::PagingLandScapeOctreeResize()
124
 
    {       
125
 
        const Ogre::Real x = mOptions->maxScaledX;
126
 
        assert (mData2DManager);
127
 
        const Ogre::Real y = mData2DManager->getMaxHeight () * 4;
128
 
        const Ogre::Real z = mOptions->maxScaledZ;
129
 
        PagingLandScapeOctreeSceneManager::resize(AxisAlignedBox(-x , 0, -z, x, y, z));
130
 
    }
131
 
    //-----------------------------------------------------------------------
132
 
    void PagingLandScapeSceneManager::WorldDimensionChange()
133
 
    {       
134
 
        PagingLandScapeOctreeResize();
135
 
 
136
 
                assert (mPageManager);
137
 
                assert (mData2DManager);
138
 
                assert (mTextureManager);
139
 
        mPageManager->WorldDimensionChange();
140
 
        mData2DManager->WorldDimensionChange();
141
 
        mTextureManager->WorldDimensionChange();
142
 
    }
143
 
    //-------------------------------------------------------------------------
144
 
    void PagingLandScapeSceneManager::shutdown(void)
145
 
        {      
146
 
        clearScene();
147
 
 
148
 
        delete mOptions;
149
 
        mOptions = 0;
150
 
 
151
 
        delete mData2DManager;
152
 
        mData2DManager = 0;
153
 
        delete mTextureManager;
154
 
                mTextureManager = 0;
155
 
 
156
 
                if (mPageManager)
157
 
                        Root::getSingleton().removeFrameListener (mPageManager);
158
 
        delete mPageManager;
159
 
        mPageManager = 0;
160
 
 
161
 
        delete mListenerManager;
162
 
        mListenerManager = 0;
163
 
        delete mTileManager;
164
 
        mTileManager = 0;
165
 
        delete mRenderableManager;
166
 
        mRenderableManager = 0;
167
 
 
168
 
        delete mIndexesManager;
169
 
        mIndexesManager = 0;
170
 
        delete mTexCoordManager;
171
 
        mTexCoordManager = 0;
172
 
 
173
 
        delete[] mCraterArray;
174
 
        mCraterArray = 0;
175
 
 
176
 
                Root::getSingleton().removeMovableObjectFactory( mMeshDecalFactory );
177
 
                delete mMeshDecalFactory;
178
 
    }
179
 
    //-----------------------------------------------------------------------
180
 
    PagingLandScapeSceneManager::~PagingLandScapeSceneManager()
181
 
        {
182
 
                shutdown();
183
 
    } 
184
 
    //-------------------------------------------------------------------------
185
 
    void PagingLandScapeSceneManager::setWorldGeometry(DataStreamPtr& stream, const String& typeName)
186
 
    {
187
 
                if (!mListenerManager)
188
 
                mListenerManager = new PagingLandScapeListenerManager(this);
189
 
        // Clear out any existing world resources (if not default)
190
 
        if (ResourceGroupManager::getSingleton().getWorldResourceGroupName() != 
191
 
            ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME)
192
 
        {
193
 
            ResourceGroupManager::getSingleton().clearResourceGroup(
194
 
                ResourceGroupManager::getSingleton().getWorldResourceGroupName());
195
 
        }
196
 
 
197
 
        if (mWorldGeomIsSetup)
198
 
                    clearScene();
199
 
        if (!mOptions)
200
 
                        mOptions = new PagingLandScapeOptions(this);   
201
 
                InitScene ();
202
 
            // Load the configuration file
203
 
                if (!stream.isNull ())
204
 
                {
205
 
                        if (mOptions->load(stream))
206
 
                            loadScene ();
207
 
                }
208
 
                // Check if we need to set the camera
209
 
                if (!mOptions->primaryCamera && !mCameras.empty ())
210
 
                {
211
 
                        PagingLandScapeCamera* c = static_cast <PagingLandScapeCamera*> (mCameras.begin()->second);
212
 
                        mOptions->setPrimaryCamera (c);
213
 
                }
214
 
    }
215
 
    //-----------------------------------------------------------------------
216
 
    void PagingLandScapeSceneManager::setWorldGeometry(const String& filename)
217
 
        {
218
 
                if (filename.empty())
219
 
                {
220
 
#ifdef PLSM2_EIHORT
221
 
            DataStreamPtr myStream;
222
 
#else
223
 
                        DataStreamPtr myStream (0);
224
 
#endif
225
 
                        myStream.setNull();
226
 
                        setWorldGeometry (myStream);
227
 
                        return;
228
 
                }               
229
 
 
230
 
                // try to open in the current folder first
231
 
                std::ifstream fs;
232
 
                fs.open(filename.c_str(), std::ios::in | std::ios::binary);
233
 
                if (fs)
234
 
                {
235
 
                        // Wrap as a stream
236
 
                        DataStreamPtr myStream (OGRE_NEW FileStreamDataStream (filename, &fs, false));
237
 
                        setWorldGeometry (myStream);
238
 
                        return;
239
 
                }
240
 
 
241
 
                // otherwise try resource system
242
 
                DataStreamPtr myStream (ResourceGroupManager::getSingleton().openResource(filename));
243
 
                setWorldGeometry (myStream);    
244
 
    }    
245
 
    //-----------------------------------------------------------------------
246
 
    void PagingLandScapeSceneManager::InitScene ()
247
 
    {        
248
 
        // Only initialized once
249
 
        // not to loose use listeners
250
 
        if (!mListenerManager)
251
 
                mListenerManager = new PagingLandScapeListenerManager(this);
252
 
            if (!mTileManager)
253
 
                mTileManager = new PagingLandScapeTileManager(this);        
254
 
        if (!mData2DManager)
255
 
                mData2DManager = new PagingLandScapeData2DManager(this, mOptions);        //
256
 
        if (!mTextureManager)
257
 
            mTextureManager = new PagingLandScapeTextureManager(this);
258
 
                if (!mIndexesManager)
259
 
                        mIndexesManager = new PagingLandScapeIndexBufferManager(this);
260
 
                if (!mTexCoordManager)
261
 
                        mTexCoordManager = new PagingLandScapeTextureCoordinatesManager(this);  
262
 
            if (!mRenderableManager)
263
 
                mRenderableManager = new PagingLandScapeRenderableManager(this); 
264
 
        if (!mCraterArray)
265
 
                        resizeCrater(); 
266
 
                if (!mPageManager)
267
 
                {
268
 
                        mPageManager = new PagingLandScapePageManager(this);
269
 
                        Root::getSingleton().addFrameListener(mPageManager);
270
 
 
271
 
                        mPageManager->setWorldGeometryRenderQueue (static_cast<Ogre::RenderQueueGroupID>(SceneManager::getWorldGeometryRenderQueue()));
272
 
                        mData2DManager->setPageManager(this);
273
 
                }
274
 
    }
275
 
    //-----------------------------------------------------------------------
276
 
    void PagingLandScapeSceneManager::loadScene()
277
 
    { 
278
 
        if (!mWorldGeomIsSetup)
279
 
            {
280
 
            // listen to frames to update queues independently of cam numbers.
281
 
                        // cannot do that if remove is called in same frame before it removes it
282
 
                        // ...
283
 
            //Root::getSingleton().addFrameListener(mPageManager); 
284
 
                        mPageManager->setEnabled (true);
285
 
 
286
 
            mTileManager->load();
287
 
                mData2DManager->load();
288
 
                mTextureManager->load();
289
 
                        mIndexesManager->load();
290
 
                        mTexCoordManager->load();
291
 
            if (mOptions->VisMap)
292
 
            {
293
 
                assert (!mHorizon);
294
 
                mHorizon = new PagingLandScapeHorizon(mOptions);
295
 
            }
296
 
            mPageManager->load();
297
 
            mRenderableManager->load();
298
 
 
299
 
            // reset camera paging
300
 
            // register existing camera in node
301
 
            CameraList::iterator i = mCameras.begin();
302
 
            for (; i != mCameras.end(); ++i)
303
 
            {
304
 
                // Notify occlusion system
305
 
                PagingLandScapeCamera *c = static_cast <PagingLandScapeCamera *> (i->second);
306
 
                assert (c);
307
 
                c->resetPaging ();
308
 
            }       
309
 
            PagingLandScapeOctreeResize();
310
 
 
311
 
          
312
 
 
313
 
            mWorldGeomIsSetup = true;
314
 
 
315
 
 
316
 
        }
317
 
    }
318
 
    //-----------------------------------------------------------------------
319
 
    void PagingLandScapeSceneManager::clearScene(void)
320
 
    {
321
 
        //SceneManager::getRenderQueue()->clear();
322
 
            PagingLandScapeSceneManager::resetScene();
323
 
            //Call the default        
324
 
        PagingLandScapeOctreeSceneManager::clearScene();
325
 
    }
326
 
    //-----------------------------------------------------------------------
327
 
    void PagingLandScapeSceneManager::resetScene(void)
328
 
    {
329
 
            if (mWorldGeomIsSetup)
330
 
        {
331
 
                        //Root::getSingleton().removeFrameListener (mPageManager);
332
 
                        mPageManager->setEnabled (false);
333
 
                    // clear the Managers
334
 
                    mPageManager->clear();
335
 
                    mTextureManager->clear();
336
 
                    mData2DManager->clear();
337
 
            if (mHorizon)
338
 
            {
339
 
                    delete mHorizon;
340
 
                mHorizon = 0;
341
 
            }
342
 
            // clear queues
343
 
            mRenderableManager->clear();
344
 
                        mTileManager->clear();
345
 
 
346
 
            // unload cached map info
347
 
                        mOptions->clearTileInfo();
348
 
 
349
 
                        // clear hardware buffer caches
350
 
                        //mIndexesManager->clear(); //don't clear to keep index buffer if tilesize
351
 
                        //mTexCoordManager->clear(); //don't clear to keep index buffer if tilesize
352
 
 
353
 
                    mWorldGeomIsSetup = false;
354
 
                    mWorldGeomIsInit = false;
355
 
 
356
 
            //PagingLandScapeOctreeSceneManager::clearScene();
357
 
            }
358
 
    }
359
 
    //-----------------------------------------------------------------------
360
 
    void PagingLandScapeSceneManager::_updateSceneGraph(Camera * cam)
361
 
    {
362
 
            // entry into here could come before setWorldGeometry 
363
 
        // got called which could be disastrous
364
 
            // so check for init
365
 
        assert(mPageManager);
366
 
        if (cam == mOptions->primaryCamera && isRenderQueueToBeProcessed(mPageManager->getPageRenderQueue()))
367
 
        {
368
 
                if (mWorldGeomIsInit)
369
 
            {
370
 
               mPageManager->updatePaging (static_cast<PagingLandScapeCamera *> (cam)); 
371
 
            }
372
 
            else
373
 
            {             
374
 
                if (mWorldGeomIsSetup)
375
 
                {
376
 
                                    mOptions->calculateCFactor (); 
377
 
                                    assert (mPageManager);
378
 
                    if (mOptions->BigImage)
379
 
                    {
380
 
                        assert (mTextureManager);
381
 
 
382
 
                        mTextureManager->setMapMaterial();
383
 
                        mPageManager->setMapMaterial();
384
 
                    } 
385
 
                    mWorldGeomIsInit = true;
386
 
                    mPageManager->updatePaging (static_cast<PagingLandScapeCamera *> (cam)); 
387
 
                }
388
 
            } 
389
 
        }
390
 
        // Call the default
391
 
            PagingLandScapeOctreeSceneManager::_updateSceneGraph(cam);            
392
 
    }
393
 
 
394
 
        AxisAlignedBoxSceneQuery* PagingLandScapeSceneManager::createAABBQuery( const AxisAlignedBox& box, 
395
 
                                                                                                                                                        unsigned long mask )
396
 
        {
397
 
                PagingLandScapeAxisAlignedBoxSceneQuery* q = new PagingLandScapeAxisAlignedBoxSceneQuery(this);
398
 
                q->setBox(box);
399
 
                q->setQueryMask(mask);
400
 
                return q;
401
 
        }
402
 
 
403
 
    //----------------------------------------------------------------------------
404
 
    RaySceneQuery* PagingLandScapeSceneManager::createRayQuery(const Ray& ray, unsigned long mask)
405
 
    {
406
 
            PagingLandScapeRaySceneQuery* q = new PagingLandScapeRaySceneQuery(this);
407
 
            q->setRay(ray);
408
 
            q->setQueryMask(mask);
409
 
            return q;
410
 
    }
411
 
    //-------------------------------------------------------------------------
412
 
    bool PagingLandScapeSceneManager::intersectSegment(const Ogre::Vector3 & raybegin, 
413
 
                                                    const Ogre::Vector3 & rayend, 
414
 
                                                    Ogre::Vector3 * rayresult)
415
 
    {
416
 
        return intersectSegmentTerrain (raybegin, rayend, rayresult);
417
 
    }
418
 
    //-------------------------------------------------------------------------
419
 
    bool PagingLandScapeSceneManager::intersectSegmentTerrain (const Ogre::Vector3 & raybegin, 
420
 
                                                                const Ogre::Vector3 & raydir, 
421
 
                                                                Ogre::Vector3 * rayresult)
422
 
    {
423
 
        Ogre::Vector3 raystart (raybegin);
424
 
                assert (mPageManager && mData2DManager);
425
 
 
426
 
                const Ogre::Real maxHeight = mData2DManager->getMaxHeight ();
427
 
                
428
 
                if (raystart.y > maxHeight)
429
 
                {
430
 
                        // find an new ray start that is under highest terrain height
431
 
                        // so that we do not test intersection between terrain and ray
432
 
                        // on ray part where Y > maxHeight
433
 
 
434
 
                        // First check if not parallel to terrain
435
 
                        if (Math::Abs(raydir.y) < std::numeric_limits<Real>::epsilon())
436
 
                        {
437
 
                                // Parallel ?
438
 
                                *rayresult = Ogre::Vector3(-1.0f, -1.0f, -1.0f);
439
 
                                return false;
440
 
                        }
441
 
                        // now ray should begin at a pertinent place.
442
 
                        const Ogre::Real t = -(raystart.y-maxHeight)/raydir.y;
443
 
                        raystart += raydir*t;
444
 
                        if (raystart.y <= mData2DManager->getInterpolatedWorldHeight(raystart.x, raystart.z))
445
 
                        {
446
 
                                *rayresult = raystart;
447
 
                                return true;
448
 
                        }
449
 
                } 
450
 
 
451
 
        PagingLandScapeTile * t = mPageManager->getTile (raystart.x, raystart.z, false);
452
 
        if (t == 0)
453
 
        {
454
 
            // we're outside LandScape
455
 
            #ifndef _STRICT_LandScape
456
 
                // if you want to be able to intersect from a point outside the canvas
457
 
                //const int pageSize = mOptions->PageSize - 1;
458
 
                const Ogre::Real W = mOptions->maxScaledX;
459
 
                const Ogre::Real H = mOptions->maxScaledZ;
460
 
                const Ogre::Real maxHeight = mData2DManager->getMaxHeight ();
461
 
                
462
 
                if (W != 0 && H != 0) {
463
 
                                        // while ray is outside but raydir going inside
464
 
                                        while ((raystart.y < 0.0f && raydir.y > 0.0f) || 
465
 
                                                        (raystart.y > maxHeight && raydir.y < 0.0f) || 
466
 
        
467
 
                                                        (raystart.x < -W && raydir.x > 0.0f) || 
468
 
                                                        (raystart.x > W  && raydir.x < 0.0f) || 
469
 
        
470
 
                                                        (raystart.z < -H && raydir.z > 0.0f) || 
471
 
                                                        (raystart.z > H  && raydir.z < 0.0f)) 
472
 
                                                raystart += raydir;
473
 
                                }
474
 
 
475
 
                if (raystart.y < 0.0f || raystart.y >= maxHeight ||
476
 
                    raystart.x < -W || raystart.x > W  || 
477
 
                    raystart.z < -H || raystart.z > H)
478
 
                {
479
 
                    *rayresult = Ogre::Vector3(-1.0f, -1.0f, -1.0f);
480
 
                    return false;
481
 
                }
482
 
                t = mPageManager->getTile (raystart.x, raystart.z, false);
483
 
                if (t == 0)
484
 
                    return false;
485
 
            #else //_STRICT_LandScape
486
 
                // if you don't want to be able to intersect from a point outside the canvas
487
 
                *rayresult = Ogre::Vector3(-1.0f, -1.0f, -1.0f);
488
 
                return false;
489
 
            #endif //_STRICT_LandScape
490
 
        }
491
 
 
492
 
        bool impact;
493
 
 
494
 
 
495
 
        //special case...
496
 
//         if (raydir.x == 0.0f && raydir.z == 0.0f)
497
 
//         {
498
 
//             if (raystart.y <=  mData2DManager->getInterpolatedWorldHeight(raystart.x, raystart.z))
499
 
//             {
500
 
//                 *rayresult = raystart;
501
 
//                 impact = true;
502
 
//             }
503
 
//             impact = false;
504
 
//         }      
505
 
//         else
506
 
        {
507
 
                        // should we scale ?
508
 
//                      const Ogre::Vector3 rayDirScaled ( 
509
 
//                              raydir.x * mOptions->scale.x,
510
 
//                              raydir.y * mOptions->scale.y,
511
 
//                              raydir.z * mOptions->scale.z);
512
 
 
513
 
                        if (raystart.y >= mData2DManager->getInterpolatedWorldHeight(raystart.x, raystart.z))
514
 
                        {
515
 
                                impact = t->intersectSegmentFromAbove(raystart, raydir, rayresult);
516
 
                        }
517
 
                        else
518
 
                        {
519
 
                                impact = t->intersectSegmentFromBelow(raystart, raydir, rayresult);
520
 
                        }
521
 
 
522
 
        }
523
 
        return impact;
524
 
    } 
525
 
    //-------------------------------------------------------------------------
526
 
    void PagingLandScapeSceneManager::resizeCrater ()
527
 
    {
528
 
        const int radius = mBrushSize;
529
 
        const unsigned int diameter = static_cast <unsigned int> (radius) * 2;
530
 
 
531
 
        mBrushArrayHeight = diameter;
532
 
        mBrushArrayWidth = diameter;
533
 
        
534
 
        delete [] mCraterArray;
535
 
        const unsigned int array_size = diameter * diameter;
536
 
        mCraterArray = new Real[array_size];
537
 
        memset (mCraterArray, 0, array_size * sizeof(Real));
538
 
 
539
 
        // Calculate the minimum X value 
540
 
        // make sure it is still on the height map
541
 
        const int Zmin = -radius;
542
 
        const int Zmax = radius;
543
 
 
544
 
                const int Xmin = -radius;
545
 
                const int Xmax = radius;
546
 
 
547
 
        // (goes through each X value)
548
 
                unsigned int array_indx = 0;
549
 
                const int radiussquare = radius * radius;
550
 
                //const Ogre::Real scaler = mOptions->scale.y;// / radius;
551
 
                const Ogre::Real scaler = 1.0 / radius;
552
 
        for (int Zcurr = Zmin; Zcurr < Zmax; Zcurr++)
553
 
        {
554
 
            const Ogre::Real Precalc = radiussquare - (Zcurr * Zcurr);
555
 
            if (Precalc > 1.0f)
556
 
            {
557
 
                // Determine the minimum and maximum X value for that 
558
 
                                // line in the circle (that Z value)
559
 
                //const int Xmax = static_cast<int> (Math::Sqrt(Precalc));            
560
 
                //const int Xmin = - Xmax;
561
 
 
562
 
                unsigned int curr_indx = array_indx;// + Xmin + radius;
563
 
                // For each of those Z values, calculate the new Y value
564
 
                for (int Xcurr = Xmin; Xcurr < Xmax; Xcurr++)
565
 
                {
566
 
                    assert (curr_indx < array_size);
567
 
                    // Calculate the new theoretical height for the current point on the circle
568
 
                                        const Ogre::Real val = static_cast <Real> (Xcurr * Xcurr);
569
 
                                        const Ogre::Real diffPrecalc = Precalc - val;
570
 
                    mCraterArray[curr_indx] = std::min(static_cast <Real> (1.0), 
571
 
                                                                                                           std::max(static_cast <Real> (0.0), 
572
 
                                                                                                                                Math::Sqrt (diffPrecalc)* scaler)) ; 
573
 
                    curr_indx++;
574
 
                } // for (int Xcurr = Xmin; Xcurr < Xmax; Xcurr++)
575
 
            } // if (Precalc > 1.0f)             
576
 
                        array_indx += diameter;         
577
 
                        //array_indx += diameter;
578
 
        } // for (int Zcurr = Zmin; Zcurr < radius; Zcurr++)
579
 
        mBrushArray = mCraterArray;
580
 
    }
581
 
    //-----------------------------------------------------------------------
582
 
    void PagingLandScapeSceneManager::paint (const Ogre::Vector3 &impact)
583
 
    {
584
 
                if (mOptions->textureModifiable)
585
 
                {
586
 
                        const int X = static_cast<int> (impact.x / mOptions->scale.x);
587
 
                        const int Z = static_cast<int> (impact.z / mOptions->scale.z);
588
 
                
589
 
                        //const int pageSize = mOptions->PageSize - 1;
590
 
                
591
 
                        const int W =  static_cast<int> (mOptions->maxUnScaledX);
592
 
                        const int H =  static_cast<int> (mOptions->maxUnScaledZ);
593
 
 
594
 
                        if (X < -W || X > W || Z < -H || Z > H)
595
 
                                return;
596
 
 
597
 
                        const int brushW = static_cast<int> (mBrushArrayWidth);
598
 
                        // Calculate the minimum X value 
599
 
                        // make sure it is still on the height map
600
 
                        unsigned int xshift = 0;
601
 
                        int Xmin = static_cast<int> (-brushW * 0.5f) ;
602
 
                        if (Xmin + X < -W)
603
 
                        {
604
 
                                //assert  (Xmin + X + W > 0);
605
 
                                xshift = static_cast <unsigned int> (abs (Xmin + X + W));
606
 
                                Xmin = - X - W;
607
 
                        }
608
 
                        // Calculate the maximum X value
609
 
                        // make sure it is still on the height map
610
 
                        int Xmax = static_cast<int> (brushW * 0.5f) ;
611
 
                        if (Xmax + X > W)
612
 
                                Xmax = W - X;
613
 
                        const int brushH = static_cast<int> (mBrushArrayHeight); 
614
 
                        // Calculate the minimum Z value 
615
 
                        // make sure it is still on the height map
616
 
                        unsigned int zshift = 0;
617
 
                        int Zmin = - static_cast<int> (brushH * 0.5) ;
618
 
                        if (Zmin + Z < -H)
619
 
                        {
620
 
                                //assert  (Zmin + Z + H > 0);
621
 
                                zshift = static_cast <unsigned int> (abs (Zmin + Z + H));
622
 
                                Zmin = - Z - H;
623
 
                        }
624
 
                        // Calculate the maximum Z value
625
 
                        // make sure it is still on the height map
626
 
                        int Zmax = static_cast<int> (brushH * 0.5); 
627
 
                        if (Zmax + Z > H)
628
 
                                Zmax = H - Z;
629
 
 
630
 
                        // Main loop to draw the circle on the height map 
631
 
                        // (goes through each X value)
632
 
                        unsigned int array_indx = zshift*brushW;
633
 
                        for (int Zcurr = Zmin; Zcurr < Zmax; Zcurr++)
634
 
                        {                
635
 
                                // For each of those Z values, calculate the new Y value
636
 
                                unsigned int curr_indx = array_indx + xshift;
637
 
                                for (int Xcurr = Xmin; Xcurr < Xmax; Xcurr++)
638
 
                                {
639
 
                                        // get results by page index ?
640
 
                                        const Ogre::Real h = mBrushArray[curr_indx];
641
 
                                        // Make sure we do it for something.
642
 
                                        if (h - 0.005f > 0)
643
 
                                        {
644
 
                                                assert (h >= 0.0f && h <= 1.0f);
645
 
                                                const Ogre::Real bushForce = std::min(static_cast <Real> (1.0), h*mBrushScale);
646
 
                                                if (bushForce - 0.005f > 0)
647
 
                                                {
648
 
                                                        const Ogre::Vector3 currpoint (X + Xcurr, static_cast <Real> (0.0), Z + Zcurr);
649
 
                                                        assert (mPageManager&&  mData2DManager && mTextureManager);
650
 
                                                        PagingLandScapeTile * t = mPageManager->getTileUnscaled (currpoint.x, currpoint.z, false);                
651
 
                                                        if (t && t->isLoaded ())
652
 
                                                        { 
653
 
                                                                mImpactInfo = t->getInfo ();
654
 
                                                                // check page boundaries to modify any page, tile neighbour
655
 
                                                                // tells any tile modified to update at next frame
656
 
                                                                assert (curr_indx < mBrushArrayWidth*mBrushArrayHeight);   
657
 
                                                                mTextureManager->paint (currpoint, bushForce, mImpactInfo);
658
 
                                                        }// if (t && t->isLoaded ())   
659
 
                                                } 
660
 
                                        } // if (h != 0.0f)
661
 
                                        curr_indx++;
662
 
                                } // for (int Xcurr = Xmin; Xcurr < Xmax; Xcurr++)
663
 
                                array_indx += brushW;
664
 
                        } // for (int Zcurr = Zmin; Zcurr < Zmax; Zcurr++) 
665
 
                }
666
 
    }//-----------------------------------------------------------------------
667
 
    void PagingLandScapeSceneManager::setHeight (const Ogre::Vector3 &impact)
668
 
    {
669
 
        if (mOptions->Deformable)
670
 
        {
671
 
            const int X = static_cast<int> (impact.x / mOptions->scale.x);
672
 
            const int Z = static_cast<int> (impact.z / mOptions->scale.z);
673
 
 
674
 
            //const int pageSize = mOptions->PageSize - 1;
675
 
 
676
 
            const int W =  static_cast<int> (mOptions->maxUnScaledX);
677
 
            const int H =  static_cast<int> (mOptions->maxUnScaledZ);
678
 
 
679
 
            if (X < -W || X > W || Z < -H || Z > H)
680
 
                return;
681
 
 
682
 
            const int brushW = static_cast<int> (mBrushArrayWidth);
683
 
            // Calculate the minimum X value 
684
 
            // make sure it is still on the height map
685
 
            unsigned int xshift = 0;
686
 
            int Xmin = static_cast<int> (-brushW * 0.5f);
687
 
            if (Xmin + X < -W)
688
 
            {
689
 
                //assert  (Xmin + X + W > 0);
690
 
                xshift = static_cast <unsigned int> (abs (Xmin + X + W));
691
 
                Xmin = - X - W;
692
 
            }
693
 
            // Calculate the maximum X value
694
 
            // make sure it is still on the height map
695
 
            int Xmax = static_cast<int> (brushW * 0.5f) ;
696
 
            if (Xmax + X > W)
697
 
                Xmax = W - X;
698
 
            const int brushH = static_cast<int> (mBrushArrayHeight); 
699
 
            // Calculate the minimum Z value 
700
 
            // make sure it is still on the height map
701
 
            unsigned int zshift = 0;
702
 
            int Zmin = static_cast<int> (- brushH * 0.5f) ;
703
 
            if (Zmin + Z < -H)
704
 
            {
705
 
                //assert  (Zmin + Z + H > 0);
706
 
                zshift = static_cast <unsigned int> (abs (Zmin + Z + H));
707
 
                Zmin = - Z - H;
708
 
            }
709
 
            // Calculate the maximum Z value
710
 
            // make sure it is still on the height map
711
 
            int Zmax = static_cast<int> (brushH * 0.5f) ; 
712
 
            if (Zmax + Z > H)
713
 
                Zmax = H - Z;
714
 
 
715
 
                        const Ogre::Real Hscale = mOptions->scale.y * mBrushScale;
716
 
            // Main loop to draw the circle on the height map 
717
 
            // (goes through each X value)
718
 
            unsigned int array_indx = zshift*brushW;
719
 
            for (int Zcurr = Zmin; Zcurr < Zmax; Zcurr++)
720
 
            {                
721
 
                // For each of those Z values, calculate the new Y value
722
 
                unsigned int curr_indx = array_indx + xshift;
723
 
                for (int Xcurr = Xmin; Xcurr < Xmax; Xcurr++)
724
 
                {
725
 
                    // get results by page index ?
726
 
                    const Ogre::Real h = - mBrushArray[curr_indx] * mBrushScale * Hscale;
727
 
                    // Make sure we do it for something.
728
 
                    if (h != 0.0f)
729
 
                    {
730
 
                        const Ogre::Vector3 currpoint (X + Xcurr, 0.0f, Z + Zcurr);
731
 
                        assert (mPageManager&&  mData2DManager && mTextureManager);
732
 
                        PagingLandScapeTile * t = mPageManager->getTileUnscaled (currpoint.x, currpoint.z, false);                
733
 
                        if (t && t->isLoaded ())
734
 
                        { 
735
 
                            mImpactInfo = t->getInfo ();
736
 
                            // check page boundaries to modify any page, tile neighbour
737
 
                            // tells any tile modified to update at next frame
738
 
                            assert (curr_indx < mBrushArrayWidth*mBrushArrayHeight);                          
739
 
                            if (mData2DManager->setHeight (currpoint, h, mImpactInfo))
740
 
                                mTextureManager->deformHeight (currpoint, mImpactInfo);
741
 
                        } // if (t && t->isLoaded ())   
742
 
                    } // if (h != 0.0f)
743
 
                    curr_indx++;
744
 
                } // for (int Xcurr = Xmin; Xcurr < Xmax; Xcurr++)
745
 
                array_indx += brushW;
746
 
            } // for (int Zcurr = Zmin; Zcurr < Zmax; Zcurr++) 
747
 
        } // if (mOptions->Deformable)
748
 
    } 
749
 
    //-----------------------------------------------------------------------
750
 
    void PagingLandScapeSceneManager::deformHeight (const Ogre::Vector3 &impact)
751
 
    {
752
 
        if (mOptions->Deformable)
753
 
        {
754
 
            const int X = static_cast<int> (impact.x / mOptions->scale.x);
755
 
            const int Z = static_cast<int> (impact.z / mOptions->scale.z);
756
 
            
757
 
            //const int pageSize = mOptions->PageSize - 1;
758
 
            
759
 
            const int W =  static_cast<int> (mOptions->maxUnScaledX);
760
 
            const int H =  static_cast<int> (mOptions->maxUnScaledZ);
761
 
 
762
 
            if (X < -W || X > W || Z < -H || Z > H)
763
 
                return;
764
 
 
765
 
            const int brushW = static_cast<int> (mBrushArrayWidth);
766
 
            // Calculate the minimum X value 
767
 
            // make sure it is still on the height map
768
 
            unsigned int xshift = 0;
769
 
            int Xmin = static_cast<int> (-brushW * 0.5f);
770
 
            if (Xmin + X < -W)
771
 
            {
772
 
               //assert  (Xmin + X + W > 0);
773
 
                xshift = static_cast <unsigned int> (abs (Xmin + X + W));
774
 
                Xmin = - X - W;
775
 
            }
776
 
            // Calculate the maximum X value
777
 
            // make sure it is still on the height map
778
 
            int Xmax = static_cast<int> (brushW * 0.5f) ;
779
 
            if (Xmax + X > W)
780
 
                Xmax = W - X;
781
 
            const int brushH = static_cast<int> (mBrushArrayHeight); 
782
 
            // Calculate the minimum Z value 
783
 
            // make sure it is still on the height map
784
 
            unsigned int zshift = 0;
785
 
            int Zmin = static_cast<int> (- brushH * 0.5f) ;
786
 
            if (Zmin + Z < -H)
787
 
            {
788
 
                //assert  (Zmin + Z + H > 0);
789
 
                zshift = static_cast <unsigned int> (abs (Zmin + Z + H));
790
 
                Zmin = - Z - H;
791
 
            }
792
 
            // Calculate the maximum Z value
793
 
            // make sure it is still on the height map
794
 
            int Zmax = static_cast<int> (brushH * 0.5f) ; 
795
 
            if (Zmax + Z > H)
796
 
                Zmax = H - Z;
797
 
 
798
 
                        const Ogre::Real Hscale = mOptions->scale.y * mBrushScale;
799
 
 
800
 
            // Main loop to draw the circle on the height map 
801
 
            // (goes through each X value)
802
 
            unsigned int array_indx = zshift*brushW;
803
 
            for (int Zcurr = Zmin; Zcurr < Zmax; Zcurr++)
804
 
            {                
805
 
                // For each of those Z values, calculate the new Y value
806
 
                unsigned int curr_indx = array_indx + xshift;
807
 
                for (int Xcurr = Xmin; Xcurr < Xmax; Xcurr++)
808
 
                {
809
 
                    // get results by page index ?
810
 
            const Ogre::Real h = - mBrushArray[curr_indx] * Hscale;
811
 
                    // Make sure we do it for something.
812
 
                    if (h != 0.0f)
813
 
                    {
814
 
                        const Ogre::Vector3 currpoint (X + Xcurr, 0.0f, Z + Zcurr);
815
 
                        assert (mPageManager&&  mData2DManager && mTextureManager);
816
 
                        PagingLandScapeTile * t = mPageManager->getTileUnscaled (currpoint.x, currpoint.z, false);                
817
 
                        if (t && t->isLoaded ())
818
 
                        { 
819
 
                            mImpactInfo = t->getInfo ();
820
 
                            // check page boundaries to modify any page, tile neighbour
821
 
                            // tells any tile modified to update at next frame
822
 
                            assert (curr_indx < mBrushArrayWidth*mBrushArrayHeight);                          
823
 
                            if (mData2DManager->deformHeight (currpoint, h, mImpactInfo))
824
 
                                 mTextureManager->deformHeight (currpoint, mImpactInfo);
825
 
                        } // if (t && t->isLoaded ())   
826
 
                    } // if (h != 0.0f)
827
 
                    curr_indx++;
828
 
                } // for (int Xcurr = Xmin; Xcurr < Xmax; Xcurr++)
829
 
                array_indx += brushW;
830
 
            } // for (int Zcurr = Zmin; Zcurr < Zmax; Zcurr++) 
831
 
        } // if (mOptions->Deformable)
832
 
    } 
833
 
    //-----------------------------------------------------------------------
834
 
    void PagingLandScapeSceneManager::getAreaHeight (const Ogre::Vector3 &impact)
835
 
    {
836
 
        const int X = static_cast<int> (impact.x / mOptions->scale.x);
837
 
        const int Z = static_cast<int> (impact.z / mOptions->scale.z);
838
 
        
839
 
        //const int pageSize = mOptions->PageSize - 1;
840
 
        
841
 
        const int W =  static_cast<int> (mOptions->maxUnScaledX);
842
 
        const int H =  static_cast<int> (mOptions->maxUnScaledZ);
843
 
 
844
 
        if (X < -W || X > W || Z < -H || Z > H)
845
 
            return;
846
 
 
847
 
        const int brushW = static_cast<int> (mBrushArrayWidth);
848
 
        // Calculate the minimum X value 
849
 
        // make sure it is still on the height map
850
 
        unsigned int xshift = 0;
851
 
        int Xmin = static_cast<int> (-brushW * 0.5f);
852
 
        if (Xmin + X < -W)
853
 
        {
854
 
            //assert  (Xmin + X + W > 0);
855
 
            xshift = static_cast <unsigned int> (abs (Xmin + X + W));
856
 
            Xmin = - X - W;
857
 
        }
858
 
        // Calculate the maximum X value
859
 
        // make sure it is still on the height map
860
 
        int Xmax = static_cast<int> (brushW * 0.5f) ;
861
 
        if (Xmax + X > W)
862
 
            Xmax = W - X;
863
 
        const int brushH = static_cast<int> (mBrushArrayHeight); 
864
 
        // Calculate the minimum Z value 
865
 
        // make sure it is still on the height map
866
 
        unsigned int zshift = 0;
867
 
        int Zmin = static_cast<int> (- brushH * 0.5f) ;
868
 
        if (Zmin + Z < -H)
869
 
        {
870
 
            //assert  (Zmin + Z + H > 0);
871
 
            zshift = static_cast <unsigned int> (abs (Zmin + Z + H));
872
 
            Zmin = - Z - H;
873
 
        }
874
 
        // Calculate the maximum Z value
875
 
        // make sure it is still on the height map
876
 
        int Zmax = static_cast<int> (brushH * 0.5f) ; 
877
 
        if (Zmax + Z > H)
878
 
            Zmax = H - Z;
879
 
 
880
 
                const unsigned int pSize = mOptions->PageSize - 1;
881
 
                const Ogre::Real Hscale = 1 / (mOptions->scale.y * mBrushScale);
882
 
        // Main loop to draw the circle on the height map 
883
 
        // (goes through each X value)
884
 
        unsigned int array_indx = zshift*brushW;
885
 
        for (int Zcurr = Zmin; Zcurr < Zmax; Zcurr++)
886
 
        {                
887
 
            // For each of those Z values, calculate the new Y value
888
 
            unsigned int curr_indx = array_indx + xshift;
889
 
            for (int Xcurr = Xmin; Xcurr < Xmax; Xcurr++)
890
 
            {
891
 
                const Ogre::Vector3 currpoint (X + Xcurr, 0.0f, Z + Zcurr);
892
 
                assert (mPageManager&&  mData2DManager && mTextureManager);
893
 
                PagingLandScapeTile * t = mPageManager->getTileUnscaled (currpoint.x, currpoint.z, false);                
894
 
                if (t && t->isLoaded ())
895
 
                { 
896
 
                    mImpactInfo = t->getInfo ();
897
 
                    // check page boundaries to modify any page, tile neighbour
898
 
                    // tells any tile modified to update at next frame
899
 
                    assert (curr_indx < mBrushArrayWidth*mBrushArrayHeight);
900
 
                    
901
 
                    // adjust x and z to be local to page
902
 
                    const unsigned int x = static_cast<unsigned int> (currpoint.x
903
 
                                                        - mImpactInfo->mPageX * pSize
904
 
                                                        + W);
905
 
                    const unsigned int z = static_cast<unsigned int> (currpoint.z
906
 
                                                        - mImpactInfo->mPageZ * pSize
907
 
                                                        + H);
908
 
                    mBrushArray[curr_indx] = mData2DManager->getHeight(mImpactInfo->mPageX, 
909
 
                                                                        mImpactInfo->mPageZ,
910
 
                                                                        x, 
911
 
                                                                        z) 
912
 
                                                                                        * 
913
 
                                                                                        Hscale;
914
 
                     
915
 
                  
916
 
                } // if (t && t->isLoaded ())   
917
 
                
918
 
                curr_indx++;
919
 
            } // for (int Xcurr = Xmin; Xcurr < Xmax; Xcurr++)
920
 
            array_indx += brushW;
921
 
        } // for (int Zcurr = Zmin; Zcurr < Zmax; Zcurr++)         
922
 
    }
923
 
    //-----------------------------------------------------------------------
924
 
    bool PagingLandScapeSceneManager::setOption(const String& strKey, const void* pValue)
925
 
    {
926
 
        //listeners
927
 
        if (StringUtil::endsWith(strKey, "listener", true))
928
 
        {
929
 
            if (mListenerManager->setOption (strKey, pValue))
930
 
                                return true;
931
 
        } 
932
 
 
933
 
        if (StringUtil::startsWith(strKey, "pause", true))
934
 
        {
935
 
            mPageManager->setEnabled( ! *(const_cast < bool * > (static_cast < const bool * >(pValue))));
936
 
        } 
937
 
 
938
 
        // deformation and painting
939
 
        if (strKey == "BrushArray")
940
 
            {
941
 
                    mBrushArray =  const_cast <Ogre::Real * > (static_cast < const Ogre::Real * >(pValue));
942
 
                    return true;
943
 
            }
944
 
        if (strKey == "BrushArrayHeight")
945
 
            {
946
 
                    mBrushArrayHeight = * static_cast < const unsigned int * > (pValue);
947
 
            return true;
948
 
            }
949
 
        if (strKey == "BrushArrayWidth")
950
 
            {
951
 
                    mBrushArrayWidth = * static_cast < const unsigned int * > (pValue);
952
 
            return true;
953
 
            }
954
 
        if (strKey == "BrushScale")
955
 
            {
956
 
                    mBrushScale = * static_cast < const Ogre::Real * >  (pValue) ;
957
 
            return true;
958
 
            }
959
 
        if (strKey == "BrushSize")
960
 
            {
961
 
                    mBrushSize = * static_cast < const unsigned int * > (pValue);
962
 
            resizeCrater();
963
 
            return true;
964
 
        }
965
 
        if (strKey == "setHeightCenter")
966
 
        {
967
 
            mBrushCenter = * static_cast < const Ogre::Vector3 * > (pValue);
968
 
            setHeight (mBrushCenter);
969
 
            return true;
970
 
 
971
 
        }
972
 
        if (strKey == "DeformationCenter")
973
 
            {
974
 
                    mBrushCenter = * static_cast < const Ogre::Vector3 * > (pValue);
975
 
            deformHeight (mBrushCenter);
976
 
            return true;
977
 
            
978
 
        }
979
 
        if (strKey == "fillBrushArray")
980
 
            {
981
 
                    mBrushCenter = * static_cast < const Ogre::Vector3 * > (pValue);
982
 
            getAreaHeight (mBrushCenter);
983
 
            return true;         
984
 
        }
985
 
        if (strKey == "PaintCenter")
986
 
            {
987
 
                    mBrushCenter = * static_cast < const Ogre::Vector3 * > (pValue);
988
 
            paint(mBrushCenter);
989
 
            return true;
990
 
            }
991
 
        if (strKey == "setPaintChannelValues")
992
 
            {
993
 
                        mTextureManager->setPaintChannelValues ( 
994
 
                        static_cast < const std::vector<Real>  *>
995
 
                                                (pValue)
996
 
                                                );
997
 
            return true;
998
 
            }
999
 
 
1000
 
                if (strKey == "renderTextureModeToBaseTextures")
1001
 
                {
1002
 
                        const String alternateMaterial = *static_cast < const String * > (pValue);
1003
 
                        renderBaseTextures(alternateMaterial);
1004
 
                }
1005
 
 
1006
 
                // Map Changes
1007
 
                if (strKey == "LoadMap")
1008
 
                {
1009
 
                        const String textureFormatName(mOptions->getCurrentTextureFormat ());
1010
 
 
1011
 
                        PagingLandScapeSceneManager::resetScene();              
1012
 
                        PagingLandScapeSceneManager::loadScene ();
1013
 
 
1014
 
                        textureFormatChanged = false;
1015
 
 
1016
 
                        return true;
1017
 
                }  
1018
 
 
1019
 
        if (strKey == "CurrentMap")
1020
 
            {
1021
 
            const String CurrentMapName = *static_cast < const String * > (pValue);
1022
 
                        mOptions->setCurrentMapName (CurrentMapName);
1023
 
                    return true;
1024
 
            }  
1025
 
        if (strKey == "InsertNewMap")
1026
 
            {
1027
 
            const String CurrentMapName = *static_cast < const String * > (pValue);
1028
 
                mOptions->insertMap(CurrentMapName);    
1029
 
                    return true;
1030
 
            }
1031
 
        // TextureFormat changes
1032
 
        if (strKey == "CurrentTextureFormat")
1033
 
            {
1034
 
            // Override File TextureFormat
1035
 
                        mOptions->setTextureFormat (*static_cast < const String * > (pValue));
1036
 
                        textureFormatChanged = true;
1037
 
                    return true;
1038
 
                }
1039
 
                // TextureFormat changes
1040
 
                if (strKey == "InsertTextureFormat")
1041
 
                {
1042
 
                        // Override File TextureFormat
1043
 
                        mOptions->insertTextureFormat (*static_cast < const String * > (pValue));
1044
 
                        return true;
1045
 
                }
1046
 
        if (strKey == "PageUpdate")
1047
 
                {
1048
 
                        const Vector2 page = *static_cast < const Vector2 * > (pValue);
1049
 
 
1050
 
                        // Reload Data. ALso must reload pages that depend on this
1051
 
                        mData2DManager->reload (page.x, page.y);
1052
 
                        mTextureManager->reload(page.x, page.y);
1053
 
                        if (page.x > 0)
1054
 
            {
1055
 
                mData2DManager->reload (page.x-1, page.y);
1056
 
                            mTextureManager->reload(page.x-1, page.y);
1057
 
            }
1058
 
                        if (page.y > 0)
1059
 
            {
1060
 
                            mTextureManager->reload(page.x, page.y-1);
1061
 
                                mData2DManager->reload (page.x, page.y-1);
1062
 
            }
1063
 
                        if (page.x > 0 && page.y > 0)
1064
 
            { 
1065
 
                                mData2DManager->reload (page.x-1, page.y-1);
1066
 
                            mTextureManager->reload(page.x-1, page.y-1);
1067
 
            }
1068
 
 
1069
 
                        // Now reload pages
1070
 
                        //mPageManager::getSingleton().getPage(page.x, page.y)->reload();
1071
 
                }  
1072
 
                
1073
 
        if (strKey == "LoadNow")
1074
 
                {
1075
 
            assert (mPageManager);
1076
 
                    if (mOptions->max_preload_pages*mOptions->max_preload_pages >= mOptions->NumPages)
1077
 
            {
1078
 
                // Configuration file is telling us to pre-load all pages at startup.
1079
 
                for (unsigned int pageY = 0; pageY < mOptions->world_height; pageY++)
1080
 
                {
1081
 
                    for (unsigned int pageX = 0; pageX < mOptions->world_width; pageX++)
1082
 
                    {
1083
 
                        PagingLandScapePage * const p = mPageManager->getPage(pageX, pageY);
1084
 
                        p->load();
1085
 
                        mPageManager->addLoadedPage(p);
1086
 
 
1087
 
                    }
1088
 
                }
1089
 
                if (mOptions->primaryCamera)
1090
 
                    mPageManager->loadNow (mOptions->primaryCamera);
1091
 
            }
1092
 
            else if (pValue)
1093
 
            {
1094
 
                            PagingLandScapeCamera *cam = const_cast <PagingLandScapeCamera *> (static_cast < const PagingLandScapeCamera * > (pValue));
1095
 
                mPageManager->loadNow (cam);
1096
 
            }                
1097
 
        }
1098
 
        if (strKey == "ResetScene")
1099
 
        {
1100
 
            if( * static_cast < const bool * > (pValue) )
1101
 
                PagingLandScapeSceneManager::resetScene();         
1102
 
 
1103
 
            return true;
1104
 
        }  
1105
 
                if (mOptions->setOption(strKey, pValue) == true)
1106
 
        {
1107
 
            return true;
1108
 
        }       
1109
 
        if (PagingLandScapeOctreeSceneManager::setOption (strKey, pValue) == true)
1110
 
        {
1111
 
            return true;
1112
 
        }       
1113
 
               
1114
 
    
1115
 
            return false;
1116
 
    }
1117
 
 
1118
 
    //-----------------------------------------------------------------------
1119
 
        bool PagingLandScapeSceneManager::getOption(const String& strKey, void* pDestValue)
1120
 
    {
1121
 
        if (strKey == "h" || strKey == "getHeightAt")
1122
 
        {
1123
 
            Ogre::Vector3 *p = static_cast < Ogre::Vector3 * > (pDestValue);
1124
 
            p->y = getHeightAt (p->x, p->z);
1125
 
            return true;
1126
 
        }
1127
 
        if (strKey == "s" || strKey == "getSlopeAt")
1128
 
        {
1129
 
            Ogre::Vector3 *p = static_cast < Ogre::Vector3 * > (pDestValue);
1130
 
            p->y = getSlopeAt (p->x, p->z);
1131
 
            return true;
1132
 
        }
1133
 
        if (StringUtil::startsWith(strKey, "pause", true))
1134
 
        {
1135
 
           * (static_cast < bool * > (pDestValue)) = !mPageManager->isEnabled();
1136
 
           return true;
1137
 
        } 
1138
 
 
1139
 
        // heightfield data an pos info
1140
 
        if (strKey == "MapBoundaries")
1141
 
            {
1142
 
            AxisAlignedBox *box = static_cast < AxisAlignedBox * > (pDestValue);
1143
 
            
1144
 
            box->setExtents(-mOptions->maxScaledX,
1145
 
                            0,
1146
 
                            -mOptions->maxScaledZ,
1147
 
                            mOptions->maxScaledX,
1148
 
                            mOptions->scale.y,
1149
 
                            mOptions->maxScaledZ);
1150
 
                    return true;
1151
 
            
1152
 
        }
1153
 
        if (strKey == "GlobalToPage")
1154
 
            {
1155
 
            Ogre::Vector3 *pos = static_cast < Ogre::Vector3 * > (pDestValue);
1156
 
            mPageManager->getGlobalToPage (pos->x, pos->z);
1157
 
                    return true;            
1158
 
        } 
1159
 
        if (strKey == "getAreaSize")
1160
 
            {
1161
 
            Ogre::Vector3 *vertices_array = static_cast < Ogre::Vector3 * > (pDestValue);
1162
 
 
1163
 
            mPageManager->getGlobalToPage (vertices_array[0].x, vertices_array[0].z);
1164
 
            mPageManager->getGlobalToPage (vertices_array[1].x, vertices_array[1].z);
1165
 
            mPageManager->getGlobalToPage (vertices_array[2].x, vertices_array[2].z);
1166
 
            mPageManager->getGlobalToPage (vertices_array[3].x, vertices_array[3].z);
1167
 
 
1168
 
            // define an area an get number of point in it.
1169
 
            const Ogre::Real maxx = std::max (vertices_array[0].x, 
1170
 
                                        std::max (vertices_array[1].x, 
1171
 
                                                  std::max (vertices_array[2].x,
1172
 
                                                            vertices_array[3].x)));
1173
 
            const Ogre::Real minx = std::min (vertices_array[0].x, 
1174
 
                                        std::min (vertices_array[1].x, 
1175
 
                                                  std::min (vertices_array[2].x,
1176
 
                                                            vertices_array[3].x)));
1177
 
          
1178
 
            const Ogre::Real maxz = std::max (vertices_array[0].z, 
1179
 
                                        std::max (vertices_array[1].z, 
1180
 
                                                  std::max (vertices_array[2].z,
1181
 
                                                            vertices_array[3].z)));
1182
 
            const Ogre::Real minz = std::min (vertices_array[0].z, 
1183
 
                                        std::min (vertices_array[1].z, 
1184
 
                                                  std::min (vertices_array[2].z,
1185
 
                                                            vertices_array[3].z)));
1186
 
 
1187
 
            const unsigned int xpoints = static_cast<unsigned int> (maxx - minx);
1188
 
            const unsigned int zpoints = static_cast<unsigned int> (maxz - minz);
1189
 
            vertices_array[4].x = zpoints * xpoints;
1190
 
 
1191
 
                    return true;
1192
 
        }
1193
 
        
1194
 
        // Visibility info 
1195
 
        if (strKey == "VisibilityMaterial")
1196
 
            {
1197
 
            if (mHorizon)
1198
 
            {
1199
 
                * static_cast < MaterialPtr * > (pDestValue) =  mHorizon->getVisibilityMaterial();
1200
 
                        return true;
1201
 
            }
1202
 
            else
1203
 
                return false;
1204
 
            }
1205
 
        // TextureFormat info 
1206
 
        if (strKey == "NextTextureFormat")
1207
 
            {
1208
 
           * static_cast < String * > (pDestValue) =  mTextureManager->getNextTextureFormat();
1209
 
                    return true;
1210
 
            }
1211
 
        if (strKey == "CurrentTextureFormat")
1212
 
            {
1213
 
           * static_cast < String * > (pDestValue) =  mTextureManager->getCurrentTextureFormat();
1214
 
                    return true;
1215
 
            }
1216
 
                
1217
 
 
1218
 
        // Map Info
1219
 
        if (strKey == "NextMap")
1220
 
            {               
1221
 
           * static_cast < String * > (pDestValue) =  mOptions->getNextMapName();
1222
 
                    return true;
1223
 
            }
1224
 
        if (strKey == "PreviousMap")
1225
 
            {
1226
 
           * static_cast < String * > (pDestValue) =  mOptions->getPreviousMapName();               
1227
 
                    return true;
1228
 
            }
1229
 
        if (strKey == "CurrentMap")
1230
 
            {
1231
 
           * static_cast < String * > (pDestValue) =  mOptions->getCurrentMapName();
1232
 
                    return true;
1233
 
            }
1234
 
        if (strKey == "CurrentMapFileName")
1235
 
            {
1236
 
           * static_cast < String * > (pDestValue) =  mOptions->LandScape_filename;
1237
 
                    return true;
1238
 
            }
1239
 
 
1240
 
 
1241
 
        // PAGEINFO
1242
 
            if (strKey == "CurrentCameraPageX")
1243
 
            {            
1244
 
            if (mPageManager)
1245
 
                        * static_cast < int * > (pDestValue) = mPageManager->getCurrentCameraPageX();
1246
 
                    return true;
1247
 
            }
1248
 
            if (strKey == "CurrentCameraPageZ")
1249
 
            {
1250
 
            if (mPageManager)
1251
 
                        * static_cast < int * > (pDestValue) = mPageManager->getCurrentCameraPageZ();
1252
 
                    return true;
1253
 
            }
1254
 
 
1255
 
 
1256
 
 
1257
 
        if (strKey == "LoadedPages")
1258
 
        {
1259
 
            if (mPageManager)
1260
 
                        * static_cast < int * > (pDestValue) = mPageManager->getLoadedPageSize();
1261
 
            return true;
1262
 
        }
1263
 
 
1264
 
        if (strKey == "UnloadedPages")
1265
 
        {
1266
 
            if (mPageManager)
1267
 
                        * static_cast < int * > (pDestValue) = mPageManager->getUnloadedPagesSize();
1268
 
            return true;
1269
 
        }
1270
 
        //TILES INFO
1271
 
            if (strKey == "MaxNumTiles")
1272
 
            {
1273
 
                    if (mTileManager)
1274
 
                        * static_cast < int * > (pDestValue) = mTileManager->numTiles();
1275
 
                    return true;
1276
 
            }
1277
 
            if (strKey == "TileFree")
1278
 
            {
1279
 
                    if (mTileManager)
1280
 
                        * static_cast < int * > (pDestValue) = (int)mTileManager->numFree();
1281
 
                    return true;
1282
 
            }
1283
 
        if (strKey == "CurrentCameraTileX")
1284
 
        {
1285
 
            if (mTileManager)
1286
 
                        * static_cast < int * > (pDestValue) = mPageManager->getCurrentCameraTileX();
1287
 
            return true;
1288
 
        }
1289
 
        if (strKey == "CurrentCameraTileZ")
1290
 
        {
1291
 
            if (mTileManager)
1292
 
                        * static_cast < int * > (pDestValue) = mPageManager->getCurrentCameraTileZ();
1293
 
            return true;
1294
 
        }
1295
 
 
1296
 
        //RENDERABLES INFO
1297
 
            if (strKey == "MaxNumRenderables")
1298
 
            {
1299
 
           if (mRenderableManager)
1300
 
                        * static_cast < int * > (pDestValue) = mRenderableManager->numRenderables();
1301
 
                    return true;
1302
 
            }
1303
 
            if (strKey == "RenderableFree")
1304
 
            {
1305
 
                    if (mRenderableManager)
1306
 
                        * static_cast < int * > (pDestValue) = (int)mRenderableManager->numFree();
1307
 
                    return true;
1308
 
            }
1309
 
            if (strKey == "RenderableLoading")
1310
 
            {
1311
 
                    if (mRenderableManager)
1312
 
                        * static_cast < int * > (pDestValue) = (int)mRenderableManager->numLoading();
1313
 
                    return true;
1314
 
            }
1315
 
        if (strKey == "VisibleRenderables")
1316
 
        {
1317
 
            if (mRenderableManager)
1318
 
                        * static_cast < unsigned int * > (pDestValue) = mRenderableManager->numVisibles();
1319
 
                        else
1320
 
                                * static_cast < unsigned int * > (pDestValue) = 0;
1321
 
            return true;
1322
 
        }
1323
 
 
1324
 
        // IMPACT INFO
1325
 
        if (strKey == "Impact")
1326
 
        {
1327
 
            * static_cast < Ogre::Vector3 * > (pDestValue) = mImpact;
1328
 
            return true;
1329
 
        }
1330
 
        if (strKey == "ImpactPageX")
1331
 
        {
1332
 
            if (mImpactInfo)
1333
 
                * static_cast < int * > (pDestValue) = mImpactInfo->mPageX;
1334
 
            return true;
1335
 
        }
1336
 
        if (strKey == "ImpactPageZ")
1337
 
        {
1338
 
            if (mImpactInfo)
1339
 
                * static_cast < int * > (pDestValue) = mImpactInfo->mPageZ;
1340
 
            return true;
1341
 
        } 
1342
 
        if (strKey == "ImpactTileX")
1343
 
        {
1344
 
            if (mImpactInfo)
1345
 
                * static_cast < int * > (pDestValue) = mImpactInfo->mTileZ;
1346
 
            return true;
1347
 
        } 
1348
 
        if (strKey == "ImpactTileZ")
1349
 
        {
1350
 
            if (mImpactInfo)
1351
 
                                * static_cast < int * > (pDestValue) = mImpactInfo->mTileZ;
1352
 
            return true;
1353
 
        }
1354
 
        if (strKey == "numModifiedTile")
1355
 
        {
1356
 
            if (mRenderableManager)
1357
 
                * static_cast < int * > (pDestValue) = mRenderableManager->numRenderables();
1358
 
            return true;
1359
 
        }
1360
 
        if (strKey == "BrushSize")
1361
 
            {
1362
 
                    * static_cast < int * >  (pDestValue) = mBrushSize;
1363
 
            return true;
1364
 
            }
1365
 
        if (strKey == "BrushScale")
1366
 
            {
1367
 
                    * static_cast <Ogre::Real * > (pDestValue) = mBrushScale;
1368
 
            return true;
1369
 
            }
1370
 
                
1371
 
        // Paint
1372
 
        if (strKey == "currentColors")
1373
 
        {
1374
 
            //
1375
 
            return true;
1376
 
        }
1377
 
        //added for Vertex data retrieval               
1378
 
                if (strKey == "PageGetTileVertexData_2")
1379
 
                {
1380
 
            /**
1381
 
             * This is the optimized, yet a bit fuzzy implementation of the getVertexDataPatch
1382
 
             * Usage: Pass in a std::vector<void*> Pointer to the getOption call containing at least 5 Elements
1383
 
             *          [0](Ogre::unsigned int*) = X Index of the Page to retrieve data from
1384
 
             *          [1](Ogre::unsigned int*) = Z Index of the Page to retrieve data from
1385
 
             *          [2](Ogre::unsigned int*) = X Index of the Tile within the Page to retrieve data from
1386
 
             *          [3](Ogre::unsigned int*) = Z Index of the Tile within the Page to retrieve data from
1387
 
             *          [4](Ogre::unsigned int*) = LodLevel to get the data at (note that level 0 means highest detail)
1388
 
             *  The getData call will then append 3 entries to the end of the vector. In Detail(in order)
1389
 
             *          [End-2](Ogre::unsigned int*) = Number of vertices returned
1390
 
             *          [End-1] (Ogre::Vector3*) = The actual vertices, this is a array containing as many elements as returned in [End-2]
1391
 
             *          [End] (Ogre::IndexData*) = The index data for the terrain polygons at the queried LodLevel
1392
 
             *  @remark note that the caller is in charge of deleting the vector array, vertices array and indice array.
1393
 
             */
1394
 
                        unsigned int requestPageX = *static_cast<unsigned int *>((*static_cast<std::vector<void*>*>(pDestValue))[0]);
1395
 
                        unsigned int requestPageZ = *static_cast<unsigned int *>((*static_cast<std::vector<void*>*>(pDestValue))[1]);
1396
 
                        unsigned int requestTileX = *static_cast<unsigned int *>((*static_cast<std::vector<void*>*>(pDestValue))[2]);
1397
 
                        unsigned int requestTileZ = *static_cast<unsigned int *>((*static_cast<std::vector<void*>*>(pDestValue))[3]);
1398
 
                        unsigned int requestLodLevel = *static_cast<unsigned int *>((*static_cast<std::vector<void*>*>(pDestValue))[4]);
1399
 
                        PagingLandScapePage* page = mPageManager->getPage(requestPageX,requestPageZ);
1400
 
                        if(page)
1401
 
                        {
1402
 
                                PagingLandScapeTile* tile = page->getTile(requestTileX,requestTileZ);
1403
 
                                if(tile)
1404
 
                                {
1405
 
                                        PagingLandScapeRenderable* rend = tile->getRenderable();
1406
 
                                        if(rend)
1407
 
                                        {
1408
 
                                                Vector3*        tempPointer;    //This will hold the vertexData and needs to be deleted by the caller
1409
 
                                                unsigned int*                   numPtr = new unsigned int;
1410
 
                                                *numPtr = rend->getVertexCount();
1411
 
                                                (*static_cast<std::vector<void*>*>(pDestValue)).push_back(numPtr);
1412
 
                        tempPointer = new Ogre::Vector3[*numPtr];
1413
 
                                                //warning! make sure that the allocated space for the vertices is big enough!
1414
 
                                                rend->getRawVertexData(tempPointer);
1415
 
                                                (*static_cast<std::vector<void*>*>(pDestValue)).push_back(tempPointer);
1416
 
                                                (*static_cast<std::vector<void*>*>(pDestValue)).push_back(rend->getRawIndexData(requestLodLevel));
1417
 
                                                return true;
1418
 
                                        }
1419
 
                                }
1420
 
                        }
1421
 
                        return false;
1422
 
                }
1423
 
        if (strKey == "getMaterialPageName")
1424
 
        {
1425
 
 
1426
 
                        if (mPageManager)
1427
 
                        {
1428
 
                                // convert position
1429
 
                                Vector3 **pos = static_cast < Ogre::Vector3 ** > (pDestValue);
1430
 
                                mPageManager->getGlobalToPage ((*pos)->x, (*pos)->z);
1431
 
 
1432
 
                                // get the texture
1433
 
                                Ogre::PagingLandScapeTexture* texture_ptr =
1434
 
                                        mTextureManager->getTexture((*pos)->x, (*pos)->z, false);
1435
 
 
1436
 
                                // check for valid texture
1437
 
                                if( texture_ptr )
1438
 
                                {
1439
 
                                        // get texture name
1440
 
                                        String* name_ptr = const_cast<String*>(&texture_ptr->getMaterialName());
1441
 
 
1442
 
                                        // convert void pointer to a string**
1443
 
                                        String** target_ptr = static_cast<String**>(pDestValue);
1444
 
 
1445
 
                                        // save name at target position
1446
 
                                        *target_ptr = name_ptr;
1447
 
                                }
1448
 
                        }
1449
 
                        return true;
1450
 
 
1451
 
        }
1452
 
                //end of addition
1453
 
        if (mOptions && mOptions->getOption(strKey, pDestValue) == false)
1454
 
        {
1455
 
            return PagingLandScapeOctreeSceneManager::getOption (strKey, pDestValue);
1456
 
        }
1457
 
        return true;
1458
 
    }
1459
 
 
1460
 
    //-----------------------------------------------------------------------
1461
 
    bool PagingLandScapeSceneManager::hasOption(const String& strKey) const
1462
 
    {
1463
 
            if (strKey == "AddNewHeight")
1464
 
            {
1465
 
                    return true;
1466
 
            }
1467
 
            if (strKey == "RemoveNewHeight")
1468
 
            {
1469
 
                    return true;
1470
 
            }
1471
 
            if (strKey == "CurrentCameraPageX")
1472
 
            {
1473
 
                    return true;
1474
 
            }
1475
 
            if (strKey == "CurrentCameraPageZ")
1476
 
            {
1477
 
                    return true;
1478
 
            }
1479
 
            if (strKey == "MaxNumTiles")
1480
 
            {
1481
 
                    return true;
1482
 
            }
1483
 
            if (strKey == "TileFree")
1484
 
            {
1485
 
                    return true;
1486
 
            }
1487
 
            if (strKey == "MaxNumRenderables")
1488
 
            {
1489
 
                    return true;
1490
 
            }
1491
 
            if (strKey == "RenderableFree")
1492
 
            {
1493
 
                    return true;
1494
 
            }
1495
 
            if (strKey == "RenderableLoading")
1496
 
            {
1497
 
                    return true;
1498
 
            }
1499
 
            if (strKey == "PagePreloadQueue")
1500
 
            {
1501
 
                    return true;
1502
 
            }
1503
 
            if (strKey == "PageLoadQueue")
1504
 
            {
1505
 
                    return true;
1506
 
            }
1507
 
            if (strKey == "PageUnloadQueue")
1508
 
            {
1509
 
                    return true;
1510
 
            }
1511
 
            if (strKey == "PagePostUnloadQueue")
1512
 
            {
1513
 
                    return true;
1514
 
            }
1515
 
                //added for Vertex data retrieval
1516
 
                if (strKey == "PageGetTileVertexData")
1517
 
            {
1518
 
                        return true;
1519
 
            }
1520
 
                //end of addition
1521
 
        if (mOptions && mOptions->hasOption(strKey) == false)
1522
 
        {
1523
 
            return PagingLandScapeOctreeSceneManager::hasOption (strKey);
1524
 
        }
1525
 
        return true;
1526
 
    }
1527
 
 
1528
 
    //-----------------------------------------------------------------------
1529
 
    bool PagingLandScapeSceneManager::getOptionValues(const String & key, StringVector &refValueList)
1530
 
    {
1531
 
//          if (key == "CurrentCameraPageX")
1532
 
//          {
1533
 
//                  refValueList.push_back(MemoryDataStreamPtr());
1534
 
//                  return true;
1535
 
//          }
1536
 
//          if (key == "CurrentCameraPageZ")
1537
 
//          {
1538
 
//                  refValueList.push_back(MemoryDataStreamPtr());
1539
 
//                  return true;
1540
 
//          }
1541
 
//          if (key == "MaxNumTiles")
1542
 
//          {
1543
 
//                  refValueList.push_back(MemoryDataStreamPtr());
1544
 
//                  return true;
1545
 
//          }
1546
 
//          if (key == "TileFree")
1547
 
//          {
1548
 
//                  refValueList.push_back(MemoryDataStreamPtr());
1549
 
//                  return true;
1550
 
//          }
1551
 
//          if (key == "MaxNumRenderables")
1552
 
//          {
1553
 
//                  refValueList.push_back(MemoryDataStreamPtr());
1554
 
//                  return true;
1555
 
//          }
1556
 
//          if (key == "RenderableFree")
1557
 
//          {
1558
 
//                  refValueList.push_back(MemoryDataStreamPtr());
1559
 
//                  return true;
1560
 
//          }
1561
 
//          if (key == "RenderableLoading")
1562
 
//          {
1563
 
//                  refValueList.push_back(MemoryDataStreamPtr());
1564
 
//                  return true;
1565
 
//          }
1566
 
//          if (key == "PagePreloadQueue")
1567
 
//          {
1568
 
//                  refValueList.push_back(MemoryDataStreamPtr());
1569
 
//                  return true;
1570
 
//          }
1571
 
//          if (key == "PageLoadQueue")
1572
 
//          {
1573
 
//                  refValueList.push_back(MemoryDataStreamPtr());
1574
 
//                  return true;
1575
 
//          }
1576
 
//          if (key == "PageUnloadQueue")
1577
 
//          {
1578
 
//                  refValueList.push_back(MemoryDataStreamPtr());
1579
 
//                  return true;
1580
 
//          }
1581
 
//          if (key == "PagePostUnloadQueue")
1582
 
//          {
1583
 
//                  refValueList.push_back(MemoryDataStreamPtr());
1584
 
//                  return true;
1585
 
//          }
1586
 
    
1587
 
        if (mOptions->getOptionValues(key, refValueList) == false)
1588
 
        {
1589
 
            return PagingLandScapeOctreeSceneManager::getOptionValues (key, refValueList);
1590
 
        }
1591
 
        return true;
1592
 
    }
1593
 
 
1594
 
    //-----------------------------------------------------------------------
1595
 
    bool PagingLandScapeSceneManager::getOptionKeys(StringVector &refKeys)
1596
 
    {
1597
 
            refKeys.clear();
1598
 
            refKeys.push_back("AddNewHeight");
1599
 
            refKeys.push_back("RemoveNewHeight");
1600
 
            refKeys.push_back("CurrentCameraPageX");
1601
 
            refKeys.push_back("CurrentCameraPageZ");
1602
 
            refKeys.push_back("MaxNumTiles");
1603
 
            refKeys.push_back("TileFree");
1604
 
            refKeys.push_back("MaxNumRenderables");
1605
 
            refKeys.push_back("RenderableFree");
1606
 
            refKeys.push_back("RenderableLoading");
1607
 
            refKeys.push_back("PagePreloadQueue");
1608
 
            refKeys.push_back("PageLoadQueue");
1609
 
            refKeys.push_back("PageUnloadQueue");
1610
 
            refKeys.push_back("PagePostUnloadQueue");
1611
 
        mOptions->getOptionKeys(refKeys);
1612
 
        return PagingLandScapeOctreeSceneManager::getOptionKeys (refKeys);
1613
 
    }
1614
 
        //-------------------------------------------------------------------------
1615
 
        void PagingLandScapeSceneManager::setWorldGeometryRenderQueue (uint8 qid)
1616
 
    {
1617
 
        PagingLandScapeOctreeSceneManager::setWorldGeometryRenderQueue(qid);
1618
 
        if (mPageManager)
1619
 
            mPageManager->setWorldGeometryRenderQueue (qid);
1620
 
        }
1621
 
    //-----------------------------------------------------------------------
1622
 
    Camera * PagingLandScapeSceneManager::createCamera(const String &name)
1623
 
    {  
1624
 
        if (mCameras.find(name) != mCameras.end())
1625
 
        {
1626
 
            OGRE_EXCEPT(
1627
 
                Exception::ERR_DUPLICATE_ITEM,
1628
 
                "A camera with the name " + name + " already exists",
1629
 
                "PagingLandScapeSceneManager::createCamera");
1630
 
        }
1631
 
 
1632
 
        Camera * c = new PagingLandScapeCamera(name, this);
1633
 
        mCameras.insert(CameraList::value_type(name, c));
1634
 
        PagingLandScapeOctreeSceneManager::addCamera (c);
1635
 
                // Check if we need to set the primaryCamera
1636
 
                if (mOptions && !mOptions->primaryCamera)
1637
 
                {
1638
 
                        mOptions->setPrimaryCamera (static_cast <PagingLandScapeCamera*> (c));
1639
 
                }
1640
 
                //default values
1641
 
                c->setNearClipDistance( 1 );
1642
 
                // Infinite far plane? 
1643
 
                if (Root::getSingleton().getRenderSystem()->getCapabilities()->hasCapability(RSC_INFINITE_FAR_PLANE)) 
1644
 
                { 
1645
 
                        c->setFarClipDistance(0); 
1646
 
                }
1647
 
                else if (mOptions)
1648
 
                { 
1649
 
                        float tmp;
1650
 
                        getOption( "VisibleDistance", &tmp);
1651
 
                        c->setFarClipDistance( tmp );
1652
 
                }
1653
 
#ifdef PLSM2_EIHORT
1654
 
        // create visible bounds aab map entry
1655
 
            mCamVisibleObjectsMap[c] = VisibleObjectsBoundsInfo();
1656
 
#endif
1657
 
        return c;
1658
 
    }
1659
 
    //-----------------------------------------------------------------------
1660
 
    void PagingLandScapeSceneManager::destroyCamera(Camera *cam)
1661
 
        { 
1662
 
                if (mOptions->primaryCamera && cam->getName() == mOptions->primaryCamera->getName())
1663
 
                {
1664
 
                        mOptions->setPrimaryCamera (0);
1665
 
                }
1666
 
        PagingLandScapeOctreeSceneManager::destroyCamera(cam);
1667
 
    }
1668
 
    //-----------------------------------------------------------------------
1669
 
    void PagingLandScapeSceneManager::destroyCamera(const String& name)
1670
 
        {
1671
 
                if (mOptions->primaryCamera && name == mOptions->primaryCamera->getName())
1672
 
                {
1673
 
                        mOptions->setPrimaryCamera (0);
1674
 
                }
1675
 
        PagingLandScapeOctreeSceneManager::destroyCamera(name);
1676
 
    }
1677
 
    //-----------------------------------------------------------------------
1678
 
    void PagingLandScapeSceneManager::destroyAllCameras(void)
1679
 
        {
1680
 
                mOptions->setPrimaryCamera (0);
1681
 
        PagingLandScapeOctreeSceneManager::destroyAllCameras();
1682
 
    } 
1683
 
    //-----------------------------------------------------------------------
1684
 
    void _OgrePagingLandScapeExport PagingLandScapeSceneManager::getWorldSize(Real *worldSizeX,Ogre::Real *worldSizeZ)
1685
 
   {
1686
 
      *worldSizeX = mOptions->maxScaledX * 2.0f;
1687
 
      *worldSizeZ = mOptions->maxScaledZ * 2.0f;
1688
 
//      *worldSizeX = (float)mOptions->world_width * mOptions->scale.x;
1689
 
//      *worldSizeZ = (float)mOptions->world_height * mOptions->scale.z;
1690
 
   }
1691
 
   //-----------------------------------------------------------------------
1692
 
   float _OgrePagingLandScapeExport PagingLandScapeSceneManager::getMaxSlope(Vector3 location1, Ogre::Vector3 location2, float maxSlopeIn)
1693
 
   {
1694
 
      return mData2DManager->getMaxSlope(location1, location2, maxSlopeIn);
1695
 
   }
1696
 
   //-----------------------------------------------------------------------
1697
 
   void PagingLandScapeSceneManager::renderBaseTextures(const String& alternateMatName)
1698
 
   {
1699
 
 
1700
 
          //only currently works for PLSplattingShaderLit mode
1701
 
          //because I can't figure out how to elegantly handle all texture modes (yet)
1702
 
      if(mOptions->textureFormat != "PLSplattingShaderLit" || alternateMatName != "PLSplattingShaderUnlit")
1703
 
          {
1704
 
                  OGRE_EXCEPT(
1705
 
                          Exception::ERR_NOT_IMPLEMENTED,
1706
 
                          "Only currently supports PLSplattingShaderLit texture mode and alternate material SplattingShader",
1707
 
                          "PagingLandScapeSceneManager::renderBaseTextures");
1708
 
          }
1709
 
 
1710
 
      PagingLandScapeTexture* t = NULL;
1711
 
          String matName;
1712
 
          TexturePtr texture;   
1713
 
          RenderTexture *renderTexture; 
1714
 
          Camera *rttCam;
1715
 
          texture = TextureManager::getSingleton ().createManual("PLRTTBaseTexture", 
1716
 
                  ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
1717
 
                  TEX_TYPE_2D,
1718
 
                  256,
1719
 
                  256, 
1720
 
                  0,
1721
 
                  PF_A8R8G8B8,
1722
 
                  TU_RENDERTARGET);
1723
 
 
1724
 
          renderTexture = texture->getBuffer()->getRenderTarget();
1725
 
          renderTexture->setAutoUpdated(false);
1726
 
          rttCam = createCamera("PLRTTBaseTextureCam");
1727
 
          rttCam->setNearClipDistance(1.0f);
1728
 
          rttCam->setFarClipDistance(0); 
1729
 
          rttCam->setPosition(Vector3(0,0,2));
1730
 
          rttCam->lookAt(Vector3(0,0,0));
1731
 
          Viewport* const v = renderTexture->addViewport(rttCam);
1732
 
          v->setClearEveryFrame(true);
1733
 
          v->setBackgroundColour(ColourValue(0.0f, 0.0f, 0.0f, 0.0f));
1734
 
 
1735
 
          //addSpecialCaseRenderQueue(Ogre::RENDER_QUEUE_6);
1736
 
          //setSpecialCaseRenderQueueMode(Ogre::SceneManager::SCRQM_INCLUDE); 
1737
 
 
1738
 
          Rectangle2D* rect = new Rectangle2D(true);
1739
 
          rect->setBoundingBox(AxisAlignedBox(-100000.0*Vector3::UNIT_SCALE, 100000.0*Vector3::UNIT_SCALE)); 
1740
 
          rect->setCorners(-1, 1, 1, -1);
1741
 
          rect->setRenderQueueGroup(Ogre::RENDER_QUEUE_OVERLAY);
1742
 
          SceneNode* node = getRootSceneNode()->createChildSceneNode("PLBaseTextureRectNode");
1743
 
          rect->setVisible(true);
1744
 
          node->attachObject(rect);
1745
 
          String textureName;
1746
 
          size_t strPos = 0;
1747
 
          MaterialPtr material;
1748
 
          MaterialPtr alternateMaterial;
1749
 
          //this->setAmbientLight(ColourValue::White);
1750
 
 
1751
 
          for(uint x = 0; x < mOptions->world_width; ++x)
1752
 
          {
1753
 
                  for(uint z = 0; z < mOptions->world_height; ++z)
1754
 
                  {
1755
 
                          t = mTextureManager->getTexture(x, z);
1756
 
                          if(!t->isLoaded())
1757
 
                                  t->load(x, z);
1758
 
                                
1759
 
                          textureName = mOptions->LandScape_filename + ".Base." + StringConverter::toString(z) + "." + StringConverter::toString(x) + ".png";
1760
 
                          matName = t->getMaterialName();
1761
 
 
1762
 
                          //if an alternate material name is specified, we'll use the texture units from our original material
1763
 
                          //and the passes from our new material
1764
 
                          if(alternateMatName != "")
1765
 
                          {
1766
 
                                  alternateMaterial = MaterialManager::getSingleton().getByName(alternateMatName + "_Clone");
1767
 
                                  if(alternateMaterial.isNull())
1768
 
                                  {
1769
 
                                          alternateMaterial = MaterialManager::getSingleton().getByName(alternateMatName);
1770
 
                                          if(alternateMaterial.isNull())
1771
 
                                          {
1772
 
                                                  OGRE_EXCEPT(
1773
 
                                                          Exception::ERR_ITEM_NOT_FOUND, 
1774
 
                                                          "Could not find alternate material " + alternateMatName,
1775
 
                                                          "PagingLandScapeSceneManager::renderBaseTextures");
1776
 
                                          }
1777
 
                                          alternateMaterial = alternateMaterial->clone(alternateMatName + "_Clone");
1778
 
                                  }
1779
 
                                  matName = alternateMaterial->getName();
1780
 
                                  material = t->getMaterial();
1781
 
                  
1782
 
                                  //we know that pass 2 of PLSplattingShaderLitDecompress has our coverage and
1783
 
                                  //splatting textures in specific texture units
1784
 
                                  //I think if we want this to be completely generic we'll have to load the original 
1785
 
                                  //texture mode's material, iterate through and find the "Coverage" and "Splatting" references from it,
1786
 
                                  //and do the same for alternate material, and attempt to hook them up the same
1787
 
                                  for(uint i = 0; i < 5; ++i)
1788
 
                                  {
1789
 
                                     alternateMaterial->getTechnique(0)->getPass(0)->getTextureUnitState(i)->setTextureName(material->getTechnique(0)->getPass(1)->getTextureUnitState(i)->getTextureName());
1790
 
                              }
1791
 
                          }
1792
 
                                                        
1793
 
                          //assign the material to the rectangle
1794
 
                          rect->setMaterial(matName);
1795
 
                          _updateSceneGraph(rttCam);
1796
 
                          renderTexture->update();
1797
 
                          renderTexture->writeContentsToFile("../../../Media/paginglandscape2/terrains/" + mOptions->LandScape_filename + "/" + textureName);
1798
 
                          TexturePtr texture = TextureManager::getSingleton().getByName(textureName);
1799
 
                          if(!texture.isNull())
1800
 
                                  texture->reload();
1801
 
 
1802
 
                          if(mOptions->VertexCompression)
1803
 
                          {
1804
 
                                  MaterialManager::getSingleton().remove(material->getHandle());
1805
 
                          }
1806
 
                  }
1807
 
          }
1808
 
 
1809
 
          TextureManager::getSingleton().remove(texture->getHandle());
1810
 
          destroyCamera("PLRTTBaseTextureCam");
1811
 
          node->detachObject(rect);
1812
 
          destroySceneNode("PLBaseTextureRectNode");
1813
 
 
1814
 
   }
1815
 
} //namespace