1
/***************************************************************************
2
OgrePagingLandScapeSceneManager.h - description
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
***************************************************************************/
9
/***************************************************************************
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. *
16
***************************************************************************/
18
#ifndef PAGINGLandScapeSCENEMANAGER_H
19
#define PAGINGLandScapeSCENEMANAGER_H
21
#include "OgrePagingLandScapePrerequisites.h"
22
#include "OgrePagingLandScapeOctreeSceneManager.h"
23
#include "OgrePagingLandScapeOptions.h"
24
#include "OgreStringVector.h"
26
#include "OgrePagingLandScapeData2DManager.h"
31
/// Factory for OctreeSceneManager
32
class PagingLandScapeSceneManagerFactory : public SceneManagerFactory
35
void initMetaData(void) const;
37
PagingLandScapeSceneManagerFactory() {}
38
~PagingLandScapeSceneManagerFactory() {}
40
static const String FACTORY_TYPE_NAME;
41
SceneManager* createInstance(const String& instanceName);
42
void destroyInstance(SceneManager* instance);
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.
50
class PagingLandScapeSceneManager : public PagingLandScapeOctreeSceneManager
52
friend class PagingLandScapeRaySceneQuery;
54
PagingLandScapeSceneManager(const String &name);
55
~PagingLandScapeSceneManager(void);
58
/// @copydoc SceneManager::getTypeName
59
const String& getTypeName(void) const;
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);
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.
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".
79
virtual void setWorldGeometry(const String& filename);
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.
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.
96
virtual void setWorldGeometry(DataStreamPtr& stream,
97
const String& typeName = StringUtil::BLANK);
100
/** Things that need to be allocated once
102
void InitScene(void);
104
/** Empties the entire scene, including all SceneNodes, Cameras, Entities and Lights etc.
106
void clearScene(void);
108
/** Empties only the Terrain Scene pages, tiles, textures and so on
110
void resetScene(void);
112
/** Loads the LandScape using current parameters
114
void loadScene(void);
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.
120
strKey The name of the option to set
122
pValue A pointer to the value - the size should be calculated by the scene manager
125
On success, true is returned.
127
On failure, false is returned.
129
bool setOption(const String& strKey, const void* pValue);
131
/** Method for getting the value of an implementation-specific Scene Manager option.
133
strKey The name of the option
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
139
On success, true is returned and pDestValue points to the value of the given
142
On failiure, false is returned and pDestValue is set to NULL.
144
bool getOption(const String& strKey, void* pDestValue);
146
/** Method for verifying wether the scene manager has an implementation-specific
149
strKey The name of the option to check for.
151
If the scene manager contains the given option, true is returned.
153
If it does not, false is returned.
155
bool hasOption(const String& strKey) const;
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
163
strKey The name of the option to get the values for.
165
refValueList A reference to a list that will be filled with the available values.
167
On success (the option exists), true is returned.
169
On failiure, false is returned.
171
bool getOptionValues(const String& key, StringVector& refValueList);
173
/** Method for getting all the implementation-specific options of the scene manager.
175
refKeys A reference to a list that will be filled with all the available options.
177
On success, true is returned.
178
On failiure, false is returned.
180
bool getOptionKeys(StringVector &refKeys);
182
/** Internal method for updating the scene graph ie the tree of SceneNode instances managed by this class.
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
190
void _updateSceneGraph(Camera* cam);
192
/** Sends visible objects found in _findVisibleObjects to the rendering engine.
194
//void _renderVisibleObjects(void);
196
/** Internal method which parses the scene to find visible objects to render.
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
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.
207
//void _findVisibleObjects(Camera * cam, bool onlyShadowCasters);
209
/** Creates an AxisAlignedBoxSceneQuery for this scene manager.
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
214
Currently this only supports custom geometry results. It ignores the y
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.
223
AxisAlignedBoxSceneQuery* createAABBQuery(const AxisAlignedBox& box, unsigned long mask = 0xFFFFFFFF);
226
/** Creates a RaySceneQuery for this scene manager.
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
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.
238
RaySceneQuery* createRayQuery(const Ray& ray, unsigned long mask = 0xFFFFFFFF);
240
/** Creates an IntersectionSceneQuery for this scene manager.
242
This method creates a new instance of a query object for locating
243
intersecting objects. See SceneQuery and IntersectionSceneQuery
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.
251
//IntersectionSceneQuery* createIntersectionQuery(unsigned long mask);
255
Intersect mainly with LandScape
257
begining of the segment
261
where it intersects with terrain
263
bool intersectSegment(const Ogre::Vector3& start, const Ogre::Vector3& end, Ogre::Vector3* result);
267
Intersect mainly with LandScape
269
begining of the segment
273
where it intersects with terrain
275
bool intersectSegmentTerrain(const Ogre::Vector3& begin, const Ogre::Vector3& dir, Ogre::Vector3* result);
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
280
void setHeight (const Ogre::Vector3 &impact);
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
285
void deformHeight(const Ogre::Vector3& impact);
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
291
void paint (const Ogre::Vector3 &impact);
293
* @remarks used to fill user allocated array with values.
294
* @param impact where array is centered
296
void getAreaHeight(const Ogre::Vector3& impact);
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
304
void renderBaseTextures(const String& alternateMatName);
306
/** Overridden from SceneManager */
307
void setWorldGeometryRenderQueue(uint8 qid);
309
void PagingLandScapeOctreeResize(void);
311
void WorldDimensionChange(void);
313
//-----------------------------------------------------------------------
314
inline Ogre::Real _OgrePagingLandScapeExport getHeightAt(const Ogre::Real x, const Ogre::Real z)
316
return mData2DManager->getInterpolatedWorldHeight(x, z);
318
//-----------------------------------------------------------------------
319
inline Ogre::Real _OgrePagingLandScapeExport getSlopeAt(const Ogre::Real x, const Ogre::Real z)
322
// return mData2DManager->getRealWorldSlope(x, z);
323
mData2DManager->getInterpolatedWorldHeight(x, z, &slope);
327
_OgrePagingLandScapeExport void getWorldSize(Real *worldSizeX,Ogre::Real *worldSizeZ);
328
_OgrePagingLandScapeExport float getMaxSlope(Vector3 location1, Ogre::Vector3 location2, float maxSlopeIn);
330
inline PagingLandScapeOptions * getOptions()
336
inline PagingLandScapeHorizon * getHorizon()
341
inline PagingLandScapeTileManager * getTileManager()
343
assert(mTileManager);
346
inline PagingLandScapePageManager * getPageManager()
348
assert(mPageManager);
351
inline PagingLandScapeData2DManager * getData2DManager()
353
assert(mData2DManager);
354
return mData2DManager;
356
inline PagingLandScapeListenerManager * getListenerManager()
358
assert(mListenerManager);
359
return mListenerManager;
361
inline PagingLandScapeTextureManager * getTextureManager()
363
assert(mTextureManager);
364
return mTextureManager;
366
inline PagingLandScapeIndexBufferManager * getIndexesManager()
368
assert(mIndexesManager);
369
return mIndexesManager;
371
inline PagingLandScapeRenderableManager * getRenderableManager()
373
assert(mRenderableManager);
374
return mRenderableManager;
376
inline PagingLandScapeTextureCoordinatesManager* getTextureCoordinatesManager()
378
assert(mTexCoordManager);
379
return mTexCoordManager;
381
inline PagingLandScapeIndexBufferManager* getIndexBufferManager()
383
assert(mIndexesManager);
384
return mIndexesManager;
389
// EntityList& getEntities(void)
394
/** All the plugin options are handle here.
396
PagingLandScapeOptions* mOptions;
398
/** LandScape 2D Data manager.
399
This class encapsulate the 2d data loading and unloading
401
PagingLandScapeData2DManager* mData2DManager;
403
/** LandScape Texture manager.
404
This class encapsulate the texture loading and unloading
406
PagingLandScapeTextureManager* mTextureManager;
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.
411
PagingLandScapeTileManager* mTileManager;
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.
416
PagingLandScapeRenderableManager* mRenderableManager;
417
/** LandScape pages Index Buffer sharing across pages for the terrain.
419
PagingLandScapeIndexBufferManager* mIndexesManager;
420
/** LandScape pages texture coordinates sharing across pages for the terrain.
422
PagingLandScapeTextureCoordinatesManager* mTexCoordManager;
423
/** LandScape pages for the terrain.
425
PagingLandScapePageManager* mPageManager;
427
/** Horizon visibility testing.
429
PagingLandScapeHorizon* mHorizon;
431
/** Dispatch scene manager events.
433
PagingLandScapeListenerManager* mListenerManager;
435
bool mNeedOptionsUpdate;
437
//JEFF - flag to indicate if the world geometry was setup
438
bool mWorldGeomIsSetup;
439
bool mWorldGeomIsInit;
441
PagingLandScapeTileInfo* mImpactInfo;
442
Ogre::Vector3 mImpact;
443
Ogre::Vector3 mBrushCenter;
444
unsigned int mBrushSize;
445
Ogre::Real mBrushScale;
447
Ogre::Real* mCraterArray;
448
Ogre::Real* mBrushArray;
450
unsigned int mBrushArrayHeight;
451
unsigned int mBrushArrayWidth;
453
bool textureFormatChanged;
455
MovableObjectFactory* mMeshDecalFactory;
457
// re-create the default Crater brush.
458
void resizeCrater ();