2
// C++ Interface: SimpleRenderContext
7
// Author: Erik Hjortsberg <erik.hjortsberg@gmail.com>, (C) 2007
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 EMBEROGRESIMPLERENDERCONTEXT_H
24
#define EMBEROGRESIMPLERENDERCONTEXT_H
26
#include "EmberOgrePrerequisites.h"
30
class SimpleRenderContext;
33
Responsible for making sure that the texture is rerendered when the texture resource needs to be reloaded.
35
class SimpleRenderContextResourceLoader : public Ogre::ManualResourceLoader
40
* @param renderContext The SimpleRenderContext to which this instance belongs.
42
SimpleRenderContextResourceLoader(SimpleRenderContext& renderContext);
46
* At load time the texture will be rerendered.
49
virtual void loadResource (Ogre::Resource *resource);
51
SimpleRenderContext& mRenderContext;
55
@author Erik Hjortsberg <erik.hjortsberg@gmail.com>
57
Useful class for rendering a single scene node.
60
class SimpleRenderContext
65
Specifices how the camera will be positioned.
67
enum CameraPositioningMode
70
Centers the camera on the object.
74
Centers the camera on the center of the world.
85
* @param prefix A unique prefix for the scene manager.
86
* @param width The width of the image created.
87
* @param height The height of the image created.
90
SimpleRenderContext(const std::string& prefix, int width, int height);
91
SimpleRenderContext(const std::string& prefix, Ogre::TexturePtr texturePtr);
93
~SimpleRenderContext();
96
* Gets the scene node which is being rendered.
99
Ogre::SceneNode* getSceneNode() const;
103
* Gets the camera used for rendering.
106
Ogre::Camera* getCamera() const;
109
* Gets the default distance of the camera from the base, most likely somewhere where the whole scene is shown
112
Ogre::Real getDefaultCameraDistance() const;
115
* Sets whether the rendering should be active or not.
118
void setActive(bool active);
121
* Adjusts the camera distance so that the full scene is shown
123
void showFull(const Ogre::MovableObject* object);
127
* After you've changed the target of the camera, i.e. the object attached to the base SceneNode,
128
the camera has to be repositioned. Make sure to always call this method after updating the scene.
130
void repositionCamera();
134
* Pitches the camera.
135
* @param degrees The amount of degrees to pitch.
137
void pitch(Ogre::Degree degrees);
141
* @param degrees The amount of degree to yaw.
143
void yaw(Ogre::Degree degrees);
147
* @param degrees The amount of degree to roll.
149
void roll(Ogre::Degree degrees);
153
* Sets the relative camera distance. Note that this is adjusted after calling repositionCamera(). A value of 1.0 indicates the most optimal distance for showing the complete mesh.
156
void setCameraDistance(Ogre::Real distance);
160
* Gets the relative distance. 1.0 being the most optimal distance for showing the complete mesh.
163
float getCameraDistance() const;
166
* Sets the absolute distance of the camera.
169
// void setCameraAbsoluteDistance(Ogre::Real distance);
172
* Gets the absolute distance in world units.
175
float getAbsoluteCameraDistance() const;
178
* Gets the rotation of the entity.
181
Ogre::Quaternion getEntityRotation();
185
* Resets the orientation of the camera.
187
void resetCameraOrientation();
190
Ogre::SceneManager* getSceneManager() const;
192
Ogre::RenderTexture* getRenderTexture();
194
Ogre::TexturePtr getTexture();
196
Ogre::SceneNode* getCameraRootNode() const;
198
Ogre::Viewport* getViewport() const;
201
* Gets the main light.
204
Ogre::Light* getLight();
208
* Sets the background colour.
211
void setBackgroundColour(const Ogre::ColourValue& colour);
213
* Sets the background colour.
219
void setBackgroundColour(float red, float green, float blue, float alpha);
222
Sets the render texture to which the scene will be rendered. By default an instance of this class will create it's own Render Texture instance, but this allows you to use a preexisting one if you want.
224
void setTexture(Ogre::TexturePtr texture);
227
* Gets the current camera positioning mode. The default is CPM_OBJECTCENTER which centers the camera on the current displayed object.
230
CameraPositioningMode getCameraPositionMode() const;
233
* Sets the camera positioning mode. This determines how the camera behaves.
236
void setCameraPositionMode(CameraPositioningMode mode);
241
Main light for the scene, places a bit to the right
243
Ogre::Light* mMainLight;
246
Since we don't want this to be shown in the "real" world, we'll use our own scene manager
248
Ogre::SceneManager* mSceneManager;
251
The default distance of the camera from the base, most likely somewhere where the whole scene is shown
253
Ogre::Real mDefaultCameraDistance;
256
* Creates the image and sets up the rendering.
259
void createImage(const std::string& prefix);
262
Width and height of the image.
267
The rendertexture used.
269
Ogre::RenderTexture* mRenderTexture;
272
* Creates the ogre camera.
273
* @param imageSetName
275
void createCamera(const std::string& prefix);
277
void setupScene(const std::string& prefix);
280
The node to which the camera is attached.
282
Ogre::SceneNode *mCameraNode, *mCameraPitchNode;
285
The node to which the rendered entities are attched.
287
Ogre::SceneNode* mEntityNode;
292
Ogre::SceneNode* mRootNode;
297
Ogre::Camera* mCamera;
299
Ogre::TexturePtr mTexture;
301
Ogre::Viewport* mViewPort;
303
SimpleRenderContextResourceLoader mResourceLoader;
306
The background colour of the scene.
308
Ogre::ColourValue mBackgroundColour;
311
The current camera positioning mode.
313
CameraPositioningMode mCameraPositionMode;
317
inline Ogre::Real SimpleRenderContext::getDefaultCameraDistance() const
319
return mDefaultCameraDistance;
322
inline Ogre::SceneManager* SimpleRenderContext::getSceneManager() const
324
return mSceneManager;