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