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_TERRAINMAP_H
24
#define EMBEROGRE_TERRAINMAP_H
35
@brief Provides lightning for the map rendering.
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.
39
You don't use this directly when you want to render however, instead you use an instance of MapCameraLightningInstance.
41
@author Erik Hjortsberg <erik.hjortsberg@gmail.com>
43
class MapCameraLightning
48
* The light will automatically be created in the constructor.
49
* @param sceneManager The scene manager which is used for rendering.
51
MapCameraLightning(Ogre::SceneManager& sceneManager);
56
virtual ~MapCameraLightning();
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.
62
Ogre::Light* getLight();
65
* @brief Gets the scene manager.
66
* @return The scene manager.
68
Ogre::SceneManager& getSceneManager();
72
* @brief The light, owned by this instance.
77
* @brief The scene manager to which everything belongs.
79
Ogre::SceneManager& mSceneManager;
83
@brief An instance of map specific lightning, using RAII to make sure that the lightning is correctly reset after rendering is complete.
85
Use an instance of this during your rendering to make sure that the lightning is correctly set up, and then reset afterwards.
87
@author Erik Hjortsberg <erik.hjortsberg@gmail.com>
88
*/class MapCameraLightningInstance {
92
* @param lightning The lightning.
94
MapCameraLightningInstance(MapCameraLightning& lightning);
99
~MapCameraLightningInstance();
102
typedef std::vector<Ogre::MovableObject*> LightStore;
105
* @brief The lightning.
107
MapCameraLightning& mLightning;
110
* @brief A store of visible lights which will be disabled when this instance is created, and enabled when it's destroyed.
112
LightStore mVisibleLights;
115
* @brief The ambient colour of the scene before this instance is created, which will be reset when it's destroyed.
117
Ogre::ColourValue mAmbientColour;
121
@brief Responsible for handling the camera used to render the terrain overhead map.
122
@author Erik Hjortsberg <erik.hjortsberg@gmail.com>
128
MapCamera(Map& map, Ogre::SceneManager* manager);
129
virtual ~MapCamera();
133
void setDistance(float distance);
134
float getDistance() const;
136
void reposition(const Ogre::Vector2& pos);
138
* @brief Gets the current 2d position of the camera, in world space.
139
* @return The current position of the camera, in world space.
141
const Ogre::Vector2 getPosition() const;
144
void setRenderTarget(Ogre::RenderTarget* renderTarget);
149
Ogre::Camera* mCamera;
150
Ogre::Viewport* mViewport;
153
MapCameraLightning mLightning;
158
@brief Represents a sub view of the map.
159
@author Erik Hjortsberg <erik.hjortsberg@gmail.com>
165
MapView(Map& map, MapCamera& mapCamera);
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.
173
bool reposition(const Ogre::Vector2& pos);
175
const Ogre::TRect<float>& getRelativeViewBounds() const;
176
const Ogre::Vector2& getRelativeViewPosition() const;
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.
182
void recalculateBounds();
187
Ogre::TRect<int> mFullBounds;
188
Ogre::TRect<float> mVisibleRelativeBounds;
189
Ogre::Vector2 mRelativeViewPosition;
192
MapCamera& mMapCamera;
199
An overhead map of the terrain, rendered into a texture.
200
@author Erik Hjortsberg <erik.hjortsberg@gmail.com>
210
Ogre::TexturePtr getTexture() const;
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.
218
Ogre::RenderTexture* getRenderTexture() const;
221
void reposition(const Ogre::Vector2& pos);
222
void reposition(float x, float y);
224
void setDistance(float distance);
225
float getDistance() const;
228
* @brief Gets the resolution in meters per pixel.
229
* @return The resolution in meters per pixel.
231
float getResolution() const;
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.
238
void setResolution(float metersPerPixel);
241
* @brief Gets the resolution in meters of the map.
242
* @return The size of one side of the map in meters.
244
float getResolutionMeters() const;
252
void createTexture();
255
Ogre::TexturePtr mTexture;
256
Ogre::RenderTexture* mRenderTexture;
258
unsigned int mTexturePixelSize;
259
float mMetersPerPixel;
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>
272
class RenderingInstance
275
RenderingInstance(Ogre::SceneManager* manager);
276
virtual ~RenderingInstance();
279
Ogre::SceneManager* mManager;
281
Ogre::FogMode mFogMode;
282
Ogre::ColourValue mFogColour;
283
Ogre::Real mFogDensity;
284
Ogre::Real mFogStart;
287
Ogre::SceneManager::SpecialCaseRenderQueueMode mSpecialCaseRenderQueueMode;