OGRE  1.7
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OgreTerrainRenderable.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 terrainrenderable.h - description
30 -------------------
31 begin : Sat Oct 5 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 TERRAINRENDERABLE_H
40 #define TERRAINRENDERABLE_H
41 
43 #include <OgreRenderable.h>
44 #include <OgreMovableObject.h>
45 #include <OgreAxisAlignedBox.h>
46 #include <OgreString.h>
48 
49 #include <vector>
50 
51 #define MORPH_CUSTOM_PARAM_ID 77
52 
53 namespace Ogre
54 {
55 
59 
65  {
66  public:
67  void shutdown(void)
68  {
69  for( size_t i=0; i<mCache.size(); i++ )
70  {
72  }
73  mCache.clear();
74  }
76  {
77  shutdown();
78  }
79 
81  };
82 
87  {
88  public:
90  {
91  pageSize = 0;
92  tileSize = 0;
93  tilesPerPage = 0;
96  maxPixelError = 4;
97  detailTile = 1;
98  lit = false;
99  coloured = false;
100  lodMorph = false;
101  lodMorphStart = 0.5;
102  useTriStrips = false;
103  primaryCamera = 0;
105  };
107  size_t pageSize;
109  size_t tileSize;
111  size_t tilesPerPage;
124  size_t detailTile;
126  bool lodMorph;
130  bool lit;
132  bool coloured;
135 
136  };
137 
138 #define STITCH_NORTH_SHIFT 0
139 #define STITCH_SOUTH_SHIFT 8
140 #define STITCH_WEST_SHIFT 16
141 #define STITCH_EAST_SHIFT 24
142 
143 #define STITCH_NORTH 128 << STITCH_NORTH_SHIFT
144 #define STITCH_SOUTH 128 << STITCH_SOUTH_SHIFT
145 #define STITCH_WEST 128 << STITCH_WEST_SHIFT
146 #define STITCH_EAST 128 << STITCH_EAST_SHIFT
147 
157  {
158  public:
159 
160  TerrainRenderable(const String& name, TerrainSceneManager* tsm);
162 
163  void deleteGeometry();
164 
165  enum Neighbor
166  {
167  NORTH = 0,
168  SOUTH = 1,
169  EAST = 2,
170  WEST = 3,
171  HERE = 4
172  };
173 
180  void initialise(int startx, int startz, Real* pageHeightData);
181 
182  //movable object methods
183 
185  virtual const String& getMovableType( void ) const
186  {
187  return mType;
188  };
189 
191  const AxisAlignedBox& getBoundingBox( void ) const
192  {
193  return mBounds;
194  };
195 
197  virtual void _notifyCurrentCamera( Camera* cam );
198 
199  virtual void _updateRenderQueue( RenderQueue* queue );
200 
202  void visitRenderables(Renderable::Visitor* visitor,
203  bool debugRenderables = false);
204 
211  virtual void getRenderOperation( RenderOperation& rend );
212 
213  virtual const MaterialPtr& getMaterial( void ) const
214  {
215  return mMaterial;
216  };
217 
218  virtual void getWorldTransforms( Matrix4* xform ) const;
219 
221  inline int getRenderLevel() const
222  {
223  return mRenderLevel;
224  };
225 
227  inline void setForcedRenderLevel( int i )
228  {
229  mForcedRenderLevel = i;
230  }
231 
233  void _getNormalAt( float x, float y, Vector3 * result );
234 
236  float getHeightAt( float x, float y );
237 
240  bool intersectSegment( const Vector3 & start, const Vector3 & end, Vector3 * result );
241 
246  {
247  mNeighbors[ n ] = t;
248  };
249 
253  {
254  return mNeighbors[ n ];
255  }
256 
257 
258  void setMaterial(const MaterialPtr& m )
259  {
260  mMaterial = m;
261  };
262 
264  void _calculateNormals();
265 
266 
267 
268 
271  void _generateVertexLighting( const Vector3 &sunlight, ColourValue ambient );
272 
273 
275  Real getSquaredViewDepth(const Camera* cam) const;
276 
278  Real getBoundingRadius(void) const { return mBoundingRadius; }
279 
281  const LightList& getLights(void) const;
282 
284  void _updateCustomGpuParameter(
285  const GpuProgramParameters::AutoConstantEntry& constantEntry,
286  GpuProgramParameters* params) const;
288  uint32 getTypeFlags(void) const;
289  protected:
294 
296  inline size_t _index( int x, int z ) const
297  {
298  return ( x + z * mOptions->tileSize );
299  };
300 
302  inline float _vertex( int x, int z, int n )
303  {
304  return mPositionBuffer[x * 3 + z * mOptions->tileSize * 3 + n];
305  };
306 
307 
308  inline int _numNeighbors() const
309  {
310  int n = 0;
311 
312  for ( int i = 0; i < 4; i++ )
313  {
314  if ( mNeighbors[ i ] != 0 )
315  n++;
316  }
317 
318  return n;
319  }
320 
321  inline bool _hasNeighborRenderLevel( int i ) const
322  {
323  for ( int j = 0; j < 4; j++ )
324  {
325  if ( mNeighbors[ j ] != 0 && mNeighbors[ j ] ->mRenderLevel == i )
326  return true;
327  }
328 
329  return false;
330 
331  }
332 
333  void _adjustRenderLevel( int i );
334 
335  bool _checkSize( int n );
336 
337  void _calculateMinLevelDist2( Real C );
338 
339  Real _calculateCFactor();
340 
342 
352  TerrainRenderable *mNeighbors [ 4 ];
354  mutable bool mLightListDirty;
364  static String mType;
368  bool mInit;
380  int mNextLevelDown[10];
382  IndexData* getIndexData(void);
384  IndexData* generateTriStripIndexes(unsigned int stitchFlags);
386  IndexData* generateTriListIndexes(unsigned int stitchFlags);
401  int stitchEdge(Neighbor neighbor, int hiLOD, int loLOD,
402  bool omitFirstTri, bool omitLastTri, unsigned short** ppIdx);
403 
405  HardwareVertexBufferSharedPtr createDeltaBuffer(void);
406 
407  };
408 
409 }
410 
411 #endif
Real lodMorphStart
At what point (parametric) should LOD morphing start.
void setMaterial(const MaterialPtr &m)
LightList mLightList
Cached light list.
A viewpoint from which the scene will be rendered.
Definition: OgreCamera.h:85
TerrainRenderable * _getNeighbor(Neighbor n)
Returns the neighbor TerrainRenderable.
bool coloured
Whether vertex colours are enabled.
Class encapsulating a standard 4x4 homogeneous matrix.
Definition: OgreMatrix4.h:78
map< unsigned int, IndexData * >::type IndexMap
float Real
Software floating point type.
Real * mMinLevelDistSqr
List of squared distances at which LODs change.
unsigned int uint32
Definition: OgrePlatform.h:246
bool lodMorph
Whether LOD morphing is enabled.
Real mBoundingRadius
The bounding radius of this tile.
A simple class for encapsulating parameters which are commonly needed by both TerrainSceneManager and...
size_t tilesPerPage
Precalculated number of tiles per page.
MaterialPtr mMaterial
Current material used by this tile.
Real getBoundingRadius(void) const
Overridden from MovableObject.
AxisAlignedBox mBounds
Bounding box of this tile.
Class representing colour.
size_t maxGeoMipMapLevel
The maximum terrain geo-mipmap level.
size_t pageSize
The size of one edge of a terrain page, in vertices.
HardwareVertexBufferSharedPtr mMainBuffer
The buffer with all the renderable geometry in it.
Shared pointer implementation used to share index buffers.
A 3D box aligned with the x/y/z axes.
virtual const MaterialPtr & getMaterial(void) const
Retrieves a weak reference to the material this renderable object uses.
bool _hasNeighborRenderLevel(int i) const
int mLastNextLevel
The previous 'next' LOD level down, for frame coherency.
float _vertex(int x, int z, int n)
Returns the vertex coord for the given coordinates.
TerrainSceneManager * mSceneManager
Parent SceneManager.
Vector3 scale
The scale factor to apply to the terrain (each vertex is 1 unscaled unit away from the next...
vector< IndexData * >::type IndexArray
void _setNeighbor(Neighbor n, TerrainRenderable *t)
Sets the appropriate neighbor for this TerrainRenderable.
Abstract class defining a movable object in a scene.
size_t maxPixelError
The maximum pixel error allowed.
size_t _index(int x, int z) const
Returns the index into the height array for the given coords.
Abstract class defining the interface all renderable objects must implement.
Structure recording the use of an automatic parameter.
void setNull(void)
This is a basic SceneManager for organizing TerrainRenderables into a total landscape.
float * mPositionBuffer
System-memory buffer with just positions in it, for CPU operations.
bool mLightListDirty
Whether light list need to re-calculate.
A cache of TerrainIndexBuffers.
size_t detailTile
The number of times to repeat a detail texture over a tile.
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
Collects together the program parameters used for a GpuProgram.
Summary class collecting together index data source information.
Vector3 mCenter
The center point of this tile.
Visitor object that can be used to iterate over a collection of Renderable instances abstractly...
int mRenderLevel
The current LOD level.
vector< HardwareVertexBufferSharedPtr >::type VertexBufferList
Optional set of delta buffers, used to morph from one LOD to the next.
const TerrainOptions * mOptions
Link to shared options.
#define OGRE_DELETE
size_t tileSize
The size of one edge of a terrain tile, in vertices.
MaterialPtr terrainMaterial
Pointer to the material to use to render the terrain.
Standard 3-dimensional vector.
Definition: OgreVector3.h:51
std::map< K, V, P, A > type
const Camera * primaryCamera
The primary camera, used for error metric calculation and page choice.
bool lit
Whether dynamic lighting is enabled.
Summary class collecting together vertex source information.
'New' rendering operation using vertex buffers.
const AxisAlignedBox & getBoundingBox(void) const
Returns the bounding box of this TerrainRenderable.
int mForcedRenderLevel
Forced rendering LOD level, optional.
vector< IndexMap * >::type LevelArray
Class to manage the scene object rendering queue.
int getRenderLevel() const
Returns the mipmap level that will be rendered for this frame.
_StringBase String
static String mType
The MovableObject type.
bool mInit
Whether this tile has been initialised.
Specialisation of SharedPtr to allow SharedPtr to be assigned to MaterialPtr.
Definition: OgreMaterial.h:677
bool useTriStrips
Whether we should use triangle strips.
Real mLODMorphFactor
The morph factor between this and the next LOD level down.
static const Vector3 UNIT_SCALE
Definition: OgreVector3.h:781
virtual const String & getMovableType(void) const
Returns the type of the movable.
void setForcedRenderLevel(int i)
Forces the LOD to the given level from this point on.
Represents a terrain tile.