Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/ogre_src_v1-9-0/OgreMain/include/OgrePredefinedControllers.h

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

Added new dependencies for ogre1.9 and cegui0.8

File size: 11.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-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 __PredefinedControllers_H__
29#define __PredefinedControllers_H__
30
31#include "OgrePrerequisites.h"
32
33#include "OgreCommon.h"
34#include "OgreController.h"
35#include "OgreFrameListener.h"
36#include "OgreGpuProgram.h"
37#include "OgreHeaderPrefix.h"
38
39namespace Ogre {
40
41        /** \addtogroup Core
42        *  @{
43        */
44        /** \addtogroup General
45        *  @{
46        */
47        //-----------------------------------------------------------------------
48    // Controller Values
49    //-----------------------------------------------------------------------
50    /** Predefined controller value for getting the latest frame time.
51    */
52    class _OgreExport FrameTimeControllerValue : public ControllerValue<Real>, public FrameListener
53    {
54    protected:
55        Real mFrameTime;
56                Real mTimeFactor;
57                Real mElapsedTime;
58                Real mFrameDelay;
59
60    public:
61        FrameTimeControllerValue();
62        bool frameEnded(const FrameEvent &evt);
63        bool frameStarted(const FrameEvent &evt);
64        Real getValue(void) const;
65        void setValue(Real value);
66                Real getTimeFactor(void) const;
67                void setTimeFactor(Real tf);
68                Real getFrameDelay(void) const;
69                void setFrameDelay(Real fd);
70                Real getElapsedTime(void) const;
71                void setElapsedTime(Real elapsedTime);
72    };
73
74    //-----------------------------------------------------------------------
75    /** Predefined controller value for getting / setting the frame number of a texture layer
76    */
77    class _OgreExport TextureFrameControllerValue : public ControllerValue<Real>
78    {
79    protected:
80        TextureUnitState* mTextureLayer;
81    public:
82        TextureFrameControllerValue(TextureUnitState* t);
83
84        /** Gets the frame number as a parametric value in the range [0,1]
85        */
86        Real getValue(void) const;
87        /** Sets the frame number as a parametric value in the range [0,1]; the actual frame number is (value * numFrames) % numFrames).
88        */
89        void setValue(Real value);
90
91    };
92    //-----------------------------------------------------------------------
93    /** Predefined controller value for getting / setting a texture coordinate modifications (scales and translates).
94        @remarks
95            Effects can be applied to the scale or the offset of the u or v coordinates, or both. If separate
96            modifications are required to u and v then 2 instances are required to control both independently, or 4
97            if you want separate u and v scales as well as separate u and v offsets.
98        @par
99            Because of the nature of this value, it can accept values outside the 0..1 parametric range.
100    */
101    class _OgreExport TexCoordModifierControllerValue : public ControllerValue<Real>
102    {
103    protected:
104        bool mTransU, mTransV;
105        bool mScaleU, mScaleV;
106        bool mRotate;
107        TextureUnitState* mTextureLayer;
108    public:
109        /** Constructor.
110            @param
111                t TextureUnitState to apply the modification to.
112            @param
113                translateU If true, the u coordinates will be translated by the modification.
114            @param
115                translateV If true, the v coordinates will be translated by the modification.
116            @param
117                scaleU If true, the u coordinates will be scaled by the modification.
118            @param
119                scaleV If true, the v coordinates will be scaled by the modification.
120            @param
121                rotate If true, the texture will be rotated by the modification.
122        */
123        TexCoordModifierControllerValue(TextureUnitState* t, bool translateU = false, bool translateV = false,
124            bool scaleU = false, bool scaleV = false, bool rotate = false );
125
126        Real getValue(void) const;
127        void setValue(Real value);
128
129    };
130
131    //-----------------------------------------------------------------------
132    /** Predefined controller value for setting a single floating-
133            point value in a constant parameter of a vertex or fragment program.
134    @remarks
135                Any value is accepted, it is propagated into the 'x'
136                component of the constant register identified by the index. If you
137                need to use named parameters, retrieve the index from the param
138                object before setting this controller up.
139        @note
140                Retrieving a value from the program parameters is not currently
141                supported, therefore do not use this controller value as a source,
142                only as a target.
143    */
144    class _OgreExport FloatGpuParameterControllerValue : public ControllerValue<Real>
145    {
146    protected:
147                /// The parameters to access
148                GpuProgramParametersSharedPtr mParams;
149                /// The index of the parameter to be read or set
150                size_t mParamIndex;
151    public:
152        /** Constructor.
153                    @param
154                                params The parameters object to access
155            @param
156                index The index of the parameter to be set
157        */
158        FloatGpuParameterControllerValue(GpuProgramParametersSharedPtr params,
159                                size_t index );
160
161        ~FloatGpuParameterControllerValue() {}
162
163        Real getValue(void) const;
164        void setValue(Real value);
165
166    };
167    //-----------------------------------------------------------------------
168    // Controller functions
169    //-----------------------------------------------------------------------
170
171        /** Predefined controller function which just passes through the original source
172        directly to dest.
173        */
174        class _OgreExport PassthroughControllerFunction : public ControllerFunction<Real>
175        {
176        public:
177                /** Constructor.
178         @param
179             deltaInput If true, signifies that the input will be a delta value such that the function should
180             add it to an internal counter before calculating the output.
181                */
182                PassthroughControllerFunction(bool deltaInput = false);
183
184                /** Overridden function.
185                */
186                Real calculate(Real source);
187        };
188
189        /** Predefined controller function for dealing with animation.
190    */
191    class _OgreExport AnimationControllerFunction : public ControllerFunction<Real>
192    {
193    protected:
194        Real mSeqTime;
195        Real mTime;
196    public:
197        /** Constructor.
198            @param
199                sequenceTime The amount of time in seconds it takes to loop through the whole animation sequence.
200            @param
201                timeOffset The offset in seconds at which to start (default is start at 0)
202        */
203        AnimationControllerFunction(Real sequenceTime, Real timeOffset = 0.0f);
204
205        /** Overridden function.
206        */
207        Real calculate(Real source);
208
209                /** Set the time value manually. */
210                void setTime(Real timeVal);
211                /** Set the sequence duration value manually. */
212                void setSequenceTime(Real seqVal);
213    };
214
215        //-----------------------------------------------------------------------
216    /** Predefined controller function which simply scales an input to an output value.
217    */
218    class _OgreExport ScaleControllerFunction : public ControllerFunction<Real>
219    {
220    protected:
221        Real mScale;
222    public:
223        /** Constructor, requires a scale factor.
224            @param
225                scalefactor The multiplier applied to the input to produce the output.
226            @param
227                deltaInput If true, signifies that the input will be a delta value such that the function should
228                 add it to an internal counter before calculating the output.
229        */
230        ScaleControllerFunction(Real scalefactor, bool deltaInput);
231
232        /** Overridden method.
233        */
234        Real calculate(Real source);
235
236    };
237
238    //-----------------------------------------------------------------------
239    /** Predefined controller function based on a waveform.
240        @remarks
241            A waveform function translates parametric input to parametric output based on a wave. The factors
242            affecting the function are:
243            - wave type - the shape of the wave
244            - base - the base value of the output from the wave
245            - frequency - the speed of the wave in cycles per second
246            - phase - the offset of the start of the wave, e.g. 0.5 to start half-way through the wave
247            - amplitude - scales the output so that instead of lying within [0,1] it lies within [0,1] * amplitude
248                        - duty cycle - the active width of a PWM signal
249        @par
250            Note that for simplicity of integration with the rest of the controller insfrastructure, the output of
251            the wave is parametric i.e. 0..1, rather than the typical wave output of [-1,1]. To compensate for this, the
252            traditional output of the wave is scaled by the following function before output:
253        @par
254            output = (waveoutput + 1) * 0.5
255        @par
256            Hence a wave output of -1 becomes 0, a wave output of 1 becomes 1, and a wave output of 0 becomes 0.5.
257    */
258    class _OgreExport WaveformControllerFunction : public ControllerFunction<Real>
259    {
260    protected:
261        WaveformType mWaveType;
262        Real mBase;
263        Real mFrequency;
264        Real mPhase;
265        Real mAmplitude;
266                Real mDutyCycle;
267
268        /** Overridden from ControllerFunction. */
269        Real getAdjustedInput(Real input);
270
271    public:
272        /** Default constructor, requires at least a wave type, other parameters can be defaulted unless required.
273            @param
274                deltaInput If true, signifies that the input will be a delta value such that the function should
275                add it to an internal counter before calculating the output.
276                        @param
277                                dutyCycle Used in PWM mode to specify the pulse width.
278        */
279        WaveformControllerFunction(WaveformType wType, Real base = 0, Real frequency = 1, Real phase = 0, Real amplitude = 1, bool deltaInput = true, Real dutyCycle = 0.5);
280
281        /** Overridden function.
282        */
283        Real calculate(Real source);
284
285    };
286    //-----------------------------------------------------------------------
287        /** @} */
288        /** @} */
289
290}
291
292#include "OgreHeaderSuffix.h"
293
294#endif
Note: See TracBrowser for help on using the repository browser.