/src/ois/src/OISEffect.cpp

https://bitbucket.org/cabalistic/ogredeps/ · C++ · 128 lines · 78 code · 16 blank · 34 comment · 8 complexity · 242e432227dccdfc47d0f8691dce944d 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. #include "OISEffect.h"
  18. #include "OISException.h"
  19. using namespace OIS;
  20. //VC7.1 had a problem with these not getting included..
  21. //Perhaps a case of a crazy extreme optimizer :/ (moved to header)
  22. //const unsigned int Effect::OIS_INFINITE = 0xFFFFFFFF;
  23. //------------------------------------------------------------------------------//
  24. static const char* pszEForceString[] =
  25. { "UnknownForce",
  26. "ConstantForce",
  27. "RampForce",
  28. "PeriodicForce",
  29. "ConditionalForce",
  30. "CustomForce" };
  31. const char* Effect::getForceTypeName(Effect::EForce eValue)
  32. {
  33. return (eValue >= 0 && eValue < _ForcesNumber) ? pszEForceString[eValue] : "<Bad force type>";
  34. }
  35. static const char* pszETypeString[] =
  36. { "Unknown",
  37. "Constant",
  38. "Ramp",
  39. "Square", "Triangle", "Sine", "SawToothUp", "SawToothDown",
  40. "Friction", "Damper", "Inertia", "Spring",
  41. "Custom" };
  42. const char* Effect::getEffectTypeName(Effect::EType eValue)
  43. {
  44. return (eValue >= 0 && eValue < _TypesNumber) ? pszETypeString[eValue] : "<Bad effect type>";
  45. }
  46. static const char* pszEDirectionString[] =
  47. { "NorthWest", "North", "NorthEast", "East", "SouthEast", "South", "SouthWest", "West"};
  48. const char* Effect::getDirectionName(Effect::EDirection eValue)
  49. {
  50. return (eValue >= 0 && eValue < _DirectionsNumber) ? pszEDirectionString[eValue] : "<Bad direction>";
  51. }
  52. //------------------------------------------------------------------------------//
  53. Effect::Effect() :
  54. force(UnknownForce),
  55. type(Unknown),
  56. effect(0),
  57. axes(1)
  58. {
  59. }
  60. //------------------------------------------------------------------------------//
  61. Effect::Effect(EForce ef, EType et) :
  62. force(ef),
  63. type(et),
  64. direction(North),
  65. trigger_button(-1),
  66. trigger_interval(0),
  67. replay_length(Effect::OIS_INFINITE),
  68. replay_delay(0),
  69. _handle(-1),
  70. axes(1)
  71. {
  72. effect = 0;
  73. switch( ef )
  74. {
  75. case ConstantForce: effect = new ConstantEffect(); break;
  76. case RampForce: effect = new RampEffect(); break;
  77. case PeriodicForce: effect = new PeriodicEffect(); break;
  78. case ConditionalForce: effect = new ConditionalEffect(); break;
  79. default: break;
  80. }
  81. }
  82. //------------------------------------------------------------------------------//
  83. Effect::~Effect()
  84. {
  85. delete effect;
  86. }
  87. //------------------------------------------------------------------------------//
  88. ForceEffect* Effect::getForceEffect() const
  89. {
  90. //If no effect was created in constructor, then we raise an error here
  91. if( effect == 0 )
  92. OIS_EXCEPT( E_NotSupported, "Requested ForceEffect is null!" );
  93. return effect;
  94. }
  95. //------------------------------------------------------------------------------//
  96. void Effect::setNumAxes(short nAxes)
  97. {
  98. //Can only be set before a handle was assigned (effect created)
  99. if( _handle != -1 )
  100. axes = nAxes;
  101. }
  102. //------------------------------------------------------------------------------//
  103. short Effect::getNumAxes() const
  104. {
  105. return axes;
  106. }