Coverage Report

Created: 2025-10-10 06:42

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ogre/OgreMain/include/OgrePredefinedControllers.h
Line
Count
Source
1
/*
2
-----------------------------------------------------------------------------
3
This source file is part of OGRE
4
    (Object-oriented Graphics Rendering Engine)
5
For the latest info, see http://www.ogre3d.org/
6
7
Copyright (c) 2000-2014 Torus Knot Software Ltd
8
9
Permission is hereby granted, free of charge, to any person obtaining a copy
10
of this software and associated documentation files (the "Software"), to deal
11
in the Software without restriction, including without limitation the rights
12
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
copies of the Software, and to permit persons to whom the Software is
14
furnished to do so, subject to the following conditions:
15
16
The above copyright notice and this permission notice shall be included in
17
all copies or substantial portions of the Software.
18
19
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25
THE 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 "OgreHeaderPrefix.h"
37
38
namespace Ogre {
39
40
    /** \addtogroup Core
41
    *  @{
42
    */
43
    /** \addtogroup Animation
44
    *  @{
45
    */
46
    //-----------------------------------------------------------------------
47
    // Controller Values
48
    //-----------------------------------------------------------------------
49
    /** Predefined controller value for getting the latest frame time.
50
    */
51
    class _OgreExport FrameTimeControllerValue : public ControllerValue<float>, private FrameListener
52
    {
53
    private:
54
        Real mFrameTime;
55
        Real mTimeFactor;
56
        Real mElapsedTime;
57
        Real mFrameDelay;
58
59
        bool frameStarted(const FrameEvent &evt) override;
60
    public:
61
        /// @deprecated use create()
62
        FrameTimeControllerValue();
63
64
0
        static ControllerValueRealPtr create() { return std::make_shared<FrameTimeControllerValue>(); }
65
66
0
        float getValue(void) const override { return mFrameTime; }
67
0
        void setValue(float value) override { /* Do nothing - value is set from frame listener */ }
68
0
        Real getTimeFactor(void) const { return mTimeFactor; }
69
        /// @copydoc ControllerManager::setTimeFactor
70
        void setTimeFactor(Real tf);
71
0
        Real getFrameDelay(void) const { return mFrameDelay; }
72
        /// @copydoc ControllerManager::setFrameDelay
73
        void setFrameDelay(Real fd);
74
0
        Real getElapsedTime(void) const { return mElapsedTime; }
75
0
        void setElapsedTime(Real elapsedTime) { mElapsedTime = elapsedTime; }
76
    };
77
78
    //-----------------------------------------------------------------------
79
    /** Predefined controller value for getting / setting the frame number of a texture layer
80
    */
81
    class _OgreExport TextureFrameControllerValue : public ControllerValue<float>
82
    {
83
    private:
84
        TextureUnitState* mTextureLayer;
85
    public:
86
        /// @deprecated use create()
87
        TextureFrameControllerValue(TextureUnitState* t);
88
89
        static ControllerValueRealPtr create(TextureUnitState* t)
90
0
        {
91
0
            return std::make_shared<TextureFrameControllerValue>(t);
92
0
        }
93
94
        /** Gets the frame number as a parametric value in the range [0,1]
95
        */
96
        float getValue(void) const override;
97
        /** Sets the frame number as a parametric value in the range [0,1]; the actual frame number is (value * numFrames) % numFrames).
98
        */
99
        void setValue(float value) override;
100
101
    };
102
    //-----------------------------------------------------------------------
103
    /** Predefined controller value for getting / setting a texture coordinate modifications (scales and translates).
104
105
        Effects can be applied to the scale or the offset of the u or v coordinates, or both. If separate
106
        modifications are required to u and v then 2 instances are required to control both independently, or 4
107
        if you want separate u and v scales as well as separate u and v offsets.
108
        @par
109
            Because of the nature of this value, it can accept values outside the 0..1 parametric range.
110
    */
111
    class _OgreExport TexCoordModifierControllerValue : public ControllerValue<float>
112
    {
113
    private:
114
        bool mTransU, mTransV;
115
        bool mScaleU, mScaleV;
116
        bool mRotate;
117
        TextureUnitState* mTextureLayer;
118
    public:
119
        /// @deprecated use create
120
        TexCoordModifierControllerValue(TextureUnitState* t, bool translateU = false, bool translateV = false,
121
            bool scaleU = false, bool scaleV = false, bool rotate = false );
122
123
        /** Constructor.
124
            @param
125
                t TextureUnitState to apply the modification to.
126
            @param
127
                translateU If true, the u coordinates will be translated by the modification.
128
            @param
129
                translateV If true, the v coordinates will be translated by the modification.
130
            @param
131
                scaleU If true, the u coordinates will be scaled by the modification.
132
            @param
133
                scaleV If true, the v coordinates will be scaled by the modification.
134
            @param
135
                rotate If true, the texture will be rotated by the modification.
136
        */
137
        static ControllerValueRealPtr create(TextureUnitState* t, bool translateU = false, bool translateV = false,
138
                                             bool scaleU = false, bool scaleV = false, bool rotate = false)
139
0
        {
140
0
            return std::make_shared<TexCoordModifierControllerValue>(t, translateU, translateV, scaleU, scaleV, rotate);
141
0
        }
142
143
        float getValue(void) const override;
144
        void setValue(float value) override;
145
146
    };
147
148
    //-----------------------------------------------------------------------
149
    /** Predefined controller value for setting a single floating-
150
        point value in a constant parameter of a vertex or fragment program.
151
152
        Any value is accepted, it is propagated into the 'x'
153
        component of the constant register identified by the index. If you
154
        need to use named parameters, retrieve the index from the param
155
        object before setting this controller up.
156
    @note
157
        Retrieving a value from the program parameters is not currently
158
        supported, therefore do not use this controller value as a source,
159
        only as a target.
160
    */
161
    class _OgreExport FloatGpuParameterControllerValue : public ControllerValue<float>
162
    {
163
    private:
164
        /// The parameters to access
165
        GpuProgramParametersSharedPtr mParams;
166
        /// The index of the parameter to be read or set
167
        size_t mParamIndex;
168
    public:
169
        /// @deprecated use create()
170
        FloatGpuParameterControllerValue(const GpuProgramParametersSharedPtr& params, size_t index);
171
172
        /** Constructor.
173
            @param
174
                params The parameters object to access
175
            @param
176
                index The index of the parameter to be set
177
        */
178
        static ControllerValueRealPtr create(const GpuProgramParametersSharedPtr& params, size_t index)
179
0
        {
180
0
            return std::make_shared<FloatGpuParameterControllerValue>(params, index);
181
0
        }
182
183
        float getValue(void) const override;
184
        void setValue(float value) override;
185
186
    };
187
    //-----------------------------------------------------------------------
188
    // Controller functions
189
    //-----------------------------------------------------------------------
190
191
    /** Predefined controller function which just passes through the original source
192
    directly to dest.
193
    */
194
    class _OgreExport PassthroughControllerFunction : public ControllerFunction<float>
195
    {
196
    public:
197
        /// @deprecated use create()
198
        PassthroughControllerFunction(bool deltaInput = false);
199
200
        /// @copydoc ControllerFunction::ControllerFunction
201
        static ControllerFunctionRealPtr create(bool deltaInput = false)
202
0
        {
203
0
            return std::make_shared<PassthroughControllerFunction>(deltaInput);
204
0
        }
205
206
        float calculate(float source) override;
207
    };
208
209
    /** Predefined controller function for dealing with animation.
210
    */
211
    class _OgreExport AnimationControllerFunction : public ControllerFunction<float>
212
    {
213
    private:
214
        Real mSeqTime;
215
        Real mTime;
216
    public:
217
        /// @deprecated use create()
218
        AnimationControllerFunction(Real sequenceTime, Real timeOffset = 0.0f);
219
220
        /** Constructor.
221
            @param
222
                sequenceTime The amount of time in seconds it takes to loop through the whole animation sequence.
223
            @param
224
                timeOffset The offset in seconds at which to start (default is start at 0)
225
        */
226
        static ControllerFunctionRealPtr create(Real sequenceTime, Real timeOffset = 0.0f)
227
0
        {
228
0
            return std::make_shared<AnimationControllerFunction>(sequenceTime, timeOffset);
229
0
        }
230
231
        float calculate(float source) override;
232
233
        /** Set the time value manually. */
234
        void setTime(Real timeVal);
235
        /** Set the sequence duration value manually. */
236
        void setSequenceTime(Real seqVal);
237
    };
238
239
    //-----------------------------------------------------------------------
240
    /** Predefined controller function which simply scales an input to an output value.
241
    */
242
    class _OgreExport ScaleControllerFunction : public ControllerFunction<float>
243
    {
244
    private:
245
        Real mScale;
246
    public:
247
        /// @deprecated use create()
248
        ScaleControllerFunction(Real scalefactor, bool deltaInput);
249
250
        /** Constructor, requires a scale factor.
251
            @param
252
                scalefactor The multiplier applied to the input to produce the output.
253
            @param
254
                deltaInput If true, signifies that the input will be a delta value such that the function should
255
                 add it to an internal counter before calculating the output.
256
        */
257
        static ControllerFunctionRealPtr create(Real scalefactor, bool deltaInput = false)
258
0
        {
259
0
            return std::make_shared<ScaleControllerFunction>(scalefactor, deltaInput);
260
0
        }
261
262
        float calculate(float source) override;
263
    };
264
265
    //-----------------------------------------------------------------------
266
    /** Predefined controller function based on a waveform.
267
268
        A waveform function translates parametric input to parametric output based on a wave.
269
        @par
270
            Note that for simplicity of integration with the rest of the controller insfrastructure, the output of
271
            the wave is parametric i.e. 0..1, rather than the typical wave output of [-1,1]. To compensate for this, the
272
            traditional output of the wave is scaled by the following function before output:
273
        @par
274
            output = (waveoutput + 1) * 0.5
275
        @par
276
            Hence a wave output of -1 becomes 0, a wave output of 1 becomes 1, and a wave output of 0 becomes 0.5.
277
    */
278
    class _OgreExport WaveformControllerFunction : public ControllerFunction<float>
279
    {
280
    private:
281
        WaveformType mWaveType;
282
        Real mBase;
283
        Real mFrequency;
284
        Real mPhase;
285
        Real mAmplitude;
286
        Real mDutyCycle;
287
288
        /** Overridden from ControllerFunction. */
289
        Real getAdjustedInput(Real input);
290
291
    public:
292
        /// @deprecated use create()
293
        WaveformControllerFunction(WaveformType wType, Real base = 0, Real frequency = 1, Real phase = 0, Real amplitude = 1, bool deltaInput = true, Real dutyCycle = 0.5);
294
295
        /** Default constructor, requires at least a wave type, other parameters can be defaulted unless required.
296
            @param wType the shape of the wave
297
            @param base the base value of the output from the wave
298
            @param frequency the speed of the wave in cycles per second
299
            @param phase the offset of the start of the wave, e.g. 0.5 to start half-way through the wave
300
            @param amplitude scales the output so that instead of lying within [0,1] it lies within [0,1] * amplitude
301
            @param
302
                deltaInput If true, signifies that the input will be a delta value such that the function should
303
                add it to an internal counter before calculating the output.
304
            @param
305
                dutyCycle Used in PWM mode to specify the pulse width.
306
        */
307
        static ControllerFunctionRealPtr create(WaveformType wType, Real base = 0, Real frequency = 1, Real phase = 0, Real amplitude = 1, bool deltaInput = true, Real dutyCycle = 0.5)
308
0
        {
309
0
            return std::make_shared<WaveformControllerFunction>(wType, base, frequency, phase, amplitude, deltaInput, dutyCycle);
310
0
        }
311
312
        float calculate(float source) override;
313
    };
314
315
    //-----------------------------------------------------------------------
316
    /** Predefined controller function based on linear function interpolation.
317
    */
318
    class _OgreExport LinearControllerFunction : public ControllerFunction<float> {
319
        Real mFrequency;
320
        std::vector<Real> mKeys;
321
        std::vector<Real> mValues;
322
    public:
323
        /// @deprecated use create()
324
        LinearControllerFunction(const std::vector<Real>& keys, const std::vector<Real>& values, Real frequency = 1, bool deltaInput = true);
325
326
        /** Constructor, requires keys and values of the function to interpolate
327
328
            For simplicity and compatibility with the predefined ControllerValue classes the function domain must be [0,1].
329
            However, you can use the frequency parameter to rescale the domain to a different range.
330
            @param
331
                keys the x-values of the function sampling points. Value range is [0,1]. Must include at least the keys 0 and 1.
332
            @param
333
                values the function values f(x) of the function. order must match keys
334
            @param frequency the speed of the evaluation in cycles per second
335
            @param
336
                deltaInput If true, signifies that the input will be a delta value such that the function should
337
                 add it to an internal counter before calculating the output.
338
            @note
339
                there must be the same amount of keys and values
340
        */
341
        static ControllerFunctionRealPtr create(const std::vector<Real>& keys, const std::vector<Real>& values, Real frequency = 1, bool deltaInput = true)
342
0
        {
343
0
            return std::make_shared<LinearControllerFunction>(keys, values, frequency, deltaInput);
344
0
        }
345
346
        float calculate(float source) override;
347
    };
348
    //-----------------------------------------------------------------------
349
    /** @} */
350
    /** @} */
351
352
}
353
354
#include "OgreHeaderSuffix.h"
355
356
#endif