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-2005 The OGRE Team
|
---|
8 | Also see acknowledgements in Readme.html
|
---|
9 |
|
---|
10 | This program is free software; you can redistribute it and/or modify it under
|
---|
11 | the terms of the GNU Lesser General Public License as published by the Free Software
|
---|
12 | Foundation; either version 2 of the License, or (at your option) any later
|
---|
13 | version.
|
---|
14 |
|
---|
15 | This program is distributed in the hope that it will be useful, but WITHOUT
|
---|
16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
---|
17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
---|
18 |
|
---|
19 | You should have received a copy of the GNU Lesser General Public License along with
|
---|
20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
---|
21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to
|
---|
22 | http://www.gnu.org/copyleft/lesser.txt.
|
---|
23 | -----------------------------------------------------------------------------
|
---|
24 | */
|
---|
25 | #ifndef __PredefinedControllers_H__
|
---|
26 | #define __PredefinedControllers_H__
|
---|
27 |
|
---|
28 | #include "OgrePrerequisites.h"
|
---|
29 |
|
---|
30 | #include "OgreCommon.h"
|
---|
31 | #include "OgreController.h"
|
---|
32 | #include "OgreFrameListener.h"
|
---|
33 | #include "OgreGpuProgram.h"
|
---|
34 |
|
---|
35 | namespace Ogre {
|
---|
36 |
|
---|
37 | //-----------------------------------------------------------------------
|
---|
38 | // Controller Values
|
---|
39 | //-----------------------------------------------------------------------
|
---|
40 | /** Predefined controller value for getting the latest frame time.
|
---|
41 | */
|
---|
42 | class _OgreExport FrameTimeControllerValue : public ControllerValue<Real>, public FrameListener
|
---|
43 | {
|
---|
44 | protected:
|
---|
45 | Real mFrameTime;
|
---|
46 | Real mTimeFactor;
|
---|
47 | Real mElapsedTime;
|
---|
48 |
|
---|
49 | public:
|
---|
50 | FrameTimeControllerValue();
|
---|
51 | bool frameEnded(const FrameEvent &evt);
|
---|
52 | bool frameStarted(const FrameEvent &evt);
|
---|
53 | Real getValue(void) const;
|
---|
54 | void setValue(Real value);
|
---|
55 | Real getTimeFactor(void) const;
|
---|
56 | void setTimeFactor(Real tf);
|
---|
57 | Real getElapsedTime(void) const;
|
---|
58 | void setElapsedTime(Real elapsedTime);
|
---|
59 | };
|
---|
60 |
|
---|
61 | //-----------------------------------------------------------------------
|
---|
62 | /** Predefined controller value for getting / setting the frame number of a texture layer
|
---|
63 | */
|
---|
64 | class _OgreExport TextureFrameControllerValue : public ControllerValue<Real>
|
---|
65 | {
|
---|
66 | protected:
|
---|
67 | TextureUnitState* mTextureLayer;
|
---|
68 | public:
|
---|
69 | TextureFrameControllerValue(TextureUnitState* t);
|
---|
70 |
|
---|
71 | /** Gets the frame number as a parametric value in the range [0,1]
|
---|
72 | */
|
---|
73 | Real getValue(void) const;
|
---|
74 | /** Sets the frame number as a parametric value in the range [0,1]; the actual frame number is value * (numFrames-1).
|
---|
75 | */
|
---|
76 | void setValue(Real value);
|
---|
77 |
|
---|
78 | };
|
---|
79 | //-----------------------------------------------------------------------
|
---|
80 | /** Predefined controller value for getting / setting a texture coordinate modifications (scales and translates).
|
---|
81 | @remarks
|
---|
82 | Effects can be applied to the scale or the offset of the u or v coordinates, or both. If separate
|
---|
83 | modifications are required to u and v then 2 instances are required to control both independently, or 4
|
---|
84 | if you ant separate u and v scales as well as separate u and v offsets.
|
---|
85 | @par
|
---|
86 | Because of the nature of this value, it can accept values outside the 0..1 parametric range.
|
---|
87 | */
|
---|
88 | class _OgreExport TexCoordModifierControllerValue : public ControllerValue<Real>
|
---|
89 | {
|
---|
90 | protected:
|
---|
91 | bool mTransU, mTransV;
|
---|
92 | bool mScaleU, mScaleV;
|
---|
93 | bool mRotate;
|
---|
94 | TextureUnitState* mTextureLayer;
|
---|
95 | public:
|
---|
96 | /** Constructor.
|
---|
97 | @param
|
---|
98 | t TextureUnitState to apply the modification to.
|
---|
99 | @param
|
---|
100 | translateU If true, the u coordinates will be translated by the modification.
|
---|
101 | @param
|
---|
102 | translateV If true, the v coordinates will be translated by the modification.
|
---|
103 | @param
|
---|
104 | scaleU If true, the u coordinates will be scaled by the modification.
|
---|
105 | @param
|
---|
106 | scaleV If true, the v coordinates will be scaled by the modification.
|
---|
107 | @param
|
---|
108 | rotate If true, the texture will be rotated by the modification.
|
---|
109 | */
|
---|
110 | TexCoordModifierControllerValue(TextureUnitState* t, bool translateU = false, bool translateV = false,
|
---|
111 | bool scaleU = false, bool scaleV = false, bool rotate = false );
|
---|
112 |
|
---|
113 | Real getValue(void) const;
|
---|
114 | void setValue(Real value);
|
---|
115 |
|
---|
116 | };
|
---|
117 |
|
---|
118 | //-----------------------------------------------------------------------
|
---|
119 | /** Predefined controller value for setting a single floating-
|
---|
120 | point value in a constant paramter of a vertex or fragment program.
|
---|
121 | @remarks
|
---|
122 | Any value is accepted, it is propagated into the 'x'
|
---|
123 | component of the constant register identified by the index. If you
|
---|
124 | need to use named parameters, retrieve the index from the param
|
---|
125 | object before setting this controller up.
|
---|
126 | @note
|
---|
127 | Retrieving a value from the program parameters is not currently
|
---|
128 | supported, therefore do not use this controller value as a source,
|
---|
129 | only as a target.
|
---|
130 | */
|
---|
131 | class _OgreExport FloatGpuParameterControllerValue : public ControllerValue<Real>
|
---|
132 | {
|
---|
133 | protected:
|
---|
134 | /// The parameters to access
|
---|
135 | GpuProgramParameters* mParams;
|
---|
136 | /// The index of the parameter to e read or set
|
---|
137 | size_t mParamIndex;
|
---|
138 | public:
|
---|
139 | /** Constructor.
|
---|
140 | @param
|
---|
141 | params The parameters object to access
|
---|
142 | @param
|
---|
143 | index The index of the parameter to be set
|
---|
144 | */
|
---|
145 | FloatGpuParameterControllerValue(GpuProgramParameters* params,
|
---|
146 | size_t index );
|
---|
147 |
|
---|
148 | ~FloatGpuParameterControllerValue() {}
|
---|
149 |
|
---|
150 | Real getValue(void) const;
|
---|
151 | void setValue(Real value);
|
---|
152 |
|
---|
153 | };
|
---|
154 | //-----------------------------------------------------------------------
|
---|
155 | // Controller functions
|
---|
156 | //-----------------------------------------------------------------------
|
---|
157 |
|
---|
158 | /** Predefined controller function for dealing with animation.
|
---|
159 | */
|
---|
160 | class _OgreExport AnimationControllerFunction : public ControllerFunction<Real>
|
---|
161 | {
|
---|
162 | protected:
|
---|
163 | Real mSeqTime;
|
---|
164 | Real mTime;
|
---|
165 | public:
|
---|
166 | /** Constructor.
|
---|
167 | @param
|
---|
168 | sequenceTime The amount of time in seconds it takes to loop through the whole animation sequence.
|
---|
169 | @param
|
---|
170 | timeOffset The offset in seconds at which to start (default is start at 0)
|
---|
171 | */
|
---|
172 | AnimationControllerFunction(Real sequenceTime, Real timeOffset = 0.0f);
|
---|
173 |
|
---|
174 | /** Overriden function.
|
---|
175 | */
|
---|
176 | Real calculate(Real source);
|
---|
177 | };
|
---|
178 |
|
---|
179 | //-----------------------------------------------------------------------
|
---|
180 | /** Predefined controller function which simply scales an input to an output value.
|
---|
181 | */
|
---|
182 | class _OgreExport ScaleControllerFunction : public ControllerFunction<Real>
|
---|
183 | {
|
---|
184 | protected:
|
---|
185 | Real mScale;
|
---|
186 | public:
|
---|
187 | /** Constructor, requires a scale factor.
|
---|
188 | @param
|
---|
189 | scalefactor The multipier applied to the input to produce the output.
|
---|
190 | @param
|
---|
191 | deltaInput If true, signifies that the input will be a delta value such that the function should
|
---|
192 | add it to an internal counter before calculating the output.
|
---|
193 | */
|
---|
194 | ScaleControllerFunction(Real scalefactor, bool deltaInput);
|
---|
195 |
|
---|
196 | /** Overriden method.
|
---|
197 | */
|
---|
198 | Real calculate(Real source);
|
---|
199 |
|
---|
200 | };
|
---|
201 |
|
---|
202 | //-----------------------------------------------------------------------
|
---|
203 | /** Predefined controller function based on a waveform.
|
---|
204 | @remarks
|
---|
205 | A waveform function translates parametric intput to parametric output based on a wave. The factors
|
---|
206 | affecting the function are:
|
---|
207 | - wave type - the shape of the wave
|
---|
208 | - base - the base value of the output from the wave
|
---|
209 | - frequency - the speed of the wave in cycles per second
|
---|
210 | - phase - the offset of the start of the wave, e.g. 0.5 to start half-way through the wave
|
---|
211 | - amplitude - scales the output so that instead of lying within [0,1] it lies within [0,1] * amplitude
|
---|
212 | @par
|
---|
213 | Note that for simplicity of integration with the rest of the controller insfrastructure, the output of
|
---|
214 | the wave is parametric i.e. 0..1, rather than the typical wave output of [-1,1]. To compensate for this, the
|
---|
215 | traditional output of the wave is scaled by the following function before output:
|
---|
216 | @par
|
---|
217 | output = (waveoutput + 1) * 0.5
|
---|
218 | @par
|
---|
219 | Hence a wave output of -1 becomes 0, a wave ouput of 1 becomes 1, and a wave output of 0 becomes 0.5.
|
---|
220 | */
|
---|
221 | class _OgreExport WaveformControllerFunction : public ControllerFunction<Real>
|
---|
222 | {
|
---|
223 | protected:
|
---|
224 | WaveformType mWaveType;
|
---|
225 | Real mBase;
|
---|
226 | Real mFrequency;
|
---|
227 | Real mPhase;
|
---|
228 | Real mAmplitude;
|
---|
229 |
|
---|
230 | /** Overridden from ControllerFunction. */
|
---|
231 | Real getAdjustedInput(Real input);
|
---|
232 |
|
---|
233 | public:
|
---|
234 | /** Default contructor, requires at least a wave type, other parameters can be defaulted unless required.
|
---|
235 | @param
|
---|
236 | deltaInput If true, signifies that the input will be a delta value such that the function should
|
---|
237 | add it to an internal counter before calculating the output.
|
---|
238 | */
|
---|
239 | WaveformControllerFunction(WaveformType wType, Real base = 0, Real frequency = 1, Real phase = 0, Real amplitude = 1, bool deltaInput = true);
|
---|
240 |
|
---|
241 | /** Overriden function.
|
---|
242 | */
|
---|
243 | Real calculate(Real source);
|
---|
244 |
|
---|
245 | };
|
---|
246 | //-----------------------------------------------------------------------
|
---|
247 |
|
---|
248 | }
|
---|
249 |
|
---|
250 | #endif
|
---|