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

« back to all changes in this revision

Viewing changes to src/components/ogre/terrain/Map.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: Map
 
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_TERRAINMAP_H
 
24
#define EMBEROGRE_TERRAINMAP_H
 
25
 
 
26
#include <Ogre.h>
 
27
 
 
28
namespace EmberOgre {
 
29
 
 
30
namespace Terrain {
 
31
 
 
32
class Map;
 
33
 
 
34
/**
 
35
@brief Provides lightning for the map rendering.
 
36
 
 
37
We don't want to use the regular scene lightning since then we won't see anything at all during the night. This class takes care of setting up a light which will provide a good sunny day for the map rendering.
 
38
 
 
39
You don't use this directly when you want to render however, instead you use an instance of MapCameraLightningInstance.
 
40
 
 
41
@author Erik Hjortsberg <erik.hjortsberg@gmail.com>
 
42
*/
 
43
class MapCameraLightning
 
44
{
 
45
public:
 
46
        /**
 
47
         * @brief Ctor.
 
48
         * The light will automatically be created in the constructor.
 
49
         * @param sceneManager The scene manager which is used for rendering.
 
50
         */
 
51
        MapCameraLightning(Ogre::SceneManager& sceneManager);
 
52
        
 
53
        /**
 
54
         * @brief Dtor.
 
55
         */
 
56
        virtual ~MapCameraLightning();
 
57
        
 
58
        /**
 
59
         * @brief Gets the light which is used for rendering. This is a yellow, bright light in the middle of the sky.
 
60
         * @return The main light.
 
61
         */
 
62
        Ogre::Light* getLight();
 
63
        
 
64
        /**
 
65
         * @brief Gets the scene manager.
 
66
         * @return The scene manager.
 
67
         */
 
68
        Ogre::SceneManager& getSceneManager();
 
69
        
 
70
protected:
 
71
        /**
 
72
         * @brief The light, owned by this instance.
 
73
         */
 
74
        Ogre::Light* mLight;
 
75
        
 
76
        /**
 
77
         * @brief The scene manager to which everything belongs.
 
78
         */
 
79
        Ogre::SceneManager& mSceneManager;
 
80
};
 
81
 
 
82
/**
 
83
@brief An instance of map specific lightning, using RAII to make sure that the lightning is correctly reset after rendering is complete.
 
84
 
 
85
Use an instance of this during your rendering to make sure that the lightning is correctly set up, and then reset afterwards.
 
86
 
 
87
@author Erik Hjortsberg <erik.hjortsberg@gmail.com>
 
88
*/class MapCameraLightningInstance {
 
89
public:
 
90
        /**
 
91
         * @brief Ctor.
 
92
         * @param lightning The lightning.
 
93
         */
 
94
        MapCameraLightningInstance(MapCameraLightning& lightning);
 
95
        
 
96
        /**
 
97
         * @brief Dtor.
 
98
         */
 
99
        ~MapCameraLightningInstance();
 
100
        
 
101
protected:
 
102
        typedef std::vector<Ogre::MovableObject*> LightStore;
 
103
        
 
104
        /**
 
105
         * @brief The lightning.
 
106
         */
 
107
        MapCameraLightning& mLightning;
 
108
        
 
109
        /**
 
110
         * @brief A store of visible lights which will be disabled when this instance is created, and enabled when it's destroyed.
 
111
         */
 
112
        LightStore mVisibleLights;
 
113
        
 
114
        /**
 
115
         * @brief The ambient colour of the scene before this instance is created, which will be reset when it's destroyed.
 
116
         */
 
117
        Ogre::ColourValue mAmbientColour;
 
118
};
 
119
 
 
120
/**
 
121
        @brief Responsible for handling the camera used to render the terrain overhead map.
 
122
        @author Erik Hjortsberg <erik.hjortsberg@gmail.com>
 
123
 
 
124
*/
 
125
class MapCamera
 
126
{
 
127
public:
 
128
        MapCamera(Map& map, Ogre::SceneManager* manager);
 
129
        virtual ~MapCamera();
 
130
        
 
131
        void render();
 
132
        
 
133
        void setDistance(float distance);
 
134
        float getDistance() const;
 
135
        
 
136
        void reposition(const Ogre::Vector2& pos);
 
137
        /**
 
138
         * @brief Gets the current 2d position of the camera, in world space.
 
139
         * @return The current position of the camera, in world space.
 
140
         */
 
141
        const Ogre::Vector2 getPosition() const;
 
142
 
 
143
        
 
144
        void setRenderTarget(Ogre::RenderTarget* renderTarget);
 
145
        
 
146
protected:
 
147
        Map& mMap;
 
148
        
 
149
        Ogre::Camera* mCamera;
 
150
        Ogre::Viewport* mViewport;
 
151
        float mDistance;
 
152
        
 
153
        MapCameraLightning mLightning;
 
154
};
 
155
 
 
156
 
 
157
/**
 
158
        @brief Represents a sub view of the map.
 
159
        @author Erik Hjortsberg <erik.hjortsberg@gmail.com>
 
160
 
 
161
*/
 
162
class MapView
 
163
{
 
164
public:
 
165
        MapView(Map& map, MapCamera& mapCamera);
 
166
        
 
167
        /**
 
168
         * @brief Reposition the view.
 
169
         * If the view after the reposition will be outside of the current rendered map, the map will be repositioned and rendered. This happens automatically.
 
170
         * @param pos The world position in ogre space to where we want to reposition the view.
 
171
         * @return True if the map needed to be repositioned and rerendered.
 
172
         */
 
173
        bool reposition(const Ogre::Vector2& pos);
 
174
        
 
175
        const Ogre::TRect<float>& getRelativeViewBounds() const;
 
176
        const Ogre::Vector2& getRelativeViewPosition() const;
 
177
        
 
178
        /**
 
179
         * @brief Recalculates the bounds. Call this whenever you've altered the scaling or repositioned the camera.
 
180
         * This will also be called internally whenever the camera needs to be repositioned through a call to MapView::reposition.
 
181
         */
 
182
        void recalculateBounds();
 
183
 
 
184
protected:
 
185
 
 
186
        
 
187
        Ogre::TRect<int> mFullBounds;
 
188
        Ogre::TRect<float> mVisibleRelativeBounds;
 
189
        Ogre::Vector2 mRelativeViewPosition;
 
190
        
 
191
        Map& mMap;
 
192
        MapCamera& mMapCamera;
 
193
        
 
194
        float mViewSize;
 
195
 
 
196
};
 
197
 
 
198
/**
 
199
        An overhead map of the terrain, rendered into a texture.
 
200
        @author Erik Hjortsberg <erik.hjortsberg@gmail.com>
 
201
*/
 
202
class Map{
 
203
public:
 
204
    Map();
 
205
 
 
206
    virtual ~Map();
 
207
    
 
208
    void initialize();
 
209
    
 
210
    Ogre::TexturePtr getTexture() const;
 
211
    
 
212
    /**
 
213
     * @brief Gets the render texture into which the map is being rendered.
 
214
     * This is the same texture as the one you will get from getTexture(), but this accesses the more low level rendering structure, allowing you to access the actual ViewPort.
 
215
     * If you haven't called initialize() yet this will return a null pointer.
 
216
     * @return A pointer to the render texture being used for rendering the map, or null if no such has been created yet.
 
217
     */
 
218
    Ogre::RenderTexture* getRenderTexture() const;
 
219
    
 
220
    void render();
 
221
    void reposition(const Ogre::Vector2& pos);
 
222
    void reposition(float x, float y);
 
223
    
 
224
        void setDistance(float distance);
 
225
        float getDistance() const;
 
226
        
 
227
        /**
 
228
         * @brief Gets the resolution in meters per pixel.
 
229
         * @return The resolution in meters per pixel.
 
230
         */
 
231
        float getResolution() const;
 
232
        
 
233
        /**
 
234
         * @brief Sets the resolution of the map.
 
235
         * The map will be rerendered after the resolution has been changed.
 
236
         * @param metersPerPixel The resolution of the map in pixels per meter.
 
237
         */
 
238
        void setResolution(float metersPerPixel);
 
239
        
 
240
        /**
 
241
         * @brief Gets the resolution in meters of the map.
 
242
         * @return The size of one side of the map in meters.
 
243
         */
 
244
        float getResolutionMeters() const;
 
245
        
 
246
        MapView& getView();
 
247
    
 
248
    
 
249
protected:
 
250
 
 
251
        void setupCamera();
 
252
        void createTexture();
 
253
 
 
254
        
 
255
        Ogre::TexturePtr mTexture;
 
256
        Ogre::RenderTexture* mRenderTexture;
 
257
        
 
258
        unsigned int mTexturePixelSize;
 
259
        float mMetersPerPixel;
 
260
        
 
261
        MapCamera mCamera;
 
262
        MapView mView;
 
263
        
 
264
};
 
265
 
 
266
 
 
267
 
 
268
/**
 
269
        By using an instance of this every time you want to alter the scene manager for a certain render operation, you can make sure that the scene manager is returned to its initial state after the render operation is complete, even if something goes wrong.
 
270
        @author Erik Hjortsberg <erik.hjortsberg@gmail.com>
 
271
*/
 
272
class RenderingInstance
 
273
{
 
274
public:
 
275
        RenderingInstance(Ogre::SceneManager* manager);
 
276
        virtual ~RenderingInstance();
 
277
 
 
278
protected:
 
279
        Ogre::SceneManager* mManager;
 
280
        
 
281
        Ogre::FogMode mFogMode;
 
282
        Ogre::ColourValue mFogColour;
 
283
        Ogre::Real mFogDensity;
 
284
        Ogre::Real mFogStart;
 
285
        Ogre::Real mFogEnd;
 
286
        
 
287
        Ogre::SceneManager::SpecialCaseRenderQueueMode mSpecialCaseRenderQueueMode;
 
288
        
 
289
};
 
290
 
 
291
 
 
292
}
 
293
 
 
294
}
 
295
 
 
296
#endif