OGRE  1.7
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OgreTerrainSceneManager.h
Go to the documentation of this file.
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4 (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org/
6 
7 Copyright (c) 2000-2011 Torus Knot Software Ltd
8 
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15 
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 THE SOFTWARE.
26 -----------------------------------------------------------------------------
27 */
28 /***************************************************************************
29 terrainscenemanager.h - description
30 ---------------------
31  begin : Mon Sep 23 2002
32  copyright : (C) 2002 by Jon Anderson
33  email : janders@users.sf.net
34 
35  Enhancements 2003 - 2004 (C) The OGRE Team
36 
37 ***************************************************************************/
38 
39 #ifndef TERRAINSCENEMANAGER_H
40 #define TERRAINSCENEMANAGER_H
41 
43 #include "OgreOctreeSceneManager.h"
44 #include "OgreOctreeSceneQuery.h"
45 #include "OgreTerrainRenderable.h"
46 #include "OgreTerrainPageSource.h"
47 #include "OgreIteratorWrappers.h"
48 
49 
50 namespace Ogre
51 {
52 
53 class Image;
54 
57 
60 {
61 protected:
62  WorldFragment mWorldFrag;
63 public:
66 
68  void execute(RaySceneQueryListener* listener);
69 };
70 
71 
72 
79 {
80 public:
81  TerrainSceneManager(const String& name);
82  virtual ~TerrainSceneManager( );
83 
85  const String& getTypeName(void) const;
86 
88  void setWorldGeometry( const String& filename );
91  virtual void setWorldGeometry(DataStreamPtr& stream,
92  const String& typeName = StringUtil::BLANK);
93 
95  virtual void _renderVisibleObjects( void );
96 
98  float getHeightAt( float x, float y );
99 
100 
101  bool intersectSegment( const Vector3 & start, const Vector3 & end, Vector3 * result );
102 
104  void setWorldTexture(const String& textureName);
106  void setDetailTexture(const String& textureName);
108  void setDetailTextureRepeat(int repeat);
110  void setTileSize(int size);
112  void setPageSize(int size);
114  void setMaxPixelError(int pixelError);
116  void setScale(const Vector3& scale);
118  void setMaxGeoMipMapLevel(int maxMip);
119 
121  const String& getWorldTexture(void) { return mWorldTextureName; }
123  const String& getDetailTexture(void) { return mDetailTextureName; }
125  int getDetailTextureRepeat(void);
127  int getTileSize(void);
129  int getPageSize(void);
131  int getMaxPixelError(void);
133  const Vector3& getScale(void);
135  int getMaxGeoMipMapLevel(void);
136 
137 
138 
143  void setUseTriStrips(bool useStrips);
146  void setUseLODMorph(bool useMorph);
148  void setUseVertexNormals(bool useNormals);
150  void setUseVertexColours(bool useColours);
151 
177  void setCustomMaterial(const String& materialName);
196  void setCustomMaterialMorphFactorParam(const String& paramName);
215  void setCustomMaterialMorphFactorParam(size_t paramIndex);
218  void setLODMorphStart(Real morphStart);
219 
223  virtual TerrainRenderable * getTerrainTile( const Vector3 & pt );
224 
228  virtual TerrainPage* getTerrainPage( const Vector3 & pt );
229 
242  RaySceneQuery*
243  createRayQuery(const Ray& ray, unsigned long mask = 0xFFFFFFFF);
244 
248  Camera* createCamera( const String &name );
250  const TerrainOptions& getOptions(void) { return mOptions; }
251 
273  virtual bool setOption( const String &, const void * );
274 
278  virtual void setPrimaryCamera(const Camera* cam);
281 
285  PageSourceIterator getPageSourceIterator(void);
298  virtual void registerPageSource(const String& typeName, TerrainPageSource* source);
309  virtual void selectPageSource(const String& typeName,
310  TerrainPageSourceOptionList& optionList);
311 
322  virtual void attachPage(ushort pageX, ushort pageZ, TerrainPage* page);
324  MaterialPtr& getTerrainMaterial(void);
325  // Overridden from basic scene manager
326  void _renderScene(Camera *cam, Viewport *vp, bool includeOverlays);
327 
329  SceneNode* getTerrainRootNode(void) const { return mTerrainRoot; }
331  void clearScene(void);
333  void setWorldGeometryRenderQueue(uint8 qid);
334 
336  TerrainBufferCache& _getIndexCache(void) {return mIndexCache;}
337 
339  LevelArray& _getLevelIndex(void) { return mLevelIndex; }
340 
342  size_t _getPageCount(void) { return mTerrainPages.size(); }
343 
345  void shutdown(void);
346 
347 
348 protected:
349 
351  bool _checkSize( int s )
352  {
353  for ( int i = 0; i < 16; i++ )
354  {
355  printf( "Checking...%d\n", ( 1 << i ) + 1 );
356 
357  if ( s == ( 1 << i ) + 1 )
358  return true;
359  }
360 
361  return false;
362 
363  }
364 
386  unsigned short mLivePageMargin;
388  unsigned short mBufferedPageMargin;
391  //-- attributes to share across tiles
396 
398  void loadConfig(DataStreamPtr& stream);
399 
401  void setupTerrainMaterial(void);
403  void setupTerrainPages(void);
405  void initLevelIndexes(void);
407  void destroyLevelIndexes(void);
408 
409 
414 
415 };
418 {
419 protected:
422  void initMetaData(void) const;
423 public:
427  static const String FACTORY_TYPE_NAME;
428  SceneManager* createInstance(const String& instanceName);
429  void destroyInstance(SceneManager* instance);
430 };
431 
432 }
433 
434 #endif
Representation of a ray in space, i.e.
Definition: OgreRay.h:46
unsigned char uint8
Definition: OgrePlatform.h:248
A viewpoint from which the scene will be rendered.
Definition: OgreCamera.h:85
float Real
Software floating point type.
String mDetailTextureName
The name of the detail texture.
A simple class for encapsulating parameters which are commonly needed by both TerrainSceneManager and...
String mCustomMaterialName
The name of the custom material to use.
std::vector< T, A > type
void initMetaData(void) const
Internal method to initialise the metadata, must be implemented.
TerrainPageSource * mActivePageSource
The currently active page source.
Factory for TerrainSceneManager.
unsigned short mLivePageMargin
The number of pages to render outside the 'home' page.
PageSourceMap mPageSources
Map of source type -> TerrainPageSource.
SceneNode * mTerrainRoot
The node to which all terrain tiles are attached.
Manages the organisation and rendering of a 'scene' i.e.
bool mUseNamedParameterLodMorph
Are we using a named parameter to hook up LOD morph?
Octree implementation of RaySceneQuery.
const String & getDetailTexture(void)
Gets the texture to use for the detail texture.
ConstMapIterator< PageSourceMap > PageSourceIterator
Iterator over all page sources.
Default implementation of RaySceneQuery.
vector< TerrainPage * >::type TerrainPageRow
TerrainPage2D mTerrainPages
Grid of buffered pages.
LevelArray & _getLevelIndex(void)
Get the shared level index list (internal use only)
Class representing a node in the scene graph.
Definition: OgreSceneNode.h:57
vector< TerrainPageSource * >::type TerrainPageSources
TerrainOptions mOptions
Terrain size, detail etc.
vector< TerrainPageRow >::type TerrainPage2D
TerrainBufferCache mIndexCache
Shared list of index buffers.
Specialized SceneManager that divides the geometry into an octree in order to facilitate spatial quer...
static const String FACTORY_TYPE_NAME
Factory type name.
Alternative listener class for dealing with RaySceneQuery.
unsigned short mBufferedPageMargin
The number of pages to keep loaded outside the 'home' page.
TerrainBufferCache & _getIndexCache(void)
Get the shared list of indexes cached (internal use only)
String mLodMorphParamName
The name of the parameter to send the LOD morph to.
This is a basic SceneManager for organizing TerrainRenderables into a total landscape.
bool _checkSize(int s)
Validates that the size picked for the terrain is acceptable.
A cache of TerrainIndexBuffers.
size_t _getPageCount(void)
Get the current page count (internal use only)
bool mPagingEnabled
Whether paging is enabled, or whether a single page will be used.
const TerrainOptions & getOptions(void)
Gets the terrain options.
void destroyInstance(SceneManager *instance)
Destroy an instance of a SceneManager.
const String & getWorldTexture(void)
Gets the texture to use for the main world texture.
Standard 3-dimensional vector.
Definition: OgreVector3.h:51
Class representing an image file.
Definition: OgreImage.h:61
String mWorldTextureName
The name of the world texture.
unsigned short ushort
static const String BLANK
Constant blank string, useful for returning by ref where local does not exist.
Definition: OgreString.h:180
An abstraction of a viewport, i.e.
Definition: OgreViewport.h:56
vector< TerrainPageSourceOption >::type TerrainPageSourceOptionList
size_t mLodMorphParamIndex
The index of the parameter to send the LOD morph to.
vector< IndexMap * >::type LevelArray
Concrete IteratorWrapper for const access to the underlying key-value container.
map< String, TerrainPageSource * >::type PageSourceMap
Internal map of page source name to page source.
SceneNode * getTerrainRootNode(void) const
Get the SceneNode under which all terrain nodes are attached.
SceneManager * createInstance(const String &instanceName)
Create a new instance of a SceneManager.
Groups a number of TerrainRenderables (tiles) into a page, which is the unit of loading / unloading...
_StringBase String
LevelArray mLevelIndex
Shared array of IndexData (reuse indexes across tiles)
bool mUseCustomMaterial
Should we use an externally-defined custom material?
Specialisation of SharedPtr to allow SharedPtr to be assigned to MaterialPtr.
Definition: OgreMaterial.h:677
Abstract class which describes the interface which a source of terrain pages must implement...
Specialises the SceneQuery class for querying along a ray.
Class which will create instances of a given SceneManager.
Represents a terrain tile.