source: GTP/trunk/App/Demos/Geom/OgreStuff/include/OgreControllerManager.h @ 1092

Revision 1092, 10.5 KB checked in by gumbau, 18 years ago (diff)

LodStrips? and LODTrees demos

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-2005 The OGRE Team
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-----------------------------------------------------------------------------
24*/
25#ifndef __ControllerManager_H__
26#define __ControllerManager_H__
27
28#include "OgrePrerequisites.h"
29
30#include "OgreCommon.h"
31#include "OgreSingleton.h"
32#include "OgreController.h"
33#include "OgrePredefinedControllers.h"
34#include "OgreTextureUnitState.h"
35#include "OgreSharedPtr.h"
36
37namespace Ogre {
38
39    typedef SharedPtr< ControllerValue<Real> > ControllerValueRealPtr;
40    typedef SharedPtr< ControllerFunction<Real> > ControllerFunctionRealPtr;
41
42    /** Class for managing Controller instances.
43        @remarks
44            This class is responsible to keeping tabs on all the Controller instances registered
45            and updating them when requested. It also provides a number of convenience methods
46            for creating commonly used controllers (such as texture animators).
47    */
48    class _OgreExport ControllerManager : public Singleton<ControllerManager>
49    {
50    protected:
51        typedef std::set<Controller<Real>*> ControllerList;
52        ControllerList mControllers;
53
54        /// Global predefined controller
55        SharedPtr< ControllerValue<Real> > mFrameTimeController;
56
57    public:
58        ControllerManager();
59        ~ControllerManager();
60
61        /** Creates a new controller and registers it with the manager.
62        */
63        Controller<Real>* createController(const ControllerValueRealPtr& src,
64            const ControllerValueRealPtr& dest, const ControllerFunctionRealPtr& func);
65
66        /** Destroys all the controllers in existence.
67        */
68        void clearControllers(void);
69
70        /** Updates all the registered controllers.
71        */
72        void updateAllControllers(void);
73
74
75        /** Returns a ControllerValue which provides the time since the last frame as a control value source.
76            @remarks
77                A common source value to use to feed into a controller is the time since the last frame. This method
78                returns a pointer to a common source value which provides this information.
79            @par
80                Remember the value will only be up to date after the RenderSystem::beginFrame method is called.
81            @see
82                RenderSystem::beginFrame
83        */
84        const ControllerValueRealPtr& getFrameTimeSource(void) const;
85
86        /** Creates a texture layer animator controller.
87            @remarks
88                This helper method creates the Controller, ControllerValue and ControllerFunction classes required
89                to animate a texture.
90            @param
91                layer TextureUnitState object to animate
92            @param
93                sequenceTime The amount of time in seconds it will take to loop through all the frames.
94        */
95        Controller<Real>* createTextureAnimator(TextureUnitState* layer, Real sequenceTime);
96
97        /** Creates a basic time-based texture coordinate modifier designed for creating scrolling textures.
98            @remarks
99                This simple method allows you to easily create constant-speed scrolling textures. If you want more
100                control, look up the ControllerManager::createTextureWaveTransformer for more complex wave-based
101                scrollers / stretchers / rotaters.
102            @param
103                layer The texture layer to animate.
104            @param
105                uSpeed Speed of horizontal (u-coord) scroll, in complete wraps per second
106            @param
107                vSpeed Speed of vertical (v-coord) scroll, in complete wraps per second
108        */
109        Controller<Real>* createTextureScroller(TextureUnitState* layer, Real uSpeed, Real vSpeed);
110
111        /** Creates a basic time-based texture coordinate modifier designed for creating rotating textures.
112            @return
113                This simple method allows you to easily create constant-speed rotating textures. If you want more
114                control, look up the ControllerManager::createTextureWaveTransformer for more complex wave-based
115                scrollers / stretchers / rotaters.
116            @param
117                layer The texture layer to rotate.
118            @param
119                vSpeed Speed of rotation, in complete anticlockwise revolutions per second
120        */
121        Controller<Real>* createTextureRotater(TextureUnitState* layer, Real speed);
122
123        /** Creates a very flexible time-based texture transformation which can alter the scale, position or
124            rotation of a texture based on a wave function.
125            @param
126                layer The texture layer to affect
127            @param
128                ttype The type of transform, either translate (scroll), scale (stretch) or rotate (spin)
129            @param
130                waveType The shape of the wave, see WaveformType enum for details
131            @param
132                base The base value of the output
133            @param
134                frequency The speed of the wave in cycles per second
135            @param
136                phase The offset of the start of the wave, e.g. 0.5 to start half-way through the wave
137            @param
138                amplitude Scales the output so that instead of lying within 0..1 it lies within 0..1*amplitude for exaggerated effects
139        */
140        Controller<Real>* createTextureWaveTransformer(TextureUnitState* layer, TextureUnitState::TextureTransformType ttype,
141            WaveformType waveType, Real base = 0, Real frequency = 1, Real phase = 0, Real amplitude = 1);
142
143        /** Creates a controller for passing a frame time value through to a vertex / fragment program parameter.
144        @remarks
145            The destination parameter is expected to be a float, and the '.x' attribute will be populated
146            with the appropriately scaled time value.
147        @param params The parameters to update
148        @param paramIndex The index of the parameter to update; if you want a named parameter, then
149            retrieve the index beforehand using GpuProgramParameters::getParamIndex
150        @param factor The factor by which to adjust the time elapsed by before passing it to the program
151        */
152        Controller<Real>* createGpuProgramTimerParam(GpuProgramParameters* params, size_t paramIndex,
153            Real timeFactor = 1.0f);
154
155        /** Removes & destroys the controller passed in as a pointer.
156        */
157        void destroyController(Controller<Real>* controller);
158
159                /** Return relative speed of time as perceived by time based controllers.
160        @remarks
161            See setTimeFactor for full information on the meaning of this value.
162                */
163                Real getTimeFactor(void) const;
164
165                /** Set the relative speed to update frame time based controllers.
166        @remarks
167            Normally any controllers which use time as an input (FrameTimeController) are updated
168            automatically in line with the real passage of time. This method allows you to change
169            that, so that controllers are told that the time is passing slower or faster than it
170            actually is. Use this to globally speed up / slow down the effect of time-based controllers.
171        @param tf The virtual speed of time (1.0 is real time).
172                */
173                void setTimeFactor(Real tf);
174
175        /** Return the elapsed time.
176        @remarks
177            See setElapsedTime for full information on the meaning of this value.
178        */
179        Real getElapsedTime(void) const;
180
181        /** Set the elapsed time.
182        @remarks
183            Normally elapsed time accumulated all frames time (which speed relative to time
184            factor) since the rendering loop started. This method allows your to change that to
185            special time, so some elapsed-time-based globally effect is repeatable.
186        @param elapsedTime The new elapsed time
187        */
188        void setElapsedTime(Real elapsedTime);
189
190        /** Override standard Singleton retrieval.
191        @remarks
192        Why do we do this? Well, it's because the Singleton
193        implementation is in a .h file, which means it gets compiled
194        into anybody who includes it. This is needed for the
195        Singleton template to work, but we actually only want it
196        compiled into the implementation of the class based on the
197        Singleton, not all of them. If we don't change this, we get
198        link errors when trying to use the Singleton-based class from
199        an outside dll.
200        @par
201        This method just delegates to the template version anyway,
202        but the implementation stays in this single compilation unit,
203        preventing link errors.
204        */
205        static ControllerManager& getSingleton(void);
206        /** Override standard Singleton retrieval.
207        @remarks
208        Why do we do this? Well, it's because the Singleton
209        implementation is in a .h file, which means it gets compiled
210        into anybody who includes it. This is needed for the
211        Singleton template to work, but we actually only want it
212        compiled into the implementation of the class based on the
213        Singleton, not all of them. If we don't change this, we get
214        link errors when trying to use the Singleton-based class from
215        an outside dll.
216        @par
217        This method just delegates to the template version anyway,
218        but the implementation stays in this single compilation unit,
219        preventing link errors.
220        */
221        static ControllerManager* getSingletonPtr(void);
222    };
223
224
225}
226#endif
Note: See TracBrowser for help on using the repository browser.