PageRenderTime 51ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/Ogre-1.9a/OgreMain/include/OgrePredefinedControllers.h

http://gamekit.googlecode.com/
C Header | 295 lines | 105 code | 30 blank | 160 comment | 0 complexity | 2f5aa0b042bdd49b8ba13c7b88eafa77 MD5 | raw file
Possible License(s): BSD-2-Clause, LGPL-2.0, AGPL-3.0, BSD-3-Clause, GPL-2.0, LGPL-3.0, MPL-2.0-no-copyleft-exception, LGPL-2.1, MIT
  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. Copyright (c) 2000-2012 Torus Knot Software Ltd
  7. Permission is hereby granted, free of charge, to any person obtaining a copy
  8. of this software and associated documentation files (the "Software"), to deal
  9. in the Software without restriction, including without limitation the rights
  10. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. copies of the Software, and to permit persons to whom the Software is
  12. furnished to do so, subject to the following conditions:
  13. The above copyright notice and this permission notice shall be included in
  14. all copies or substantial portions of the Software.
  15. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. THE SOFTWARE.
  22. -----------------------------------------------------------------------------
  23. */
  24. #ifndef __PredefinedControllers_H__
  25. #define __PredefinedControllers_H__
  26. #include "OgrePrerequisites.h"
  27. #include "OgreCommon.h"
  28. #include "OgreController.h"
  29. #include "OgreFrameListener.h"
  30. #include "OgreGpuProgram.h"
  31. #include "OgreHeaderPrefix.h"
  32. namespace Ogre {
  33. /** \addtogroup Core
  34. * @{
  35. */
  36. /** \addtogroup General
  37. * @{
  38. */
  39. //-----------------------------------------------------------------------
  40. // Controller Values
  41. //-----------------------------------------------------------------------
  42. /** Predefined controller value for getting the latest frame time.
  43. */
  44. class _OgreExport FrameTimeControllerValue : public ControllerValue<Real>, public FrameListener
  45. {
  46. protected:
  47. Real mFrameTime;
  48. Real mTimeFactor;
  49. Real mElapsedTime;
  50. Real mFrameDelay;
  51. public:
  52. FrameTimeControllerValue();
  53. bool frameEnded(const FrameEvent &evt);
  54. bool frameStarted(const FrameEvent &evt);
  55. Real getValue(void) const;
  56. void setValue(Real value);
  57. Real getTimeFactor(void) const;
  58. void setTimeFactor(Real tf);
  59. Real getFrameDelay(void) const;
  60. void setFrameDelay(Real fd);
  61. Real getElapsedTime(void) const;
  62. void setElapsedTime(Real elapsedTime);
  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. /** Gets the frame number as a parametric value in the range [0,1]
  74. */
  75. Real getValue(void) const;
  76. /** Sets the frame number as a parametric value in the range [0,1]; the actual frame number is value * (numFrames-1).
  77. */
  78. void setValue(Real value);
  79. };
  80. //-----------------------------------------------------------------------
  81. /** Predefined controller value for getting / setting a texture coordinate modifications (scales and translates).
  82. @remarks
  83. Effects can be applied to the scale or the offset of the u or v coordinates, or both. If separate
  84. modifications are required to u and v then 2 instances are required to control both independently, or 4
  85. if you ant separate u and v scales as well as separate u and v offsets.
  86. @par
  87. Because of the nature of this value, it can accept values outside the 0..1 parametric range.
  88. */
  89. class _OgreExport TexCoordModifierControllerValue : public ControllerValue<Real>
  90. {
  91. protected:
  92. bool mTransU, mTransV;
  93. bool mScaleU, mScaleV;
  94. bool mRotate;
  95. TextureUnitState* mTextureLayer;
  96. public:
  97. /** Constructor.
  98. @param
  99. t TextureUnitState to apply the modification to.
  100. @param
  101. translateU If true, the u coordinates will be translated by the modification.
  102. @param
  103. translateV If true, the v coordinates will be translated by the modification.
  104. @param
  105. scaleU If true, the u coordinates will be scaled by the modification.
  106. @param
  107. scaleV If true, the v coordinates will be scaled by the modification.
  108. @param
  109. rotate If true, the texture will be rotated by the modification.
  110. */
  111. TexCoordModifierControllerValue(TextureUnitState* t, bool translateU = false, bool translateV = false,
  112. bool scaleU = false, bool scaleV = false, bool rotate = false );
  113. Real getValue(void) const;
  114. void setValue(Real value);
  115. };
  116. //-----------------------------------------------------------------------
  117. /** Predefined controller value for setting a single floating-
  118. point value in a constant parameter of a vertex or fragment program.
  119. @remarks
  120. Any value is accepted, it is propagated into the 'x'
  121. component of the constant register identified by the index. If you
  122. need to use named parameters, retrieve the index from the param
  123. object before setting this controller up.
  124. @note
  125. Retrieving a value from the program parameters is not currently
  126. supported, therefore do not use this controller value as a source,
  127. only as a target.
  128. */
  129. class _OgreExport FloatGpuParameterControllerValue : public ControllerValue<Real>
  130. {
  131. protected:
  132. /// The parameters to access
  133. GpuProgramParametersSharedPtr mParams;
  134. /// The index of the parameter to e read or set
  135. size_t mParamIndex;
  136. public:
  137. /** Constructor.
  138. @param
  139. params The parameters object to access
  140. @param
  141. index The index of the parameter to be set
  142. */
  143. FloatGpuParameterControllerValue(GpuProgramParametersSharedPtr params,
  144. size_t index );
  145. ~FloatGpuParameterControllerValue() {}
  146. Real getValue(void) const;
  147. void setValue(Real value);
  148. };
  149. //-----------------------------------------------------------------------
  150. // Controller functions
  151. //-----------------------------------------------------------------------
  152. /** Predefined controller function which just passes through the original source
  153. directly to dest.
  154. */
  155. class _OgreExport PassthroughControllerFunction : public ControllerFunction<Real>
  156. {
  157. public:
  158. /** Constructor.
  159. @param
  160. sequenceTime The amount of time in seconds it takes to loop through the whole animation sequence.
  161. @param
  162. timeOffset The offset in seconds at which to start (default is start at 0)
  163. */
  164. PassthroughControllerFunction(bool deltaInput = false);
  165. /** Overriden function.
  166. */
  167. Real calculate(Real source);
  168. };
  169. /** Predefined controller function for dealing with animation.
  170. */
  171. class _OgreExport AnimationControllerFunction : public ControllerFunction<Real>
  172. {
  173. protected:
  174. Real mSeqTime;
  175. Real mTime;
  176. public:
  177. /** Constructor.
  178. @param
  179. sequenceTime The amount of time in seconds it takes to loop through the whole animation sequence.
  180. @param
  181. timeOffset The offset in seconds at which to start (default is start at 0)
  182. */
  183. AnimationControllerFunction(Real sequenceTime, Real timeOffset = 0.0f);
  184. /** Overridden function.
  185. */
  186. Real calculate(Real source);
  187. /** Set the time value manually. */
  188. void setTime(Real timeVal);
  189. /** Set the sequence duration value manually. */
  190. void setSequenceTime(Real seqVal);
  191. };
  192. //-----------------------------------------------------------------------
  193. /** Predefined controller function which simply scales an input to an output value.
  194. */
  195. class _OgreExport ScaleControllerFunction : public ControllerFunction<Real>
  196. {
  197. protected:
  198. Real mScale;
  199. public:
  200. /** Constructor, requires a scale factor.
  201. @param
  202. scalefactor The multiplier applied to the input to produce the output.
  203. @param
  204. deltaInput If true, signifies that the input will be a delta value such that the function should
  205. add it to an internal counter before calculating the output.
  206. */
  207. ScaleControllerFunction(Real scalefactor, bool deltaInput);
  208. /** Overridden method.
  209. */
  210. Real calculate(Real source);
  211. };
  212. //-----------------------------------------------------------------------
  213. /** Predefined controller function based on a waveform.
  214. @remarks
  215. A waveform function translates parametric input to parametric output based on a wave. The factors
  216. affecting the function are:
  217. - wave type - the shape of the wave
  218. - base - the base value of the output from the wave
  219. - frequency - the speed of the wave in cycles per second
  220. - phase - the offset of the start of the wave, e.g. 0.5 to start half-way through the wave
  221. - amplitude - scales the output so that instead of lying within [0,1] it lies within [0,1] * amplitude
  222. - duty cycle - the active width of a PWM signal
  223. @par
  224. Note that for simplicity of integration with the rest of the controller insfrastructure, the output of
  225. the wave is parametric i.e. 0..1, rather than the typical wave output of [-1,1]. To compensate for this, the
  226. traditional output of the wave is scaled by the following function before output:
  227. @par
  228. output = (waveoutput + 1) * 0.5
  229. @par
  230. Hence a wave output of -1 becomes 0, a wave ouput of 1 becomes 1, and a wave output of 0 becomes 0.5.
  231. */
  232. class _OgreExport WaveformControllerFunction : public ControllerFunction<Real>
  233. {
  234. protected:
  235. WaveformType mWaveType;
  236. Real mBase;
  237. Real mFrequency;
  238. Real mPhase;
  239. Real mAmplitude;
  240. Real mDutyCycle;
  241. /** Overridden from ControllerFunction. */
  242. Real getAdjustedInput(Real input);
  243. public:
  244. /** Default constructor, requires at least a wave type, other parameters can be defaulted unless required.
  245. @param
  246. deltaInput If true, signifies that the input will be a delta value such that the function should
  247. add it to an internal counter before calculating the output.
  248. @param
  249. dutyCycle Used in PWM mode to specify the pulse width.
  250. */
  251. WaveformControllerFunction(WaveformType wType, Real base = 0, Real frequency = 1, Real phase = 0, Real amplitude = 1, bool deltaInput = true, Real dutyCycle = 0.5);
  252. /** Overridden function.
  253. */
  254. Real calculate(Real source);
  255. };
  256. //-----------------------------------------------------------------------
  257. /** @} */
  258. /** @} */
  259. }
  260. #include "OgreHeaderSuffix.h"
  261. #endif