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

« back to all changes in this revision

Viewing changes to src/components/ogre/SimpleRenderContext.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: SimpleRenderContext
 
3
//
 
4
// Description: 
 
5
//
 
6
//
 
7
// Author: Erik Hjortsberg <erik.hjortsberg@gmail.com>, (C) 2007
 
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 EMBEROGRESIMPLERENDERCONTEXT_H
 
24
#define EMBEROGRESIMPLERENDERCONTEXT_H
 
25
 
 
26
#include "EmberOgrePrerequisites.h"
 
27
 
 
28
namespace EmberOgre {
 
29
 
 
30
class SimpleRenderContext;
 
31
 
 
32
/**
 
33
Responsible for making sure that the texture is rerendered when the texture resource needs to be reloaded.
 
34
*/
 
35
class SimpleRenderContextResourceLoader : public Ogre::ManualResourceLoader
 
36
{
 
37
public:
 
38
        /**
 
39
         *    Ctor.
 
40
         * @param renderContext The SimpleRenderContext to which this instance belongs.
 
41
         */
 
42
        SimpleRenderContextResourceLoader(SimpleRenderContext& renderContext);
 
43
        
 
44
        
 
45
        /**
 
46
         *    At load time the texture will be rerendered.
 
47
         * @param resource 
 
48
         */
 
49
        virtual void loadResource (Ogre::Resource *resource);
 
50
protected:
 
51
        SimpleRenderContext& mRenderContext;
 
52
};
 
53
 
 
54
/**
 
55
        @author Erik Hjortsberg <erik.hjortsberg@gmail.com>
 
56
 
 
57
Useful class for rendering a single scene node.
 
58
 
 
59
*/
 
60
class SimpleRenderContext
 
61
{
 
62
public:
 
63
    
 
64
    /**
 
65
    Specifices how the camera will be positioned.
 
66
    */
 
67
    enum CameraPositioningMode
 
68
        {
 
69
                /**
 
70
                Centers the camera on the object.
 
71
                */
 
72
                CPM_OBJECTCENTER = 0,
 
73
                /**
 
74
                Centers the camera on the center of the world.
 
75
                */
 
76
                CPM_WORLDCENTER = 1,
 
77
                /**
 
78
                Allows free roaming.
 
79
                */
 
80
                CPM_FREE = 2,
 
81
        };
 
82
    
 
83
    /**
 
84
     * Constructor.
 
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.
 
88
     * @return 
 
89
     */
 
90
    SimpleRenderContext(const std::string& prefix, int width, int height);
 
91
    SimpleRenderContext(const std::string& prefix, Ogre::TexturePtr texturePtr);
 
92
 
 
93
    ~SimpleRenderContext();
 
94
    
 
95
    /**
 
96
     * Gets the scene node which is being rendered.
 
97
     * @return 
 
98
     */
 
99
    Ogre::SceneNode* getSceneNode() const;
 
100
    
 
101
    
 
102
    /**
 
103
     * Gets the camera used for rendering.
 
104
     * @return 
 
105
     */
 
106
    Ogre::Camera* getCamera() const;
 
107
    
 
108
    /**
 
109
     * Gets the default distance of the camera from the base, most likely somewhere where the whole scene is shown
 
110
     * @return 
 
111
     */
 
112
    Ogre::Real getDefaultCameraDistance() const;
 
113
    
 
114
    /**
 
115
     * Sets whether the rendering should be active or not.
 
116
     * @param active 
 
117
     */
 
118
    void setActive(bool active);
 
119
    
 
120
    /**
 
121
     * Adjusts the camera distance so that the full scene is shown
 
122
     */
 
123
    void showFull(const Ogre::MovableObject* object);
 
124
    
 
125
    
 
126
        /**
 
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.
 
129
         */
 
130
        void repositionCamera();
 
131
        
 
132
        
 
133
        /**
 
134
         *    Pitches the camera.
 
135
         * @param degrees The amount of degrees to pitch.
 
136
         */
 
137
        void pitch(Ogre::Degree degrees);
 
138
        
 
139
        /**
 
140
         *    Yaws the camera.
 
141
         * @param degrees The amount of degree to yaw.
 
142
         */
 
143
        void yaw(Ogre::Degree degrees);
 
144
    
 
145
        /**
 
146
         *    Rolls the camera.
 
147
         * @param degrees The amount of degree to roll.
 
148
         */
 
149
    void roll(Ogre::Degree degrees);
 
150
 
 
151
    
 
152
        /**
 
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.
 
154
         * @param distance 
 
155
         */
 
156
        void setCameraDistance(Ogre::Real distance);
 
157
    
 
158
    
 
159
        /**
 
160
         *    Gets the relative distance. 1.0 being the most optimal distance for showing the complete mesh.
 
161
         * @return 
 
162
         */
 
163
        float getCameraDistance() const;
 
164
        
 
165
        /**
 
166
         *    Sets the absolute distance of the camera.
 
167
         * @param distance 
 
168
         */
 
169
//      void setCameraAbsoluteDistance(Ogre::Real distance);
 
170
        
 
171
        /**
 
172
         *    Gets the absolute distance in world units.
 
173
         * @return 
 
174
         */
 
175
        float getAbsoluteCameraDistance() const;
 
176
        
 
177
        /**
 
178
         *    Gets the rotation of the entity.
 
179
         * @return 
 
180
         */
 
181
        Ogre::Quaternion getEntityRotation();
 
182
        
 
183
        
 
184
        /**
 
185
         *    Resets the orientation of the camera.
 
186
         */
 
187
        void resetCameraOrientation();
 
188
    
 
189
    
 
190
    Ogre::SceneManager* getSceneManager() const;
 
191
    
 
192
    Ogre::RenderTexture* getRenderTexture();
 
193
    
 
194
    Ogre::TexturePtr getTexture();
 
195
    
 
196
    Ogre::SceneNode* getCameraRootNode() const;
 
197
    
 
198
    Ogre::Viewport* getViewport() const;
 
199
    
 
200
    /**
 
201
     * Gets the main light.
 
202
     * @return 
 
203
     */
 
204
    Ogre::Light* getLight();
 
205
    
 
206
    
 
207
    /**
 
208
     * Sets the background colour.
 
209
     * @param colour 
 
210
     */
 
211
    void setBackgroundColour(const Ogre::ColourValue& colour);
 
212
    /**
 
213
     * Sets the background colour.
 
214
     * @param red 
 
215
     * @param green 
 
216
     * @param blue 
 
217
     * @param  
 
218
     */
 
219
    void setBackgroundColour(float red, float green, float blue, float alpha);
 
220
    
 
221
    /**
 
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.
 
223
    */
 
224
    void setTexture(Ogre::TexturePtr texture);
 
225
    
 
226
        /**
 
227
         *    Gets the current camera positioning mode. The default is CPM_OBJECTCENTER which centers the camera on the current displayed object.
 
228
         * @return 
 
229
         */
 
230
        CameraPositioningMode getCameraPositionMode() const;
 
231
    
 
232
        /**
 
233
         *    Sets the camera positioning mode. This determines how the camera behaves.
 
234
         * @param mode 
 
235
         */
 
236
        void setCameraPositionMode(CameraPositioningMode mode);
 
237
        
 
238
private:
 
239
 
 
240
        /**
 
241
        Main light for the scene, places a bit to the right 
 
242
        */
 
243
        Ogre::Light* mMainLight;
 
244
 
 
245
        /**
 
246
        Since we don't want this to be shown in the "real" world, we'll use our own scene manager
 
247
        */
 
248
        Ogre::SceneManager* mSceneManager;
 
249
 
 
250
        /**
 
251
        The default distance of the camera from the base, most likely somewhere where the whole scene is shown
 
252
        */
 
253
        Ogre::Real mDefaultCameraDistance;
 
254
        
 
255
        /**
 
256
         *    Creates the image and sets up the rendering.
 
257
         * @param prefix 
 
258
         */
 
259
        void createImage(const std::string& prefix);
 
260
        
 
261
        /**
 
262
        Width and height of the image.
 
263
        */
 
264
        int mWidth, mHeight;
 
265
        
 
266
        /**
 
267
        The rendertexture used.
 
268
        */
 
269
        Ogre::RenderTexture* mRenderTexture;
 
270
        
 
271
        /**
 
272
         *    Creates the ogre camera.
 
273
         * @param imageSetName 
 
274
         */
 
275
        void createCamera(const std::string& prefix);
 
276
        
 
277
        void setupScene(const std::string& prefix);
 
278
        
 
279
        /**
 
280
        The node to which the camera is attached.
 
281
        */
 
282
        Ogre::SceneNode *mCameraNode, *mCameraPitchNode;
 
283
        
 
284
        /**
 
285
        The node to which the rendered entities are attched.
 
286
        */
 
287
        Ogre::SceneNode* mEntityNode;
 
288
        
 
289
        /**
 
290
        The root node.
 
291
        */
 
292
        Ogre::SceneNode* mRootNode;
 
293
        
 
294
        /**
 
295
        The camera used.
 
296
        */
 
297
        Ogre::Camera* mCamera;
 
298
        
 
299
        Ogre::TexturePtr mTexture;
 
300
        
 
301
        Ogre::Viewport* mViewPort;
 
302
        
 
303
        SimpleRenderContextResourceLoader mResourceLoader;
 
304
        
 
305
        /**
 
306
        The background colour of the scene.
 
307
        */
 
308
        Ogre::ColourValue mBackgroundColour;
 
309
        
 
310
        /**
 
311
        The current camera positioning mode.
 
312
        */
 
313
        CameraPositioningMode mCameraPositionMode;
 
314
 
 
315
};
 
316
 
 
317
inline Ogre::Real SimpleRenderContext::getDefaultCameraDistance() const 
 
318
{
 
319
        return mDefaultCameraDistance;
 
320
}
 
321
 
 
322
inline Ogre::SceneManager* SimpleRenderContext::getSceneManager() const
 
323
{
 
324
        return mSceneManager;
 
325
}
 
326
 
 
327
}
 
328
 
 
329
#endif