Orxonox  0.0.5 Codename: Arcturus
OISEffect.h
Go to the documentation of this file.
1 /*
2 The zlib/libpng License
3 
4 Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com)
5 
6 This software is provided 'as-is', without any express or implied warranty. In no event will
7 the authors be held liable for any damages arising from the use of this software.
8 
9 Permission is granted to anyone to use this software for any purpose, including commercial
10 applications, and to alter it and redistribute it freely, subject to the following
11 restrictions:
12 
13  1. The origin of this software must not be misrepresented; you must not claim that
14  you wrote the original software. If you use this software in a product,
15  an acknowledgment in the product documentation would be appreciated but is
16  not required.
17 
18  2. Altered source versions must be plainly marked as such, and must not be
19  misrepresented as being the original software.
20 
21  3. This notice may not be removed or altered from any source distribution.
22 */
23 #ifndef OIS_Effect_H
24 #define OIS_Effect_H
25 
26 #include "OISPrereqs.h"
27 
28 namespace OIS
29 {
30  //Predeclare some Effect Property structs
31  class ForceEffect;
32  class ConstantEffect;
33  class RampEffect;
34  class PeriodicEffect;
35  class ConditionalEffect;
36 
48  {
52  Effect();
53  public:
55  enum EForce
56  {
57  UnknownForce = 0,
63  _ForcesNumber // Always keep in last position.
64  };
65 
66  static const char* getForceTypeName(EForce eValue);
67 
69  enum EType
70  {
71  //Type ----- Pairs with force:
72  Unknown = 0, //UnknownForce
73  Constant, //ConstantForce
74  Ramp, //RampForce
75  Square, //PeriodicForce
76  Triangle, //PeriodicForce
77  Sine, //PeriodicForce
78  SawToothUp, //PeriodicForce
79  SawToothDown,//PeriodicForce
80  Friction, //ConditionalForce
81  Damper, //ConditionalForce
82  Inertia, //ConditionalForce
83  Spring, //ConditionalForce
84  Custom, //CustomForce
85  _TypesNumber // Always keep in last position.
86  };
87 
88  static const char* getEffectTypeName(EType eValue);
89 
92  {
101  _DirectionsNumber // Always keep in last position.
102  };
103 
104  static const char* getDirectionName(EDirection eValue);
105 
109  Effect(EForce ef, EType et);
110  virtual ~Effect();
111 
112  const EForce force;
113  const EType type;
114 
115  //Infinite Time
116  static const unsigned int OIS_INFINITE = 0xFFFFFFFF;
117 
118  //-------------------------------------------------------------------//
119  //--- Set these variables before uploading or modifying an effect ---//
120 
121  //Direction to apply to the force - affects two axes+ effects
123 
124  //Number of button triggering an effect (-1 means no trigger)
126 
127  //Time to wait before an effect can be re-triggered (microseconds)
128  unsigned int trigger_interval;
129 
130  //Duration of an effect (microseconds)
131  unsigned int replay_length;
132 
133  //Time to wait before to start playing an effect (microseconds)
134  unsigned int replay_delay;
135 
136  //Get the specific Force Effect. This should be cast depending on the EForce
137  ForceEffect* getForceEffect() const;
138 
145  void setNumAxes(short nAxes);
146 
151  short getNumAxes() const;
152 
153  //------------- Library Internal -------------------------------------//
159  mutable int _handle;
160  protected:
161  ForceEffect* effect; //Properties depend on EForce
162  short axes; //Number of axes to use in effect
163  };
164 
165  //-----------------------------------------------------------------------------//
170  {
171  public:
172  virtual ~ForceEffect() {}
173  };
174 
175  //-----------------------------------------------------------------------------//
182  {
183  public:
184  Envelope() : attackLength(0), attackLevel(0), fadeLength(0), fadeLevel(0) {}
185 #if defined(OIS_MSVC_COMPILER)
186  #pragma warning (push)
187  #pragma warning (disable : 4800)
188 #endif
189  bool isUsed() const { return attackLength | attackLevel | fadeLength | fadeLevel; }
190 #if defined(OIS_MSVC_COMPILER)
191  #pragma warning (pop)
192 #endif
193 
194  // Duration of the attack (microseconds)
195  unsigned int attackLength;
196 
197  // Absolute level at the beginning of the attack (0 to 10K)
198  // (automatically signed when necessary by FF core according to effect level sign)
199  unsigned short attackLevel;
200 
201  // Duration of fade (microseconds)
202  unsigned int fadeLength;
203 
204  // Absolute level at the end of fade (0 to 10K)
205  // (automatically signed when necessary by FF core according to effect level sign)
206  unsigned short fadeLevel;
207  };
208 
209  //-----------------------------------------------------------------------------//
214  {
215  public:
216  ConstantEffect() : level(5000) {}
217 
218  class Envelope envelope; //Optional envolope
219  signed short level; //-10K to +10k
220  };
221 
222  //-----------------------------------------------------------------------------//
227  {
228  public:
229  RampEffect() : startLevel(0), endLevel(0) {}
230 
231  class Envelope envelope; //Optional envelope
232  signed short startLevel; //-10K to +10k
233  signed short endLevel; //-10K to +10k
234  };
235 
236  //-----------------------------------------------------------------------------//
241  {
242  public:
243  PeriodicEffect() : magnitude(0), offset(0), phase(0), period(0) {}
244 
245  class Envelope envelope; //Optional Envelope
246 
247  unsigned short magnitude; //0 to 10,0000
248  signed short offset;
249  unsigned short phase; //Position at which playback begins 0 to 35,999
250  unsigned int period; //Period of effect (microseconds)
251  };
252 
253  //-----------------------------------------------------------------------------//
258  {
259  public:
261  rightCoeff(0), leftCoeff(0), rightSaturation(0), leftSaturation(0),
262  deadband(0), center(0) {}
263 
264  signed short rightCoeff; //-10k to +10k (Positive Coeff)
265  signed short leftCoeff; //-10k to +10k (Negative Coeff)
266 
267  unsigned short rightSaturation; //0 to 10k (Pos Saturation)
268  unsigned short leftSaturation; //0 to 10k (Neg Saturation)
269 
270  //Region around center in which the condition is not active, in the range
271  //from 0 through 10,000
272  unsigned short deadband;
273 
274  //(Offset in DX) -10k and 10k
275  signed short center;
276  };
277 }
278 #endif //OIS_Effect_H
Definition: OISEffect.h:76
EDirection
Direction of the Force.
Definition: OISEffect.h:91
Definition: OISEffect.h:78
Definition: OISEffect.h:81
EDirection direction
Definition: OISEffect.h:122
unsigned int attackLength
Definition: OISEffect.h:195
Envelope()
Definition: OISEffect.h:184
unsigned short magnitude
Definition: OISEffect.h:247
Definition: OISEffect.h:75
const EForce force
Definition: OISEffect.h:112
#define _OISExport
Definition: OISPrereqs.h:40
Definition: OISEffect.h:84
EType
Type of effect.
Definition: OISEffect.h:69
unsigned short rightSaturation
Definition: OISEffect.h:267
Definition: OISEffect.h:77
short trigger_button
Definition: OISEffect.h:125
unsigned short fadeLevel
Definition: OISEffect.h:206
Force Feedback is a relatively complex set of properties to upload to a device.
Definition: OISEffect.h:47
signed short level
Definition: OISEffect.h:219
unsigned int fadeLength
Definition: OISEffect.h:202
unsigned short leftSaturation
Definition: OISEffect.h:268
Base class of all effect property classes.
Definition: OISEffect.h:169
Use this class when dealing with Force type of Periodic.
Definition: OISEffect.h:240
unsigned short deadband
Definition: OISEffect.h:272
Definition: OISEffect.h:82
Definition: OISEffect.h:100
short axes
Definition: OISEffect.h:162
unsigned int replay_length
Definition: OISEffect.h:131
An optional envelope to be applied to the start/end of an effect.
Definition: OISEffect.h:181
const EType type
Definition: OISEffect.h:113
unsigned int trigger_interval
Definition: OISEffect.h:128
signed short startLevel
Definition: OISEffect.h:232
Definition: OISEffect.h:62
Definition: OISEffect.h:58
Use this class when dealing with Force type of Condional.
Definition: OISEffect.h:257
Definition: OISEffect.h:80
signed short center
Definition: OISEffect.h:275
Definition: OISEffect.h:79
unsigned short attackLevel
Definition: OISEffect.h:199
PeriodicEffect()
Definition: OISEffect.h:243
ConstantEffect()
Definition: OISEffect.h:216
signed short rightCoeff
Definition: OISEffect.h:264
Definition: OISEffect.h:93
EForce
Type of force.
Definition: OISEffect.h:55
Definition: OISEffect.h:61
Definition: OISEffect.h:99
Definition: OISEffect.h:95
Definition: OISEffect.h:94
Definition: OISEffect.h:74
unsigned int replay_delay
Definition: OISEffect.h:134
Use this class when dealing with Force type of Constant.
Definition: OISEffect.h:213
signed short endLevel
Definition: OISEffect.h:233
RampEffect()
Definition: OISEffect.h:229
Definition: OISEffect.h:96
unsigned short phase
Definition: OISEffect.h:249
Definition: OISEffect.h:73
Definition: OISEffect.h:97
ForceEffect * effect
Definition: OISEffect.h:161
int _handle
set internally.
Definition: OISEffect.h:159
bool isUsed() const
Definition: OISEffect.h:189
Definition: OISEffect.h:60
signed short offset
Definition: OISEffect.h:248
ConditionalEffect()
Definition: OISEffect.h:260
virtual ~ForceEffect()
Definition: OISEffect.h:172
Definition: OISEffect.h:59
Definition: OISEffect.h:98
Use this class when dealing with Force type of Ramp.
Definition: OISEffect.h:226
Definition: EventHelpers.h:31
signed short leftCoeff
Definition: OISEffect.h:265
Definition: OISEffect.h:83
unsigned int period
Definition: OISEffect.h:250