Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/ogre_src_v1-9-0/OgreMain/include/OgreControllerManager.h @ 148

Last change on this file since 148 was 148, checked in by patricwi, 6 years ago

Added new dependencies for ogre1.9 and cegui0.8

File size: 13.4 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-2013 Torus Knot Software Ltd
8
9Permission is hereby granted, free of charge, to any person obtaining a copy
10of this software and associated documentation files (the "Software"), to deal
11in the Software without restriction, including without limitation the rights
12to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13copies of the Software, and to permit persons to whom the Software is
14furnished to do so, subject to the following conditions:
15
16The above copyright notice and this permission notice shall be included in
17all copies or substantial portions of the Software.
18
19THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25THE SOFTWARE.
26-----------------------------------------------------------------------------
27*/
28#ifndef __ControllerManager_H__
29#define __ControllerManager_H__
30
31#include "OgrePrerequisites.h"
32
33#include "OgreCommon.h"
34#include "OgreSingleton.h"
35#include "OgreController.h"
36#include "OgrePredefinedControllers.h"
37#include "OgreTextureUnitState.h"
38#include "OgreSharedPtr.h"
39#include "OgreHeaderPrefix.h"
40
41namespace Ogre {
42    /** \addtogroup Core
43    *  @{
44    */
45    /** \addtogroup General
46    *  @{
47    */
48
49    typedef SharedPtr< ControllerValue<Real> > ControllerValueRealPtr;
50    typedef SharedPtr< ControllerFunction<Real> > ControllerFunctionRealPtr;
51
52    /** Class for managing Controller instances.
53    @remarks
54        This class is responsible to keeping tabs on all the Controller instances registered
55        and updating them when requested. It also provides a number of convenience methods
56        for creating commonly used controllers (such as texture animators).
57    */
58    class _OgreExport ControllerManager : public Singleton<ControllerManager>, public ControllerAlloc
59    {
60    protected:
61        typedef set<Controller<Real>*>::type ControllerList;
62        ControllerList mControllers;
63
64        /// Global predefined controller
65        ControllerValueRealPtr mFrameTimeController;
66       
67        /// Global predefined controller
68        ControllerFunctionRealPtr mPassthroughFunction;
69
70        /// Last frame number updated
71        unsigned long mLastFrameNumber;
72
73    public:
74        ControllerManager();
75        ~ControllerManager();
76
77        /** Creates a new controller and registers it with the manager.
78        */
79        Controller<Real>* createController(const ControllerValueRealPtr& src,
80            const ControllerValueRealPtr& dest, const ControllerFunctionRealPtr& func);
81
82        /** Creates a new controller use frame time source and passthrough controller function.
83        */
84        Controller<Real>* createFrameTimePassthroughController(
85            const ControllerValueRealPtr& dest);
86
87        /** Destroys all the controllers in existence.
88        */
89        void clearControllers(void);
90
91        /** Updates all the registered controllers.
92        */
93        void updateAllControllers(void);
94
95
96        /** Returns a ControllerValue which provides the time since the last frame as a control value source.
97        @remarks
98            A common source value to use to feed into a controller is the time since the last frame. This method
99            returns a pointer to a common source value which provides this information.
100        @par
101            Remember the value will only be up to date after the RenderSystem::beginFrame method is called.
102        @see
103            RenderSystem::beginFrame
104        */
105        const ControllerValueRealPtr& getFrameTimeSource(void) const;
106
107        /** Retrieve a simple passthrough controller function. */
108        const ControllerFunctionRealPtr& getPassthroughControllerFunction(void) const;
109
110        /** Creates a texture layer animator controller.
111        @remarks
112            This helper method creates the Controller, ControllerValue and ControllerFunction classes required
113            to animate a texture.
114        @param layer
115            TextureUnitState object to animate
116        @param sequenceTime
117            The amount of time in seconds it will take to loop through all the frames.
118        */
119        Controller<Real>* createTextureAnimator(TextureUnitState* layer, Real sequenceTime);
120
121        /** Creates a basic time-based texture uv coordinate modifier designed for creating scrolling textures.
122        @remarks
123            This simple method allows you to easily create constant-speed uv scrolling textures. If you want to
124            specify different speed values for horizontal and vertical scroll, use the specific methods
125            ControllerManager::createTextureUScroller and ControllerManager::createTextureVScroller.
126            If you want more control, look up the ControllerManager::createTextureWaveTransformer
127            for more complex wave-based scrollers / stretchers / rotators.
128        @param layer
129            The texture layer to animate.
130        @param speed
131            Speed of horizontal (u-coord) and vertical (v-coord) scroll, in complete wraps per second.
132        */
133        Controller<Real>* createTextureUVScroller(TextureUnitState* layer, Real speed);
134
135        /** Creates a basic time-based texture u coordinate modifier designed for creating scrolling textures.
136        @remarks
137            This simple method allows you to easily create constant-speed u scrolling textures. If you want more
138            control, look up the ControllerManager::createTextureWaveTransformer for more complex wave-based
139            scrollers / stretchers / rotators.
140        @param layer
141            The texture layer to animate.
142        @param uSpeed
143            Speed of horizontal (u-coord) scroll, in complete wraps per second.
144        */
145        Controller<Real>* createTextureUScroller(TextureUnitState* layer, Real uSpeed);
146
147        /** Creates a basic time-based texture v coordinate modifier designed for creating scrolling textures.
148        @remarks
149            This simple method allows you to easily create constant-speed v scrolling textures. If you want more
150            control, look up the ControllerManager::createTextureWaveTransformer for more complex wave-based
151            scrollers / stretchers / rotators.
152        @param layer
153            The texture layer to animate.
154        @param vSpeed
155            Speed of vertical (v-coord) scroll, in complete wraps per second.
156        */
157        Controller<Real>* createTextureVScroller(TextureUnitState* layer, Real vSpeed);
158
159        /** Creates a basic time-based texture coordinate modifier designed for creating rotating textures.
160        @return
161            This simple method allows you to easily create constant-speed rotating textures. If you want more
162            control, look up the ControllerManager::createTextureWaveTransformer for more complex wave-based
163            scrollers / stretchers / rotators.
164        @param layer
165            The texture layer to rotate.
166        @param speed
167            Speed of rotation, in complete anticlockwise revolutions per second.
168        */
169        Controller<Real>* createTextureRotater(TextureUnitState* layer, Real speed);
170
171        /** Creates a very flexible time-based texture transformation which can alter the scale, position or
172            rotation of a texture based on a wave function.
173        @param layer
174            The texture layer to affect.
175        @param ttype
176            The type of transform, either translate (scroll), scale (stretch) or rotate (spin).
177        @param waveType
178            The shape of the wave, see WaveformType enum for details.
179        @param base
180            The base value of the output.
181        @param frequency
182            The speed of the wave in cycles per second.
183        @param phase
184            The offset of the start of the wave, e.g. 0.5 to start half-way through the wave.
185        @param amplitude
186            Scales the output so that instead of lying within 0..1 it lies within 0..1*amplitude for exaggerated effects.
187        */
188        Controller<Real>* createTextureWaveTransformer(TextureUnitState* layer, TextureUnitState::TextureTransformType ttype,
189            WaveformType waveType, Real base = 0, Real frequency = 1, Real phase = 0, Real amplitude = 1);
190
191        /** Creates a controller for passing a frame time value through to a vertex / fragment program parameter.
192        @remarks
193            The destination parameter is expected to be a float, and the '.x' attribute will be populated
194            with the appropriately scaled time value.
195        @param params
196            The parameters to update.
197        @param paramIndex
198            The index of the parameter to update; if you want a named parameter, then
199            retrieve the index beforehand using GpuProgramParameters::getParamIndex.
200        @param timeFactor
201            The factor by which to adjust the time elapsed by before passing it to the program.
202        */
203        Controller<Real>* createGpuProgramTimerParam(GpuProgramParametersSharedPtr params, size_t paramIndex,
204            Real timeFactor = 1.0f);
205
206        /** Removes & destroys the controller passed in as a pointer.
207        */
208        void destroyController(Controller<Real>* controller);
209
210        /** Return relative speed of time as perceived by time based controllers.
211        @remarks
212            See setTimeFactor for full information on the meaning of this value.
213        */
214        Real getTimeFactor(void) const;
215
216        /** Set the relative speed to update frame time based controllers.
217        @remarks
218            Normally any controllers which use time as an input (FrameTimeController) are updated
219            automatically in line with the real passage of time. This method allows you to change
220            that, so that controllers are told that the time is passing slower or faster than it
221            actually is. Use this to globally speed up / slow down the effect of time-based controllers.
222        @param tf
223            The virtual speed of time (1.0 is real time).
224        */
225        void setTimeFactor(Real tf);
226
227        /** Gets the constant that is added to time lapsed between each frame.
228        @remarks
229            See setFrameDelay for full information on the meaning of this value.
230        */
231        Real getFrameDelay(void) const;
232
233        /** Sets a constant frame rate.
234        @remarks
235            This function is useful when rendering a sequence to
236            files that should create a film clip with constant frame
237            rate.
238            It will ensure that scrolling textures and animations
239            move at a constant frame rate.
240        @param fd
241            The delay in seconds wanted between each frame
242            (1.0f / 25.0f means a seconds worth of animation is done
243            in 25 frames).
244        */
245        void setFrameDelay(Real fd);
246
247        /** Return the elapsed time.
248        @remarks
249            See setElapsedTime for full information on the meaning of this value.
250        */
251        Real getElapsedTime(void) const;
252
253        /** Set the elapsed time.
254        @remarks
255            Normally elapsed time accumulated all frames time (which speed relative to time
256            factor) since the rendering loop started. This method allows your to change that to
257            special time, so some elapsed-time-based globally effect is repeatable.
258        @param elapsedTime
259            The new elapsed time.
260        */
261        void setElapsedTime(Real elapsedTime);
262
263        /** Override standard Singleton retrieval.
264        @remarks
265        Why do we do this? Well, it's because the Singleton
266        implementation is in a .h file, which means it gets compiled
267        into anybody who includes it. This is needed for the
268        Singleton template to work, but we actually only want it
269        compiled into the implementation of the class based on the
270        Singleton, not all of them. If we don't change this, we get
271        link errors when trying to use the Singleton-based class from
272        an outside dll.
273        @par
274        This method just delegates to the template version anyway,
275        but the implementation stays in this single compilation unit,
276        preventing link errors.
277        */
278        static ControllerManager& getSingleton(void);
279        /** Override standard Singleton retrieval.
280        @remarks
281        Why do we do this? Well, it's because the Singleton
282        implementation is in a .h file, which means it gets compiled
283        into anybody who includes it. This is needed for the
284        Singleton template to work, but we actually only want it
285        compiled into the implementation of the class based on the
286        Singleton, not all of them. If we don't change this, we get
287        link errors when trying to use the Singleton-based class from
288        an outside dll.
289        @par
290        This method just delegates to the template version anyway,
291        but the implementation stays in this single compilation unit,
292        preventing link errors.
293        */
294        static ControllerManager* getSingletonPtr(void);
295    };
296
297    /** @} */
298    /** @} */
299
300} // namespace Ogre
301
302#include "OgreHeaderSuffix.h"
303
304#endif // __ControllerManager_H__
Note: See TracBrowser for help on using the repository browser.