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

« back to all changes in this revision

Viewing changes to src/components/ogre/SceneManagers/EmberPagingSceneManager/include/OgrePagingLandScapeSceneManager.h

  • Committer: Bazaar Package Importer
  • Author(s): Michael Koch
  • Date: 2009-07-23 07:46:40 UTC
  • Revision ID: james.westby@ubuntu.com-20090723074640-wh0ukzis0kda36qv
Tags: upstream-0.5.6
ImportĀ upstreamĀ versionĀ 0.5.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
        OgrePagingLandScapeSceneManager.h  -  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
#ifndef PAGINGLandScapeSCENEMANAGER_H
 
19
#define PAGINGLandScapeSCENEMANAGER_H
 
20
 
 
21
#include "OgrePagingLandScapePrerequisites.h"
 
22
#include "OgrePagingLandScapeOctreeSceneManager.h"
 
23
#include "OgrePagingLandScapeOptions.h"
 
24
#include "OgreStringVector.h"
 
25
 
 
26
#include "OgrePagingLandScapeData2DManager.h"
 
27
 
 
28
namespace Ogre
 
29
{
 
30
    
 
31
     /// Factory for OctreeSceneManager
 
32
     class PagingLandScapeSceneManagerFactory : public SceneManagerFactory
 
33
     {
 
34
     protected:
 
35
        void initMetaData(void) const;
 
36
     public:
 
37
        PagingLandScapeSceneManagerFactory() {}
 
38
        ~PagingLandScapeSceneManagerFactory() {}
 
39
        /// Factory type name
 
40
        static const String FACTORY_TYPE_NAME;
 
41
        SceneManager* createInstance(const String& instanceName);
 
42
        void destroyInstance(SceneManager* instance);
 
43
     };
 
44
     
 
45
 
 
46
 
 
47
    /** This is a basic SceneManager for organizing PagingLandScapeRenderables into a total LandScape.
 
48
            It loads a LandScape from a .cfg file that specifies what textures/scale/mipmaps/etc to use.
 
49
    */
 
50
    class PagingLandScapeSceneManager : public PagingLandScapeOctreeSceneManager
 
51
    {
 
52
            friend class PagingLandScapeRaySceneQuery;
 
53
    public:
 
54
            PagingLandScapeSceneManager(const String &name);
 
55
            ~PagingLandScapeSceneManager(void);
 
56
 
 
57
        void shutdown();
 
58
        /// @copydoc SceneManager::getTypeName
 
59
        const String& getTypeName(void) const;
 
60
 
 
61
        /** Creates a specialized Camera */
 
62
        virtual Camera * createCamera(const String &name);
 
63
        virtual void destroyCamera(Camera *cam);
 
64
        virtual void destroyCamera(const String& name);
 
65
        virtual void destroyAllCameras(void);
 
66
 
 
67
              /** Sets the source of the 'world' geometry, i.e. the large, mainly static geometry
 
68
            making up the world e.g. rooms, LandScape etc.
 
69
            @remarks
 
70
                Depending on the type of SceneManager (subclasses will be specialised
 
71
                for particular world geometry types) you have requested via the Root or
 
72
                SceneManagerEnumerator classes, you can pass a filename to this method and it
 
73
                will attempt to load the world-level geometry for use. If you try to load
 
74
                an inappropriate type of world data an exception will be thrown. The default
 
75
                SceneManager cannot handle any sort of world geometry and so will always
 
76
                throw an exception. However subclasses like BspSceneManager can load
 
77
                particular types of world geometry e.g. "q3dm1.bsp".
 
78
        */
 
79
            virtual void setWorldGeometry(const String& filename);
 
80
        
 
81
        /** Sets the source of the 'world' geometry, i.e. the large, mainly 
 
82
                        static geometry making up the world e.g. rooms, LandScape etc.
 
83
            @remarks
 
84
                Depending on the type of SceneManager (subclasses will be 
 
85
                                specialised for particular world geometry types) you have 
 
86
                                requested via the Root or SceneManagerEnumerator classes, you 
 
87
                                can pass a stream to this method and it will attempt to load 
 
88
                                the world-level geometry for use. If the manager can only 
 
89
                                handle one input format the typeName parameter is not required.
 
90
                                The stream passed will be read (and it's state updated). 
 
91
                        @param stream Data stream containing data to load
 
92
                        @param typeName String identifying the type of world geometry
 
93
                                contained in the stream - not required if this manager only 
 
94
                                supports one type of world geometry.
 
95
        */
 
96
        virtual void setWorldGeometry(DataStreamPtr& stream, 
 
97
                const String& typeName = StringUtil::BLANK);
 
98
 
 
99
 
 
100
        /** Things that need to be allocated once 
 
101
        */
 
102
        void InitScene(void);
 
103
 
 
104
            /** Empties the entire scene, including all SceneNodes, Cameras, Entities and Lights etc.
 
105
            */
 
106
            void clearScene(void);
 
107
 
 
108
        /** Empties only the Terrain Scene pages, tiles, textures and so on
 
109
        */
 
110
        void resetScene(void);
 
111
 
 
112
         /** Loads the LandScape using current parameters
 
113
         */
 
114
        void loadScene(void);
 
115
 
 
116
            /** Method for setting a specific option of the Scene Manager. These options are usually
 
117
                    specific for a certain implementation of the Scene Manager class, and may (and probably
 
118
                    will) not exist across different implementations.
 
119
                    @param
 
120
                            strKey The name of the option to set
 
121
                    @param
 
122
                            pValue A pointer to the value - the size should be calculated by the scene manager
 
123
                            based on the key
 
124
                    @return
 
125
                            On success, true is returned.
 
126
                    @par
 
127
                            On failure, false is returned.
 
128
            */
 
129
            bool setOption(const String& strKey, const void* pValue);
 
130
 
 
131
            /** Method for getting the value of an implementation-specific Scene Manager option.
 
132
                    @param
 
133
                            strKey The name of the option
 
134
                    @param
 
135
                            pDestValue A pointer to a memory location where the value will
 
136
                            be copied. Currently, the memory will be allocated by the
 
137
                            scene manager, but this may change
 
138
                    @return
 
139
                            On success, true is returned and pDestValue points to the value of the given
 
140
                            option.
 
141
                    @par
 
142
                            On failiure, false is returned and pDestValue is set to NULL.
 
143
            */
 
144
            bool getOption(const String& strKey, void* pDestValue);
 
145
 
 
146
            /** Method for verifying wether the scene manager has an implementation-specific
 
147
                    option.
 
148
                    @param
 
149
                            strKey The name of the option to check for.
 
150
                    @return
 
151
                            If the scene manager contains the given option, true is returned.
 
152
                    @remarks
 
153
                            If it does not, false is returned.
 
154
            */
 
155
            bool hasOption(const String& strKey) const;
 
156
 
 
157
            /** Method for getting all possible values for a specific option. When this list is too large
 
158
                    (i.e. the option expects, for example, aOgre::Real), the return value will be true, but the
 
159
                    list will contain just one element whose size will be set to 0.
 
160
                    Otherwise, the list will be filled with all the possible values the option can
 
161
                    accept.
 
162
                    @param
 
163
                            strKey The name of the option to get the values for.
 
164
                    @param
 
165
                            refValueList A reference to a list that will be filled with the available values.
 
166
                    @return
 
167
                            On success (the option exists), true is returned.
 
168
                    @par
 
169
                            On failiure, false is returned.
 
170
            */
 
171
            bool getOptionValues(const String& key, StringVector& refValueList);
 
172
 
 
173
            /** Method for getting all the implementation-specific options of the scene manager.
 
174
                    @param
 
175
                            refKeys A reference to a list that will be filled with all the available options.
 
176
                    @return
 
177
                            On success, true is returned.
 
178
                                On failiure, false is returned.
 
179
            */
 
180
        bool getOptionKeys(StringVector &refKeys);
 
181
 
 
182
            /** Internal method for updating the scene graph ie the tree of SceneNode instances managed by this class.
 
183
                    @remarks
 
184
                            This must be done before issuing objects to the rendering pipeline, since derived transformations from
 
185
                            parent nodes are not updated until required. This SceneManager is a basic implementation which simply
 
186
                            updates all nodes from the root. This ensures the scene is up to date but requires all the nodes
 
187
                            to be updated even if they are not visible. Subclasses could trim this such that only potentially visible
 
188
                            nodes are updated.
 
189
            */
 
190
            void _updateSceneGraph(Camera* cam);
 
191
 
 
192
            /** Sends visible objects found in _findVisibleObjects to the rendering engine.
 
193
            */
 
194
            //void _renderVisibleObjects(void);
 
195
 
 
196
            /** Internal method which parses the scene to find visible objects to render.
 
197
                    @remarks
 
198
                            If you're implementing a custom scene manager, this is the most important method to
 
199
                            override since it's here you can apply your custom world partitioning scheme. Once you
 
200
                            have added the appropriate objects to the render queue, you can let the default
 
201
                            SceneManager objects _renderVisibleObjects handle the actual rendering of the objects
 
202
                            you pick.
 
203
                    @par
 
204
                            Any visible objects will be added to a rendering queue, which is indexed by material in order
 
205
                            to ensure objects with the same material are rendered together to minimise render state changes.
 
206
            */
 
207
            //void _findVisibleObjects(Camera * cam, bool onlyShadowCasters);
 
208
 
 
209
        /** Creates an AxisAlignedBoxSceneQuery for this scene manager. 
 
210
        @remarks
 
211
            This method creates a new instance of a query object for this scene manager, 
 
212
            for an axis aligned box region. See SceneQuery and AxisAlignedBoxSceneQuery 
 
213
            for full details.
 
214
                        Currently this only supports custom geometry results.  It ignores the y
 
215
                        coords of the AABB.
 
216
        @par
 
217
            The instance returned from this method must be destroyed by calling
 
218
            SceneManager::destroyQuery when it is no longer required.
 
219
        @param box Details of the box which describes the region for this query.
 
220
        @param mask The query mask to apply to this query; can be used to filter out
 
221
            certain objects; see SceneQuery for details.
 
222
        */
 
223
        AxisAlignedBoxSceneQuery* createAABBQuery(const AxisAlignedBox& box, unsigned long mask = 0xFFFFFFFF);
 
224
 
 
225
 
 
226
            /** Creates a RaySceneQuery for this scene manager. 
 
227
                    @remarks
 
228
                            This method creates a new instance of a query object for this scene manager, 
 
229
                            looking for objects which fall along a ray. See SceneQuery and RaySceneQuery 
 
230
                            for full details.
 
231
                    @par
 
232
                            The instance returned from this method must be destroyed by calling
 
233
                            SceneManager::destroyQuery when it is no longer required.
 
234
                    @param ray Details of the ray which describes the region for this query.
 
235
                    @param mask The query mask to apply to this query; can be used to filter out
 
236
                            certain objects; see SceneQuery for details.
 
237
            */
 
238
            RaySceneQuery* createRayQuery(const Ray& ray, unsigned long mask = 0xFFFFFFFF);
 
239
 
 
240
            /** Creates an IntersectionSceneQuery for this scene manager. 
 
241
                    @remarks
 
242
                            This method creates a new instance of a query object for locating
 
243
                            intersecting objects. See SceneQuery and IntersectionSceneQuery
 
244
                            for full details.
 
245
                    @par
 
246
                            The instance returned from this method must be destroyed by calling
 
247
                            SceneManager::destroyQuery when it is no longer required.
 
248
                    @param mask The query mask to apply to this query; can be used to filter out
 
249
                            certain objects; see SceneQuery for details.
 
250
            */
 
251
            //IntersectionSceneQuery* createIntersectionQuery(unsigned long mask);
 
252
 
 
253
        /** intersectSegment 
 
254
            @remarks
 
255
                Intersect mainly with LandScape
 
256
            @param start 
 
257
                begining of the segment 
 
258
            @param end 
 
259
                where it ends
 
260
            @param result 
 
261
                where it intersects with terrain
 
262
        */
 
263
        bool intersectSegment(const Ogre::Vector3& start, const Ogre::Vector3& end, Ogre::Vector3* result);
 
264
    
 
265
        /** intersectSegment 
 
266
            @remarks
 
267
                Intersect mainly with LandScape
 
268
            @param start 
 
269
                begining of the segment 
 
270
            @param dir 
 
271
                direction of the ray
 
272
            @param result 
 
273
                where it intersects with terrain
 
274
        */
 
275
        bool intersectSegmentTerrain(const Ogre::Vector3& begin, const Ogre::Vector3& dir, Ogre::Vector3* result);
 
276
        /** load
 
277
        * @remarks load heights only LandScape, need brush and brush scale to be set before
 
278
        * @param &impact  where load take place, where BrushArray is centered
 
279
        */
 
280
        void setHeight (const Ogre::Vector3 &impact);
 
281
        /** deform
 
282
        * @remarks deform only LandScape, need brush and brush scale to be set before
 
283
        * @param &impact  where deformation take place, where BrushArray is centered
 
284
        */
 
285
        void deformHeight(const Ogre::Vector3& impact);
 
286
        /** paint
 
287
        * @remarks paint only LandScape, need channel, brush and brush scale to be set before
 
288
        * @param impact  where painting take place
 
289
        * @param isAlpha  if we want to paint alpha or color
 
290
        */
 
291
        void paint (const Ogre::Vector3 &impact);
 
292
        /** getAreaHeight
 
293
        * @remarks used to fill user allocated array with values.
 
294
        * @param impact  where array is centered
 
295
        */
 
296
        void getAreaHeight(const Ogre::Vector3& impact); 
 
297
 
 
298
                /** renderBaseTextures()
 
299
                * @remarks Performs render to texture for all pages to create base textures from
 
300
                * splatting shader. If alternate material is specified, will use it instead of 
 
301
                * the actual material assigned to the page. This is necessary when terrain is lit
 
302
                * and/or compressed.
 
303
                */
 
304
                void renderBaseTextures(const String& alternateMatName); 
 
305
 
 
306
            /** Overridden from SceneManager */
 
307
            void setWorldGeometryRenderQueue(uint8 qid);
 
308
 
 
309
        void PagingLandScapeOctreeResize(void);
 
310
 
 
311
        void WorldDimensionChange(void);
 
312
 
 
313
        //-----------------------------------------------------------------------
 
314
        inline Ogre::Real _OgrePagingLandScapeExport getHeightAt(const Ogre::Real x, const Ogre::Real z)
 
315
        {
 
316
            return mData2DManager->getInterpolatedWorldHeight(x, z);
 
317
        }
 
318
        //-----------------------------------------------------------------------
 
319
        inline Ogre::Real _OgrePagingLandScapeExport getSlopeAt(const Ogre::Real x, const Ogre::Real z)
 
320
        {
 
321
           Ogre::Real slope;
 
322
            //      return mData2DManager->getRealWorldSlope(x, z);
 
323
            mData2DManager->getInterpolatedWorldHeight(x, z, &slope);
 
324
            return slope;
 
325
        }
 
326
 
 
327
        _OgrePagingLandScapeExport void  getWorldSize(Real *worldSizeX,Ogre::Real *worldSizeZ);
 
328
        _OgrePagingLandScapeExport float getMaxSlope(Vector3 location1, Ogre::Vector3 location2, float maxSlopeIn);
 
329
 
 
330
        inline PagingLandScapeOptions                 * getOptions()
 
331
        {
 
332
            assert(mOptions);
 
333
            return mOptions;
 
334
        }
 
335
 
 
336
        inline PagingLandScapeHorizon                  * getHorizon()
 
337
        {
 
338
            assert(mHorizon);
 
339
            return mHorizon;
 
340
        }
 
341
        inline PagingLandScapeTileManager              * getTileManager()
 
342
        {
 
343
            assert(mTileManager);
 
344
            return mTileManager;
 
345
        }
 
346
        inline PagingLandScapePageManager              * getPageManager()
 
347
        {
 
348
            assert(mPageManager);
 
349
            return mPageManager;
 
350
        }
 
351
        inline PagingLandScapeData2DManager            * getData2DManager()
 
352
        {
 
353
            assert(mData2DManager);
 
354
            return mData2DManager;
 
355
        }
 
356
        inline PagingLandScapeListenerManager          * getListenerManager()
 
357
        {
 
358
            assert(mListenerManager);
 
359
            return mListenerManager;
 
360
        }
 
361
        inline PagingLandScapeTextureManager           * getTextureManager()
 
362
        {
 
363
            assert(mTextureManager);
 
364
            return mTextureManager;
 
365
        }
 
366
        inline PagingLandScapeIndexBufferManager       * getIndexesManager()
 
367
        {
 
368
            assert(mIndexesManager);
 
369
            return mIndexesManager;
 
370
        }
 
371
        inline PagingLandScapeRenderableManager        * getRenderableManager()
 
372
        {
 
373
            assert(mRenderableManager);
 
374
            return mRenderableManager;
 
375
        }
 
376
        inline PagingLandScapeTextureCoordinatesManager* getTextureCoordinatesManager()
 
377
        {
 
378
            assert(mTexCoordManager);
 
379
            return mTexCoordManager;
 
380
        }
 
381
        inline PagingLandScapeIndexBufferManager* getIndexBufferManager()
 
382
        {
 
383
            assert(mIndexesManager);
 
384
            return mIndexesManager;
 
385
        }
 
386
        
 
387
 
 
388
    protected:
 
389
//          EntityList& getEntities(void)
 
390
//              {
 
391
//                      return mEntities;
 
392
//              }
 
393
 
 
394
            /** All the plugin options are handle here.
 
395
            */
 
396
            PagingLandScapeOptions* mOptions;
 
397
 
 
398
            /** LandScape 2D Data manager.
 
399
                    This class encapsulate the 2d data loading and unloading
 
400
            */
 
401
            PagingLandScapeData2DManager* mData2DManager;
 
402
 
 
403
            /** LandScape Texture manager.
 
404
                    This class encapsulate the texture loading and unloading
 
405
            */
 
406
            PagingLandScapeTextureManager* mTextureManager;
 
407
 
 
408
            /** LandScape tiles manager to avoid creating a deleting terrain tiles.
 
409
                    They are created at the plugin start and destroyed at the plugin unload.
 
410
            */
 
411
            PagingLandScapeTileManager* mTileManager;
 
412
 
 
413
            /** LandScape Renderable manager to avoid creating a deleting renderables.
 
414
                    They are created at the plugin start and destroyed at the plug in unload.
 
415
            */
 
416
            PagingLandScapeRenderableManager* mRenderableManager;
 
417
                /** LandScape pages Index Buffer sharing across pages for the terrain.
 
418
                */
 
419
                PagingLandScapeIndexBufferManager* mIndexesManager;
 
420
                /** LandScape pages texture coordinates sharing across pages for the terrain.
 
421
                */
 
422
                PagingLandScapeTextureCoordinatesManager* mTexCoordManager;
 
423
            /** LandScape pages for the terrain.
 
424
            */
 
425
            PagingLandScapePageManager* mPageManager;
 
426
 
 
427
            /** Horizon visibility testing.
 
428
            */
 
429
        PagingLandScapeHorizon* mHorizon;
 
430
 
 
431
            /** Dispatch scene manager events.
 
432
            */
 
433
        PagingLandScapeListenerManager* mListenerManager;
 
434
 
 
435
            bool mNeedOptionsUpdate;
 
436
 
 
437
            //JEFF - flag to indicate if the world geometry was setup
 
438
            bool mWorldGeomIsSetup;
 
439
        bool mWorldGeomIsInit;
 
440
 
 
441
        PagingLandScapeTileInfo* mImpactInfo;
 
442
        Ogre::Vector3 mImpact;  
 
443
        Ogre::Vector3 mBrushCenter;
 
444
        unsigned int mBrushSize;
 
445
       Ogre::Real mBrushScale;
 
446
 
 
447
       Ogre::Real* mCraterArray;
 
448
       Ogre::Real* mBrushArray;
 
449
 
 
450
        unsigned int mBrushArrayHeight;
 
451
        unsigned int mBrushArrayWidth;
 
452
 
 
453
                bool textureFormatChanged;
 
454
 
 
455
                MovableObjectFactory* mMeshDecalFactory;
 
456
 
 
457
        // re-create the default Crater brush.
 
458
        void resizeCrater ();  
 
459
 
 
460
    };
 
461
 
 
462
}
 
463
 
 
464
#endif