Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/OgreMain/include/OgreControllerManager.h @ 3

Last change on this file since 3 was 3, checked in by anonymous, 17 years ago

=update

File size: 13.0 KB
Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4    (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2006 Torus Knot Software Ltd
8Also see acknowledgements in Readme.html
9
10This program is free software; you can redistribute it and/or modify it under
11the terms of the GNU Lesser General Public License as published by the Free Software
12Foundation; either version 2 of the License, or (at your option) any later
13version.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public License along with
20this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22http://www.gnu.org/copyleft/lesser.txt.
23
24You may alternatively use this source under the terms of a specific version of
25the OGRE Unrestricted License provided you have obtained such a license from
26Torus Knot Software Ltd.
27-----------------------------------------------------------------------------
28*/
29#ifndef __ControllerManager_H__
30#define __ControllerManager_H__
31
32#include "OgrePrerequisites.h"
33
34#include "OgreCommon.h"
35#include "OgreSingleton.h"
36#include "OgreController.h"
37#include "OgrePredefinedControllers.h"
38#include "OgreTextureUnitState.h"
39#include "OgreSharedPtr.h"
40
41namespace Ogre {
42
43    typedef SharedPtr< ControllerValue<Real> > ControllerValueRealPtr;
44    typedef SharedPtr< ControllerFunction<Real> > ControllerFunctionRealPtr;
45
46    /** Class for managing Controller instances.
47        @remarks
48            This class is responsible to keeping tabs on all the Controller instances registered
49            and updating them when requested. It also provides a number of convenience methods
50            for creating commonly used controllers (such as texture animators).
51    */
52    class _OgreExport ControllerManager : public Singleton<ControllerManager>
53    {
54    protected:
55        typedef std::set<Controller<Real>*> ControllerList;
56        ControllerList mControllers;
57
58        /// Global predefined controller
59        ControllerValueRealPtr mFrameTimeController;
60       
61                /// Global predefined controller
62                ControllerFunctionRealPtr mPassthroughFunction;
63
64                // Last frame number updated
65        unsigned long mLastFrameNumber;
66
67    public:
68        ControllerManager();
69        ~ControllerManager();
70
71        /** Creates a new controller and registers it with the manager.
72        */
73        Controller<Real>* createController(const ControllerValueRealPtr& src,
74            const ControllerValueRealPtr& dest, const ControllerFunctionRealPtr& func);
75
76        /** Creates a new controller use frame time source and passthrough controller function.
77        */
78        Controller<Real>* createFrameTimePassthroughController(
79            const ControllerValueRealPtr& dest);
80
81        /** Destroys all the controllers in existence.
82        */
83        void clearControllers(void);
84
85        /** Updates all the registered controllers.
86        */
87        void updateAllControllers(void);
88
89
90        /** Returns a ControllerValue which provides the time since the last frame as a control value source.
91            @remarks
92                A common source value to use to feed into a controller is the time since the last frame. This method
93                returns a pointer to a common source value which provides this information.
94            @par
95                Remember the value will only be up to date after the RenderSystem::beginFrame method is called.
96            @see
97                RenderSystem::beginFrame
98        */
99        const ControllerValueRealPtr& getFrameTimeSource(void) const;
100
101                /** Retrieve a simple passthrough controller function. */
102                const ControllerFunctionRealPtr& getPassthroughControllerFunction(void) const;
103
104        /** Creates a texture layer animator controller.
105            @remarks
106                This helper method creates the Controller, ControllerValue and ControllerFunction classes required
107                to animate a texture.
108            @param
109                layer TextureUnitState object to animate
110            @param
111                sequenceTime The amount of time in seconds it will take to loop through all the frames.
112        */
113        Controller<Real>* createTextureAnimator(TextureUnitState* layer, Real sequenceTime);
114
115                /** Creates a basic time-based texture uv coordinate modifier designed for creating scrolling textures.
116            @remarks
117                This simple method allows you to easily create constant-speed uv scrolling textures. If you want to
118                                specify different speed values for horizontal and vertical scroll, use the specific methods
119                                ControllerManager::createTextureUScroller and ControllerManager::createTextureVScroller.
120                                If you want more control, look up the ControllerManager::createTextureWaveTransformer
121                                for more complex wave-based scrollers / stretchers / rotaters.
122            @param
123                layer The texture layer to animate.
124            @param
125                speed Speed of horizontal (u-coord) and vertical (v-coord) scroll, in complete wraps per second
126        */
127        Controller<Real>* createTextureUVScroller(TextureUnitState* layer, Real speed);
128
129        /** Creates a basic time-based texture u coordinate modifier designed for creating scrolling textures.
130            @remarks
131                This simple method allows you to easily create constant-speed u scrolling textures. If you want more
132                control, look up the ControllerManager::createTextureWaveTransformer for more complex wave-based
133                scrollers / stretchers / rotaters.
134            @param
135                layer The texture layer to animate.
136            @param
137                uSpeed Speed of horizontal (u-coord) scroll, in complete wraps per second
138        */
139        Controller<Real>* createTextureUScroller(TextureUnitState* layer, Real uSpeed);
140
141                /** Creates a basic time-based texture v coordinate modifier designed for creating scrolling textures.
142            @remarks
143                This simple method allows you to easily create constant-speed v scrolling textures. If you want more
144                control, look up the ControllerManager::createTextureWaveTransformer for more complex wave-based
145                scrollers / stretchers / rotaters.
146            @param
147                layer The texture layer to animate.           
148            @param
149                vSpeed Speed of vertical (v-coord) scroll, in complete wraps per second
150        */
151        Controller<Real>* createTextureVScroller(TextureUnitState* layer, Real vSpeed);
152
153        /** Creates a basic time-based texture coordinate modifier designed for creating rotating textures.
154            @return
155                This simple method allows you to easily create constant-speed rotating textures. If you want more
156                control, look up the ControllerManager::createTextureWaveTransformer for more complex wave-based
157                scrollers / stretchers / rotaters.
158            @param
159                layer The texture layer to rotate.
160            @param
161                vSpeed Speed of rotation, in complete anticlockwise revolutions per second
162        */
163        Controller<Real>* createTextureRotater(TextureUnitState* layer, Real speed);
164
165        /** Creates a very flexible time-based texture transformation which can alter the scale, position or
166            rotation of a texture based on a wave function.
167            @param
168                layer The texture layer to affect
169            @param
170                ttype The type of transform, either translate (scroll), scale (stretch) or rotate (spin)
171            @param
172                waveType The shape of the wave, see WaveformType enum for details
173            @param
174                base The base value of the output
175            @param
176                frequency The speed of the wave in cycles per second
177            @param
178                phase The offset of the start of the wave, e.g. 0.5 to start half-way through the wave
179            @param
180                amplitude Scales the output so that instead of lying within 0..1 it lies within 0..1*amplitude for exaggerated effects
181        */
182        Controller<Real>* createTextureWaveTransformer(TextureUnitState* layer, TextureUnitState::TextureTransformType ttype,
183            WaveformType waveType, Real base = 0, Real frequency = 1, Real phase = 0, Real amplitude = 1);
184
185        /** Creates a controller for passing a frame time value through to a vertex / fragment program parameter.
186        @remarks
187            The destination parameter is expected to be a float, and the '.x' attribute will be populated
188            with the appropriately scaled time value.
189        @param params The parameters to update
190        @param paramIndex The index of the parameter to update; if you want a named parameter, then
191            retrieve the index beforehand using GpuProgramParameters::getParamIndex
192        @param factor The factor by which to adjust the time elapsed by before passing it to the program
193        */
194        Controller<Real>* createGpuProgramTimerParam(GpuProgramParameters* params, size_t paramIndex,
195            Real timeFactor = 1.0f);
196
197        /** Removes & destroys the controller passed in as a pointer.
198        */
199        void destroyController(Controller<Real>* controller);
200
201                /** Return relative speed of time as perceived by time based controllers.
202        @remarks
203            See setTimeFactor for full information on the meaning of this value.
204                */
205                Real getTimeFactor(void) const;
206
207                /** Set the relative speed to update frame time based controllers.
208        @remarks
209            Normally any controllers which use time as an input (FrameTimeController) are updated
210            automatically in line with the real passage of time. This method allows you to change
211            that, so that controllers are told that the time is passing slower or faster than it
212            actually is. Use this to globally speed up / slow down the effect of time-based controllers.
213        @param tf The virtual speed of time (1.0 is real time).
214                */
215                void setTimeFactor(Real tf);
216
217                /** Gets the constant that is added to time lapsed between each frame.
218                @remarks
219                        See setFrameDelay for full information on the meaning of this value.
220                */
221                Real getFrameDelay(void) const;
222
223                /** Sets a constant frame rate.
224                @remarks
225                        This function is useful when rendering a sequence to
226                        files that should create a film clip with constant frame
227                        rate.
228                        It will ensure that scrolling textures and animations
229                        move at a constant frame rate.
230                @param fd The delay in seconds wanted between each frame
231                        (1.0f / 25.0f means a seconds worth of animation is done
232                        in 25 frames).
233                */
234                void setFrameDelay(Real fd);
235
236                /** Return the elapsed time.
237        @remarks
238            See setElapsedTime for full information on the meaning of this value.
239        */
240        Real getElapsedTime(void) const;
241
242        /** Set the elapsed time.
243        @remarks
244            Normally elapsed time accumulated all frames time (which speed relative to time
245            factor) since the rendering loop started. This method allows your to change that to
246            special time, so some elapsed-time-based globally effect is repeatable.
247        @param elapsedTime The new elapsed time
248        */
249        void setElapsedTime(Real elapsedTime);
250
251        /** Override standard Singleton retrieval.
252        @remarks
253        Why do we do this? Well, it's because the Singleton
254        implementation is in a .h file, which means it gets compiled
255        into anybody who includes it. This is needed for the
256        Singleton template to work, but we actually only want it
257        compiled into the implementation of the class based on the
258        Singleton, not all of them. If we don't change this, we get
259        link errors when trying to use the Singleton-based class from
260        an outside dll.
261        @par
262        This method just delegates to the template version anyway,
263        but the implementation stays in this single compilation unit,
264        preventing link errors.
265        */
266        static ControllerManager& getSingleton(void);
267        /** Override standard Singleton retrieval.
268        @remarks
269        Why do we do this? Well, it's because the Singleton
270        implementation is in a .h file, which means it gets compiled
271        into anybody who includes it. This is needed for the
272        Singleton template to work, but we actually only want it
273        compiled into the implementation of the class based on the
274        Singleton, not all of them. If we don't change this, we get
275        link errors when trying to use the Singleton-based class from
276        an outside dll.
277        @par
278        This method just delegates to the template version anyway,
279        but the implementation stays in this single compilation unit,
280        preventing link errors.
281        */
282        static ControllerManager* getSingletonPtr(void);
283    };
284
285
286}
287#endif
Note: See TracBrowser for help on using the repository browser.