2
// C++ Interface: TerrainPage
7
// Author: Erik Hjortsberg <erik.hjortsberg@gmail.com>, (C) 2005
9
// This program is free software; you can redistribute it and/or modify
10
// it under the terms of the GNU General Public License as published by
11
// the Free Software Foundation; either version 2 of the License, or
12
// (at your option) any later version.
14
// This program is distributed in the hope that it will be useful,
15
// but WITHOUT ANY WARRANTY; without even the implied warranty of
16
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
// GNU General Public License for more details.
19
// You should have received a copy of the GNU General Public License
20
// along with this program; if not, write to the Free Software
21
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.//
23
#ifndef EMBEROGRETERRAINPAGE_H
24
#define EMBEROGRETERRAINPAGE_H
26
#include "../EmberOgrePrerequisites.h"
28
#include <Mercator/Terrain.h>
29
#include <Mercator/Segment.h>
30
#include <Mercator/Surface.h>
31
#include <Mercator/TerrainMod.h>
39
Mercator::Segment* segment;
42
typedef std::vector<PageSegment> SegmentVector;
45
#include "TerrainPageShadow.h"
55
class TerrainGenerator;
56
class TerrainPageSurface;
58
class TerrainPageFoliage;
59
class TerrainPageSurfaceLayer;
60
class ITerrainPageBridge;
61
class terrainModListEntry;
63
TYPEDEF_STL_MAP(const Mercator::Shader*, TerrainShader*, ShaderMap);
69
@brief Reprents one terrain page.
71
This is a bridge class between one Ogre terrain page instance and one or many Mercator::Segment. Since each Segment is 64x64 meters, but one Ogre page often is much larger, we need to combine many Segments for every single Ogre page.
73
Instances of this is created by TerrainGenerator.
74
One terrain page is composed of both height data, a material, textures for the material and plant positions for the foliage system. This class handles all of these, some of them directly and some by other classes.
76
@author Erik Hjortsberg <erik.hjortsberg@gmail.com>
79
friend class TerrainPageShadow;
80
friend class ITerrainPageShadowTechnique;
83
TerrainPage(TerrainPosition position, const std::map<const Mercator::Shader*, TerrainShader*> shaderMap, TerrainGenerator* generator);
89
* The number of Mercator::Segments for each axis. I.e. the root of the total number of segments.
90
* Mainly used to check if it's 1, in which case everything becomes much easier.
93
int getNumberOfSegmentsPerAxis() const;
97
* The max height of this page
100
float getMaxHeight();
103
* The minimum height of this page
106
float getMinHeight();
110
* @brief Generates the terrain materials needed.
111
* @param reselectTechnique If true, we'll also see if we need to reselect the technique to use.
112
* @return The new material created.
114
Ogre::MaterialPtr generateTerrainMaterials(bool reselectTechnique);
117
* Fills the bound height data with height data. If no buffer has been bound nothing will be done.
119
void updateOgreHeightData(Ogre::Real* heightData);
122
* The total number of vertices used for this page
125
long getVerticeCount() const;
128
* The position of the page in Worldforge space
131
const TerrainPosition& getWFPosition() const;
135
* The material used for the page
138
Ogre::MaterialPtr getMaterial();
141
* creates a new foliage for this page, but does not show it yet
143
void prepareFoliage();
146
* shows the foliage for this page, if no foliage exists it's created
152
* hides the foliage for this page, but does not destroy it
158
* destroys the foliage for this page
160
void destroyFoliage();
163
* this adds a shader to the page, meaning that it will be used in rendering
166
TerrainPageSurfaceLayer* addShader(TerrainShader* shader);
169
* Updates the shader texture for the specific shader
172
TerrainPageSurfaceLayer* updateShaderTexture(TerrainShader* shader, bool repopulate = true);
175
* Updates all the shader textures of the page.
176
* You should usually call this after you've made a change to the terrain and already have called populateSurfaces()
178
void updateAllShaderTextures(bool repopulate = true);
180
void populateSurfaces();
182
void populateSurface(TerrainShader* shader);
184
int getPageSize() const ;
188
void createShadow(const Ogre::Vector3& lightDirection);
190
void updateShadow(const Ogre::Vector3& lightDirection);
193
* The size in pixels of one side of the AlphaTexture. This is in sizes of 64.
196
int getAlphaTextureSize() const;
198
SegmentVector& getValidSegments();
201
* Gets the extent of this page in meters, in worldforge space.
204
const WFMath::AxisBox<2>& getExtent() const;
206
// const PlantsStore& getPlants() const;
208
TerrainPageSurface* getSurface() const;
210
TerrainPageFoliage* getPageFoliage() const;
212
TerrainPageShadow& getPageShadow();
215
* Gets the segment positioned at the supplied position in local space.
216
* @param pos A Wordforge position in local space, i.e. > 0 && < [width in meters of the page]
217
* @return A pointer to Mercator::Segment or null.
219
Mercator::Segment* getSegmentAtLocalPosition(const TerrainPosition& pos) const;
222
* Gets the segment positioned at the supplied position in local space and also translates the supplied position into a local position in the returned segment.
223
* @param pos A Wordforge position in local space, i.e. > 0 && < [width in meters of the page]
224
* @param localPositionInSegment The resulting position in the segment space.
225
* @return A pointer to Mercator::Segment or null.
227
Mercator::Segment* getSegmentAtLocalPosition(const TerrainPosition& pos, TerrainPosition& localPositionInSegment) const;
231
* @brief Binds a bridge instance to this page.
232
* The bridge will be responsible for updating the terrain engine after the Mercator terrain has changed.
233
* This class won't take ownership of the bridge, so it's up to the calling class to make sure that it's properly destroyed, and when so also calling @see unregisterBridge()
234
* @param bridge A vlid bridge instance.
236
void registerBridge(ITerrainPageBridge* bridge);
239
* @brief Unregisters the current terrain bridge.
240
* Make sure to call this when the bridge is destroyed, so as not to leave any dangling pointers. This won't however delete the bridge.
242
void unregisterBridge();
246
* @brief Gets the normal at the specified local position.
247
* @param localPosition The position, local to the page.
248
* @param normal The normal will be placed here.
249
* @return True if a valid normal could be found at the specified position.
251
bool getNormal(const TerrainPosition& localPosition, WFMath::Vector<3>& normal) const;
256
SegmentVector mValidSegments;
260
this holds a map of the area, to be used in a map widget etc.
262
Ogre::TexturePtr mMap;
265
TerrainGenerator* mGenerator;
270
TerrainPosition mPosition;
274
* gets a segment for the x and y position in the page
279
Mercator::Segment* getSegmentAtLocalIndex(int indexX, int indexY) const;
285
* How much to scale the alpha map. This is done to avoid pixelated terrain (a blur filter is applied).
286
This value is taken from the config file.
288
unsigned int getAlphaMapScale() const;
290
std::auto_ptr<TerrainPageSurface> mTerrainSurface;
291
TerrainPageShadow mShadow;
292
ITerrainPageShadowTechnique* mShadowTechnique;
293
void setupShadowTechnique();
296
The extent of this page in meters, in WF space.
298
const WFMath::AxisBox<2> mExtent;
299
std::auto_ptr<TerrainPageFoliage> mPageFoliage;
302
A local copy of the segments for fast lookup. This will also include nonvalid segments.
303
The keys will be the local indices.
305
Mercator::Terrain::Segmentstore mLocalSegments;
309
@brief Bridge to the ogre terrain engine.
310
When the terrain data is changed we need to also update the actual ingame representation that the terrain engine provides. This instance will take care of that.
312
ITerrainPageBridge* mBridge;
317
inline int TerrainPage::getAlphaTextureSize( ) const
319
return (getPageSize() - 1);