Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 #ifndef __SP_XBOX360_GAMEPAD_H__
00009 #define __SP_XBOX360_GAMEPAD_H__
00010 
00011 
00012 #include "Base/spStandard.hpp"
00013 
00014 #ifdef SP_COMPILE_WITH_XBOX360GAMEPAD
00015 
00016 
00017 #include "Base/spInputOutputString.hpp"
00018 #include "Base/spDimensionPoint2D.hpp"
00019 #include "Base/spInputKeyCodes.hpp"
00020 
00021 #include <boost/function.hpp>
00022 
00023 
00024 namespace sp
00025 {
00026 namespace io
00027 {
00028 
00029 
00030 static const u32 MAX_XBOX_CONTROLLERS = 4;
00031 
00032 class XBox360GamePad;
00033 
00035 typedef boost::shared_ptr<XBox360GamePad> XBox360GamePadPtr;
00036 
00038 typedef boost::function<void (const XBox360GamePad &Controller)> XBoxGamePadConnectCallback;
00039 
00040 
00041 static const u16 MAX_GAMEPAD_VIRBATION  = 65535;
00042 static const s32 XBOX_JOYSTICK_MIN      = 32768;
00043 static const s32 XBOX_JOYSTICK_MAX      = 32767;
00044 
00045 
00050 class SP_EXPORT XBox360GamePad
00051 {
00052     
00053     public:
00054         
00056         XBox360GamePad(s32 Number);
00057         ~XBox360GamePad();
00058         
00059         
00060         
00062         bool buttonHit(const EGamePadButtons Button) const;
00064         bool buttonDown(const EGamePadButtons Button) const;
00066         bool buttonReleased(const EGamePadButtons Button) const;
00067         
00069         u8 getLeftTrigger() const;
00071         u8 getRightTrigger() const;
00072         
00079         dim::point2df getLeftJoystick(f32 Threshold = 0.15f) const;
00084         dim::point2df getRightJoystick(f32 Threshold = 0.15f) const;
00085         
00087         dim::point2di getLeftJoystickNative() const;
00089         dim::point2di getRightJoystickNative() const;
00090         
00092         void setVibration(u16 MotorSpeed);
00094         void setVibration(u16 LeftMotorSpeed, u16 RightMotorSpeed);
00095         
00100         void setLeftVibration(u16 MotorSpeed);
00105         void setRightVibration(u16 MotorSpeed);
00106         
00112         void setLeftVibration(u16 MotorSpeed, u64 Duration);
00117         void setRightVibration(u16 MotorSpeed, u64 Duration);
00118         
00119         
00120         
00125         inline bool connected() const
00126         {
00127             return Connected_;
00128         }
00130         inline s32 getNumber() const
00131         {
00132             return Number_;
00133         }
00134         
00136         inline void setConnectCallback(const XBoxGamePadConnectCallback &Callback)
00137         {
00138             ConnectCallback_ = Callback;
00139         }
00140         
00141     private:
00142         
00143         friend class InputControl;
00144         
00145         
00146         
00147         void updateState();
00148         void clearButtonStates();
00149         void updateButtonStates();
00150         
00151         
00152         
00153         s32 Number_;
00154         bool Connected_;
00155         
00156         XBoxGamePadConnectCallback ConnectCallback_;
00157         
00158         u64 VibrationDuration_[2];
00159         
00160         bool ButtonHitSet_[GAMEPAD_BUTTON_COUNT];
00161         bool ButtonWasHitSet_[GAMEPAD_BUTTON_COUNT];
00162         bool ButtonReleasedSet_[GAMEPAD_BUTTON_COUNT];
00163         
00164 };
00165 
00166 
00167 } 
00168 
00169 } 
00170 
00171 
00172 #endif
00173 
00174 #endif
00175 
00176 
00177 
00178