Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/archive/tutorialHS08/src/ois/OISEffect.h @ 10255

Last change on this file since 10255 was 1505, checked in by rgrieder, 17 years ago

f* svn: It doesn't even inform you if you attempt to set a non existing property. It is svn:eol-style and not eol-style when using the command by the way…

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