/src/ois/includes/OISEffect.h

https://bitbucket.org/cabalistic/ogredeps/ · C Header · 278 lines · 136 code · 39 blank · 103 comment · 0 complexity · 3ed1b998fd6ad1ebade6dd51c0c96f26 MD5 · raw file

  1. /*
  2. The zlib/libpng License
  3. Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com)
  4. This software is provided 'as-is', without any express or implied warranty. In no event will
  5. the authors be held liable for any damages arising from the use of this software.
  6. Permission is granted to anyone to use this software for any purpose, including commercial
  7. applications, and to alter it and redistribute it freely, subject to the following
  8. restrictions:
  9. 1. The origin of this software must not be misrepresented; you must not claim that
  10. you wrote the original software. If you use this software in a product,
  11. an acknowledgment in the product documentation would be appreciated but is
  12. not required.
  13. 2. Altered source versions must be plainly marked as such, and must not be
  14. misrepresented as being the original software.
  15. 3. This notice may not be removed or altered from any source distribution.
  16. */
  17. #ifndef OIS_Effect_H
  18. #define OIS_Effect_H
  19. #include "OISPrereqs.h"
  20. namespace OIS
  21. {
  22. //Predeclare some Effect Property structs
  23. class ForceEffect;
  24. class ConstantEffect;
  25. class RampEffect;
  26. class PeriodicEffect;
  27. class ConditionalEffect;
  28. /**
  29. Force Feedback is a relatively complex set of properties to upload to a device.
  30. The best place for information on the different properties, effects, etc is in
  31. the DX Documentation and MSDN - there are even pretty graphs ther =)
  32. As this class is modeled on the the DX interface you can apply that same
  33. knowledge to creating effects via this class on any OS supported by OIS.
  34. In anycase, this is the main class you will be using. There is *absolutely* no
  35. need to instance any of the supporting ForceEffect classes yourself.
  36. */
  37. class _OISExport Effect
  38. {
  39. /**
  40. hidden so this class cannot be instanced with default constructor
  41. */
  42. Effect();
  43. public:
  44. //! Type of force
  45. enum EForce
  46. {
  47. UnknownForce = 0,
  48. ConstantForce,
  49. RampForce,
  50. PeriodicForce,
  51. ConditionalForce,
  52. CustomForce,
  53. _ForcesNumber // Always keep in last position.
  54. };
  55. static const char* getForceTypeName(EForce eValue);
  56. //! Type of effect
  57. enum EType
  58. {
  59. //Type ----- Pairs with force:
  60. Unknown = 0, //UnknownForce
  61. Constant, //ConstantForce
  62. Ramp, //RampForce
  63. Square, //PeriodicForce
  64. Triangle, //PeriodicForce
  65. Sine, //PeriodicForce
  66. SawToothUp, //PeriodicForce
  67. SawToothDown,//PeriodicForce
  68. Friction, //ConditionalForce
  69. Damper, //ConditionalForce
  70. Inertia, //ConditionalForce
  71. Spring, //ConditionalForce
  72. Custom, //CustomForce
  73. _TypesNumber // Always keep in last position.
  74. };
  75. static const char* getEffectTypeName(EType eValue);
  76. //! Direction of the Force
  77. enum EDirection
  78. {
  79. NorthWest,
  80. North,
  81. NorthEast,
  82. East,
  83. SouthEast,
  84. South,
  85. SouthWest,
  86. West,
  87. _DirectionsNumber // Always keep in last position.
  88. };
  89. static const char* getDirectionName(EDirection eValue);
  90. /**
  91. This constructor allows you to set the force type and effect.
  92. */
  93. Effect(EForce ef, EType et);
  94. virtual ~Effect();
  95. const EForce force;
  96. const EType type;
  97. //Infinite Time
  98. static const unsigned int OIS_INFINITE = 0xFFFFFFFF;
  99. //-------------------------------------------------------------------//
  100. //--- Set these variables before uploading or modifying an effect ---//
  101. //Direction to apply to the force - affects two axes+ effects
  102. EDirection direction;
  103. //Number of button triggering an effect (-1 means no trigger)
  104. short trigger_button;
  105. //Time to wait before an effect can be re-triggered (microseconds)
  106. unsigned int trigger_interval;
  107. //Duration of an effect (microseconds)
  108. unsigned int replay_length;
  109. //Time to wait before to start playing an effect (microseconds)
  110. unsigned int replay_delay;
  111. //Get the specific Force Effect. This should be cast depending on the EForce
  112. ForceEffect* getForceEffect() const;
  113. /**
  114. @remarks
  115. Set the number of Axes to use before the initial creation of the effect.
  116. Can only be done prior to creation! Use the FF interface to determine
  117. how many axes can be used (are availiable)
  118. */
  119. void setNumAxes(short nAxes);
  120. /**
  121. @remarks
  122. Returns the number of axes used in this effect
  123. */
  124. short getNumAxes() const;
  125. //------------- Library Internal -------------------------------------//
  126. /**
  127. set internally.. do not change or you will not be able to upload/stop
  128. this effect any more. It will become lost. It is mutable so even
  129. with const reference it can/will be changed by this lib
  130. */
  131. mutable int _handle;
  132. protected:
  133. ForceEffect* effect; //Properties depend on EForce
  134. short axes; //Number of axes to use in effect
  135. };
  136. //-----------------------------------------------------------------------------//
  137. /**
  138. Base class of all effect property classes
  139. */
  140. class _OISExport ForceEffect
  141. {
  142. public:
  143. virtual ~ForceEffect() {}
  144. };
  145. //-----------------------------------------------------------------------------//
  146. /**
  147. An optional envelope to be applied to the start/end of an effect. If any of
  148. these values are nonzero, then the envelope will be used in setting up the
  149. effect.
  150. */
  151. class _OISExport Envelope : public ForceEffect
  152. {
  153. public:
  154. Envelope() : attackLength(0), attackLevel(0), fadeLength(0), fadeLevel(0) {}
  155. #if defined(OIS_MSVC_COMPILER)
  156. #pragma warning (push)
  157. #pragma warning (disable : 4800)
  158. #endif
  159. bool isUsed() const { return attackLength | attackLevel | fadeLength | fadeLevel; }
  160. #if defined(OIS_MSVC_COMPILER)
  161. #pragma warning (pop)
  162. #endif
  163. // Duration of the attack (microseconds)
  164. unsigned int attackLength;
  165. // Absolute level at the beginning of the attack (0 to 10K)
  166. // (automatically signed when necessary by FF core according to effect level sign)
  167. unsigned short attackLevel;
  168. // Duration of fade (microseconds)
  169. unsigned int fadeLength;
  170. // Absolute level at the end of fade (0 to 10K)
  171. // (automatically signed when necessary by FF core according to effect level sign)
  172. unsigned short fadeLevel;
  173. };
  174. //-----------------------------------------------------------------------------//
  175. /**
  176. Use this class when dealing with Force type of Constant
  177. */
  178. class _OISExport ConstantEffect : public ForceEffect
  179. {
  180. public:
  181. ConstantEffect() : level(5000) {}
  182. class Envelope envelope; //Optional envolope
  183. signed short level; //-10K to +10k
  184. };
  185. //-----------------------------------------------------------------------------//
  186. /**
  187. Use this class when dealing with Force type of Ramp
  188. */
  189. class _OISExport RampEffect : public ForceEffect
  190. {
  191. public:
  192. RampEffect() : startLevel(0), endLevel(0) {}
  193. class Envelope envelope; //Optional envelope
  194. signed short startLevel; //-10K to +10k
  195. signed short endLevel; //-10K to +10k
  196. };
  197. //-----------------------------------------------------------------------------//
  198. /**
  199. Use this class when dealing with Force type of Periodic
  200. */
  201. class _OISExport PeriodicEffect : public ForceEffect
  202. {
  203. public:
  204. PeriodicEffect() : magnitude(0), offset(0), phase(0), period(0) {}
  205. class Envelope envelope; //Optional Envelope
  206. unsigned short magnitude; //0 to 10,0000
  207. signed short offset;
  208. unsigned short phase; //Position at which playback begins 0 to 35,999
  209. unsigned int period; //Period of effect (microseconds)
  210. };
  211. //-----------------------------------------------------------------------------//
  212. /**
  213. Use this class when dealing with Force type of Condional
  214. */
  215. class _OISExport ConditionalEffect : public ForceEffect
  216. {
  217. public:
  218. ConditionalEffect() :
  219. rightCoeff(0), leftCoeff(0), rightSaturation(0), leftSaturation(0),
  220. deadband(0), center(0) {}
  221. signed short rightCoeff; //-10k to +10k (Positive Coeff)
  222. signed short leftCoeff; //-10k to +10k (Negative Coeff)
  223. unsigned short rightSaturation; //0 to 10k (Pos Saturation)
  224. unsigned short leftSaturation; //0 to 10k (Neg Saturation)
  225. //Region around center in which the condition is not active, in the range
  226. //from 0 through 10,000
  227. unsigned short deadband;
  228. //(Offset in DX) -10k and 10k
  229. signed short center;
  230. };
  231. }
  232. #endif //OIS_Effect_H