2
// C++ Interface: TerrainPageFoliage
7
// Author: Erik Hjortsberg <erik.hjortsberg@gmail.com>, (C) 2008
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 EMBEROGRE_TERRAINTERRAINPAGEFOLIAGE_H
24
#define EMBEROGRE_TERRAINTERRAINPAGEFOLIAGE_H
27
#include <OgreCommon.h>
28
#include <OgreSharedPtr.h>
29
#include <OgreDataStream.h>
30
#include <OgreMemoryAllocatorConfig.h>
34
class MemoryDataStream;
43
class TerrainGenerator;
44
class TerrainPageSurface;
46
class TerrainPageFoliage;
47
class TerrainLayerDefinition;
49
// struct PlantPosition
52
// unsigned char rotation;
57
@author Erik Hjortsberg <erik.hjortsberg@gmail.com>
59
class TerrainPageFoliage
63
A store of plant positions. We keep this in ogre space for performance reasons.
65
typedef std::vector<Ogre::Vector2, Ogre::STLAllocator<Ogre::Vector2, Ogre::CategorisedAlignAllocPolicy<Ogre::MEMCATEGORY_GEOMETRY> > > PlantStore;
66
typedef std::map<int, PlantStore> PlantBatchColumn;
67
typedef std::map<int, PlantBatchColumn> PlantBatchStore;
68
typedef std::map<std::string, PlantBatchStore> PlantStoreMap;
70
TerrainPageFoliage(TerrainGenerator& generator, TerrainPage& page);
71
virtual ~TerrainPageFoliage();
75
* Generates the plant positions for all registered plant types.
77
void generatePlantPositions();
81
* Regenerates the coverage map which can be used for quick lookup for plant probability.
83
void generateCoverageMap();
89
const PlantStoreMap& getPlants() const;
92
* Place the plants for the supplied area in the supplied store.
93
* @param layer The layer which we should use as base for determining what plants to get.
94
* @param plantType The plant type.
95
* @param area The enclosing area.
96
* @param store The store in which to place the plants.
98
void getPlantsForArea(const TerrainLayerDefinition& layerDef, unsigned char threshold, const std::string& plantType, Ogre::TRect<float> area, PlantStore& store);
100
TerrainPage& getTerrainPage() const;
102
unsigned int getCoverageMapPixelWidth() const;
106
The positions of the plants. These are precalulcated and not changed.
108
PlantStoreMap mPlantStores;
110
TerrainGenerator& mGenerator;
111
TerrainPage& mTerrainPage;
113
*we need to create a new lookup image for where grass should be placed. This should be based on the core grass coverage image, but with all layers that are above it substracted. Thus grass won't show up on roads and fields.
114
Note that this currently is disabled since it's faster to do the lookups through Mercator instead.
116
Ogre::MemoryDataStream* mFoliageCoverageDataStream;
117
Ogre::DataStreamPtr mFoliageCoverageDataStreamPtr;
119
unsigned int mCoverageMapPixelWidth;
129
PlantPopulator(TerrainPageFoliage& terrainPageFoliage);
130
virtual ~PlantPopulator();
132
virtual void populate(TerrainPageFoliage::PlantBatchStore& plantBatchStore, int plantIndex, unsigned int batchSize) = 0;
136
TerrainPageFoliage& mTerrainPageFoliage;
140
class ClusterPopulator : public PlantPopulator
143
ClusterPopulator(TerrainPageFoliage& terrainPageFoliage);
144
virtual ~ClusterPopulator();
146
virtual void populate(TerrainPageFoliage::PlantBatchStore& plantBatchStore, int plantIndex, unsigned int batchSize);
148
void setMinClusterRadius ( float theValue );
149
float getMinClusterRadius() const;
151
void setMaxClusterRadius ( float theValue );
152
float getMaxClusterRadius() const;
154
void setDensity ( float theValue );
155
float getDensity() const;
157
void setFalloff ( float theValue );
158
float getFalloff() const;
160
void setClusterDistance ( float theValue );
161
float getClusterDistance() const;
165
float mMinClusterRadius;
166
float mMaxClusterRadius;
167
float mClusterDistance;