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