OGRE  1.7
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OgreTerrainZoneRenderable.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 OgreTerrainZoneRenderable.h - based on OgreTerrainRenderable.h from Ogre3d
28 
29 -----------------------------------------------------------------------------
30 begin : Thu May 3 2007
31 author : Eric Cha
32 email : ericcATxenopiDOTcom
33 -----------------------------------------------------------------------------
34 */
35 
36 #ifndef TERRAINZONERENDERABLE_H
37 #define TERRAINZONERENDERABLE_H
38 
40 #include <OgreRenderable.h>
41 #include <OgreMovableObject.h>
42 #include <OgreAxisAlignedBox.h>
43 #include <OgreString.h>
45 
46 #include <vector>
47 
48 #define MORPH_CUSTOM_PARAM_ID 77
49 
50 namespace Ogre
51 {
52 
53  typedef map<unsigned int, IndexData* >::type IndexMap;
56 
62  {
63  public:
64  void shutdown(void)
65  {
66  for( size_t i=0; i<mCache.size(); i++ )
67  {
69  }
70  mCache.clear();
71  }
73  {
74  shutdown();
75  }
76 
78  };
79 
84  {
85  public:
87  {
88  pageSize = 0;
89  tileSize = 0;
90  tilesPerPage = 0;
93  maxPixelError = 4;
94  detailTile = 1;
95  lit = false;
96  coloured = false;
97  lodMorph = false;
98  lodMorphStart = 0.5;
99  useTriStrips = false;
100  primaryCamera = 0;
102  };
104  size_t pageSize;
106  size_t tileSize;
108  size_t tilesPerPage;
121  size_t detailTile;
123  bool lodMorph;
127  bool lit;
129  bool coloured;
132 
133  };
134 
135 #define STITCH_NORTH_SHIFT 0
136 #define STITCH_SOUTH_SHIFT 8
137 #define STITCH_WEST_SHIFT 16
138 #define STITCH_EAST_SHIFT 24
139 
140 #define STITCH_NORTH 128 << STITCH_NORTH_SHIFT
141 #define STITCH_SOUTH 128 << STITCH_SOUTH_SHIFT
142 #define STITCH_WEST 128 << STITCH_WEST_SHIFT
143 #define STITCH_EAST 128 << STITCH_EAST_SHIFT
144 
154  {
155  public:
156 
157  TerrainZoneRenderable(const String& name, TerrainZone* tz);
159 
160  void deleteGeometry();
161 
162  enum Neighbor
163  {
164  NORTH = 0,
165  SOUTH = 1,
166  EAST = 2,
167  WEST = 3,
168  HERE = 4
169  };
170 
177  void initialise(int startx, int startz, Real* pageHeightData);
178 
179  //movable object methods
180 
182  virtual const String& getMovableType( void ) const
183  {
184  return mType;
185  };
186 
188  const AxisAlignedBox& getBoundingBox( void ) const
189  {
190  return mBounds;
191  };
192 
194  virtual void _notifyCurrentCamera( Camera* cam );
195 
196  virtual void _updateRenderQueue( RenderQueue* queue );
197 
199  void visitRenderables(Renderable::Visitor* visitor,
200  bool debugRenderables = false);
207  virtual void getRenderOperation( RenderOperation& rend );
208 
209  virtual const MaterialPtr& getMaterial( void ) const
210  {
211  return mMaterial;
212  };
213 
214  virtual void getWorldTransforms( Matrix4* xform ) const;
215 
216  virtual const Quaternion& getWorldOrientation(void) const;
217  virtual const Vector3& getWorldPosition(void) const;
218 
220  inline int getRenderLevel() const
221  {
222  return mRenderLevel;
223  };
224 
226  inline void setForcedRenderLevel( int i )
227  {
228  mForcedRenderLevel = i;
229  }
230 
232  void _getNormalAt( float x, float y, Vector3 * result );
233 
235  float getHeightAt( float x, float y );
236 
239  bool intersectSegment( const Vector3 & start, const Vector3 & end, Vector3 * result );
240 
245  {
246  mNeighbors[ n ] = t;
247  };
248 
252  {
253  return mNeighbors[ n ];
254  }
255 
256 
257  void setMaterial(const MaterialPtr& m )
258  {
259  mMaterial = m;
260  };
261 
263  void _calculateNormals();
264 
265 
266 
267 
270  void _generateVertexLighting( const Vector3 &sunlight, ColourValue ambient );
271 
272 
274  Real getSquaredViewDepth(const Camera* cam) const;
275 
277  Real getBoundingRadius(void) const { return mBoundingRadius; }
278 
280  const LightList& getLights(void) const;
281 
283  void _updateCustomGpuParameter(
284  const GpuProgramParameters::AutoConstantEntry& constantEntry,
285  GpuProgramParameters* params) const;
287  uint32 getTypeFlags(void) const;
288  protected:
293 
295  inline size_t _index( int x, int z ) const
296  {
297  return ( x + z * mOptions->tileSize );
298  };
299 
301  inline float _vertex( int x, int z, int n )
302  {
303  return mPositionBuffer[x * 3 + z * mOptions->tileSize * 3 + n];
304  };
305 
306 
307  inline int _numNeighbors() const
308  {
309  int n = 0;
310 
311  for ( int i = 0; i < 4; i++ )
312  {
313  if ( mNeighbors[ i ] != 0 )
314  n++;
315  }
316 
317  return n;
318  }
319 
320  inline bool _hasNeighborRenderLevel( int i ) const
321  {
322  for ( int j = 0; j < 4; j++ )
323  {
324  if ( mNeighbors[ j ] != 0 && mNeighbors[ j ] ->mRenderLevel == i )
325  return true;
326  }
327 
328  return false;
329 
330  }
331 
332  void _adjustRenderLevel( int i );
333 
334  bool _checkSize( int n );
335 
336  void _calculateMinLevelDist2( Real C );
337 
338  Real _calculateCFactor();
339 
341 
351  TerrainZoneRenderable *mNeighbors [ 4 ];
353  mutable bool mLightListDirty;
363  static String mType;
367  bool mInit;
379  int mNextLevelDown[10];
381  IndexData* getIndexData(void);
383  IndexData* generateTriStripIndexes(unsigned int stitchFlags);
385  IndexData* generateTriListIndexes(unsigned int stitchFlags);
400  int stitchEdge(Neighbor neighbor, int hiLOD, int loLOD,
401  bool omitFirstTri, bool omitLastTri, unsigned short** ppIdx);
402 
404  HardwareVertexBufferSharedPtr createDeltaBuffer(void);
405 
406  };
407 
408 }
409 
410 #endif
size_t tilesPerPage
Precalculated number of tiles per page.
A viewpoint from which the scene will be rendered.
Definition: OgreCamera.h:85
void setForcedRenderLevel(int i)
Forces the LOD to the given level from this point on.
Real getBoundingRadius(void) const
Overridden from MovableObject.
Class encapsulating a standard 4x4 homogeneous matrix.
Definition: OgreMatrix4.h:78
bool lodMorph
Whether LOD morphing is enabled.
LightList mLightList
Cached light list.
map< unsigned int, IndexData * >::type IndexMap
float Real
Software floating point type.
unsigned int uint32
Definition: OgrePlatform.h:246
std::vector< IndexData *, A > type
This is a basic PCZone for organizing TerrainRenderables into a total landscape.
Class representing colour.
const Camera * primaryCamera
The primary camera, used for error metric calculation and page choice.
const TerrainZoneOptions * mOptions
Link to shared options.
bool coloured
Whether vertex colours are enabled.
A simple class for encapsulating parameters which are commonly needed by both TerrainSceneManager and...
Shared pointer implementation used to share index buffers.
A 3D box aligned with the x/y/z axes.
size_t detailTile
The number of times to repeat a detail texture over a tile.
float * mPositionBuffer
System-memory buffer with just positions in it, for CPU operations.
#define _OgreOctreeZonePluginExport
vector< IndexData * >::type IndexArray
Abstract class defining a movable object in a scene.
Abstract class defining the interface all renderable objects must implement.
Implementation of a Quaternion, i.e.
size_t maxPixelError
The maximum pixel error allowed.
bool mInit
Whether this tile has been initialised.
TerrainZoneRenderable * _getNeighbor(Neighbor n)
Returns the neighbor TerrainZoneRenderable.
Structure recording the use of an automatic parameter.
Vector3 scale
The scale factor to apply to the terrain (each vertex is 1 unscaled unit away from the next...
void setNull(void)
const AxisAlignedBox & getBoundingBox(void) const
Returns the bounding box of this TerrainZoneRenderable.
int mLastNextLevel
The previous 'next' LOD level down, for frame coherency.
AxisAlignedBox mBounds
Bounding box of this tile.
size_t tileSize
The size of one edge of a terrain tile, in vertices.
int mRenderLevel
The current LOD level.
void _setNeighbor(Neighbor n, TerrainZoneRenderable *t)
Sets the appropriate neighbor for this TerrainZoneRenderable.
size_t pageSize
The size of one edge of a terrain page, in vertices.
bool lit
Whether dynamic lighting is enabled.
virtual const MaterialPtr & getMaterial(void) const
Retrieves a weak reference to the material this renderable object uses.
void setMaterial(const MaterialPtr &m)
int getRenderLevel() const
Returns the mipmap level that will be rendered for this frame.
Real lodMorphStart
At what point (parametric) should LOD morphing start.
Collects together the program parameters used for a GpuProgram.
bool mLightListDirty
Whether light list need to re-calculate.
Summary class collecting together index data source information.
TerrainZone * mTerrainZone
Parent Zone.
Real * mMinLevelDistSqr
List of squared distances at which LODs change.
bool useTriStrips
Whether we should use triangle strips.
Visitor object that can be used to iterate over a collection of Renderable instances abstractly...
MaterialPtr terrainMaterial
Pointer to the material to use to render the terrain.
HardwareVertexBufferSharedPtr mMainBuffer
The buffer with all the renderable geometry in it.
#define OGRE_DELETE
Standard 3-dimensional vector.
Definition: OgreVector3.h:51
A cache of TerrainIndexBuffers.
MaterialPtr mMaterial
Current material used by this tile.
Summary class collecting together vertex source information.
'New' rendering operation using vertex buffers.
virtual const String & getMovableType(void) const
Returns the type of the movable.
vector< HardwareVertexBufferSharedPtr >::type VertexBufferList
Optional set of delta buffers, used to morph from one LOD to the next.
vector< IndexMap * >::type LevelArray
Class to manage the scene object rendering queue.
Represents a terrain tile.
size_t _index(int x, int z) const
Returns the index into the height array for the given coords.
_StringBase String
Real mBoundingRadius
The bounding radius of this tile.
Specialisation of SharedPtr to allow SharedPtr to be assigned to MaterialPtr.
Definition: OgreMaterial.h:677
float _vertex(int x, int z, int n)
Returns the vertex coord for the given coordinates.
Real mLODMorphFactor
The morph factor between this and the next LOD level down.
size_t maxGeoMipMapLevel
The maximum terrain geo-mipmap level.
static const Vector3 UNIT_SCALE
Definition: OgreVector3.h:781
int mForcedRenderLevel
Forced rendering LOD level, optional.
Vector3 mCenter
The center point of this tile.
static String mType
The MovableObject type.