~ubuntu-branches/debian/sid/ember/sid

« back to all changes in this revision

Viewing changes to src/components/ogre/terrain/TerrainPageFoliage.h

  • Committer: Bazaar Package Importer
  • Author(s): Michael Koch
  • Date: 2009-07-23 07:46:40 UTC
  • Revision ID: james.westby@ubuntu.com-20090723074640-wh0ukzis0kda36qv
Tags: upstream-0.5.6
ImportĀ upstreamĀ versionĀ 0.5.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// C++ Interface: TerrainPageFoliage
 
3
//
 
4
// Description: 
 
5
//
 
6
//
 
7
// Author: Erik Hjortsberg <erik.hjortsberg@gmail.com>, (C) 2008
 
8
//
 
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.
 
13
// 
 
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.
 
18
// 
 
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.//
 
22
//
 
23
#ifndef EMBEROGRE_TERRAINTERRAINPAGEFOLIAGE_H
 
24
#define EMBEROGRE_TERRAINTERRAINPAGEFOLIAGE_H
 
25
 
 
26
#include <vector>
 
27
#include <OgreCommon.h>
 
28
#include <OgreSharedPtr.h>
 
29
#include <OgreDataStream.h>
 
30
#include <OgreMemoryAllocatorConfig.h>
 
31
 
 
32
namespace Ogre
 
33
{
 
34
class MemoryDataStream;
 
35
class Vector2;
 
36
}
 
37
 
 
38
namespace EmberOgre {
 
39
 
 
40
namespace Terrain {
 
41
 
 
42
class TerrainShader;
 
43
class TerrainGenerator;
 
44
class TerrainPageSurface;
 
45
class TerrainPage;
 
46
class TerrainPageFoliage;
 
47
class TerrainLayerDefinition;
 
48
 
 
49
// struct PlantPosition
 
50
// {
 
51
//      Ogre::Vector2 pos;
 
52
//      unsigned char rotation;
 
53
//      float scale;
 
54
// };
 
55
 
 
56
/**
 
57
        @author Erik Hjortsberg <erik.hjortsberg@gmail.com>
 
58
*/
 
59
class TerrainPageFoliage
 
60
{
 
61
public:
 
62
        /** 
 
63
        A store of plant positions. We keep this in ogre space for performance reasons.
 
64
        */
 
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;
 
69
 
 
70
        TerrainPageFoliage(TerrainGenerator& generator, TerrainPage& page);
 
71
        virtual ~TerrainPageFoliage();
 
72
 
 
73
 
 
74
        /**
 
75
         *    Generates the plant positions for all registered plant types.
 
76
         */
 
77
        void generatePlantPositions();
 
78
        
 
79
        
 
80
        /**
 
81
         *    Regenerates the coverage map which can be used for quick lookup for plant probability.
 
82
         */
 
83
        void generateCoverageMap();
 
84
        
 
85
        /**
 
86
         *    Gets all plants.
 
87
         * @return 
 
88
         */
 
89
        const PlantStoreMap& getPlants() const;
 
90
        
 
91
        /**
 
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.
 
97
         */
 
98
        void getPlantsForArea(const TerrainLayerDefinition& layerDef, unsigned char threshold, const std::string& plantType, Ogre::TRect<float> area, PlantStore& store);
 
99
 
 
100
        TerrainPage& getTerrainPage() const;
 
101
 
 
102
        unsigned int getCoverageMapPixelWidth() const;
 
103
        
 
104
protected:
 
105
        /**
 
106
        The positions of the plants. These are precalulcated and not changed.
 
107
        */
 
108
        PlantStoreMap mPlantStores;
 
109
        
 
110
        TerrainGenerator& mGenerator;
 
111
        TerrainPage& mTerrainPage;
 
112
        /**
 
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.
 
115
        */
 
116
        Ogre::MemoryDataStream* mFoliageCoverageDataStream;
 
117
        Ogre::DataStreamPtr mFoliageCoverageDataStreamPtr;
 
118
        
 
119
        unsigned int mCoverageMapPixelWidth;
 
120
        
 
121
        void setupBatches();
 
122
        
 
123
};
 
124
 
 
125
class PlantPopulator
 
126
{
 
127
public:
 
128
 
 
129
        PlantPopulator(TerrainPageFoliage& terrainPageFoliage);
 
130
        virtual ~PlantPopulator();
 
131
        
 
132
        virtual void populate(TerrainPageFoliage::PlantBatchStore& plantBatchStore, int plantIndex, unsigned int batchSize) = 0;
 
133
 
 
134
protected:
 
135
 
 
136
        TerrainPageFoliage& mTerrainPageFoliage;
 
137
 
 
138
};
 
139
 
 
140
class ClusterPopulator : public PlantPopulator
 
141
{
 
142
public:
 
143
        ClusterPopulator(TerrainPageFoliage& terrainPageFoliage);
 
144
        virtual ~ClusterPopulator();
 
145
        
 
146
        virtual void populate(TerrainPageFoliage::PlantBatchStore& plantBatchStore, int plantIndex, unsigned int batchSize);
 
147
 
 
148
        void setMinClusterRadius ( float theValue );
 
149
        float getMinClusterRadius() const;
 
150
 
 
151
        void setMaxClusterRadius ( float theValue );
 
152
        float getMaxClusterRadius() const;
 
153
 
 
154
        void setDensity ( float theValue );
 
155
        float getDensity() const;
 
156
 
 
157
        void setFalloff ( float theValue );
 
158
        float getFalloff() const;
 
159
 
 
160
        void setClusterDistance ( float theValue );
 
161
        float getClusterDistance() const;
 
162
 
 
163
protected:
 
164
 
 
165
        float mMinClusterRadius;
 
166
        float mMaxClusterRadius;
 
167
        float mClusterDistance;
 
168
        float mDensity;
 
169
        float mFalloff;
 
170
 
 
171
};
 
172
 
 
173
}
 
174
 
 
175
}
 
176
 
 
177
#endif