00001 //------------------------------------------------------------------------------ 00002 // Lamp : Open source game middleware 00003 // Copyright (C) 2004 Junpei Ohtani ( Email : junpee@users.sourceforge.jp ) 00004 // 00005 // This library is free software; you can redistribute it and/or 00006 // modify it under the terms of the GNU Lesser General Public 00007 // License as published by the Free Software Foundation; either 00008 // version 2.1 of the License, or (at your option) any later version. 00009 // 00010 // This library is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 // Lesser General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU Lesser General Public 00016 // License along with this library; if not, write to the Free Software 00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00018 //------------------------------------------------------------------------------ 00019 00020 /** @file 00021 * PS2互換パッドヘッダ 00022 * @author Junpee 00023 */ 00024 00025 #ifndef PS2_PAD_H_ 00026 #define PS2_PAD_H_ 00027 00028 #include <Input/Pad/Pad.h> 00029 00030 namespace Lamp{ 00031 00032 //------------------------------------------------------------------------------ 00033 /** 00034 * PS2互換パッド 00035 * 00036 * 主にELECOM、LOASのPS2コントローラ変換ケーブルを使用した場合に対応している。 00037 * FFXI互換を謳っているUSBパッドはボタン並びが違っている模様。 00038 * SmartJoypadにも対応、Z軸、Z回転の扱いが逆になり、十字キーをボタンで認識している。 00039 */ 00040 class PS2Pad : public Pad{ 00041 public: 00042 /** 00043 * 互換性チェック 00044 * @param joystick 互換性をチェックするジョイスティック 00045 * @return 互換性があればtrueを返す 00046 */ 00047 static bool checkCompatibility(Joystick* joystick); 00048 00049 /// ボタン 00050 enum Button{ 00051 button0 = 0, 00052 button1, 00053 button2, 00054 button3, 00055 buttonL2, 00056 buttonR2, 00057 buttonL1, 00058 buttonR1, 00059 buttonStart, 00060 buttonSelect, 00061 buttonL3, 00062 buttonR3, 00063 buttonPOVUp, 00064 buttonPOVRight, 00065 buttonPOVDown, 00066 buttonPOVLeft, 00067 maxButtonCount, 00068 buttonUnknown = -1, 00069 buttonSankaku = 0, 00070 buttonMaru = 1, 00071 buttonBatu = 2, 00072 buttonSikaku = 3, 00073 }; 00074 00075 //-------------------------------------------------------------------------- 00076 // 生成、破棄 00077 //-------------------------------------------------------------------------- 00078 /** 00079 * コンストラクタ 00080 * @param joystick 使用するジョイスティック 00081 */ 00082 PS2Pad(Joystick* joystick); 00083 00084 /** 00085 * デストラクタ 00086 */ 00087 virtual ~PS2Pad(); 00088 00089 //-------------------------------------------------------------------------- 00090 // ボタンマップ 00091 //-------------------------------------------------------------------------- 00092 /** 00093 * ボタンマップの変更 00094 * @param button ボタンマップを変更するボタン 00095 * @param id 変更するボタンID 00096 */ 00097 virtual void changeButtonMap(Button button, int id); 00098 00099 /** 00100 * ボタンマップの取得 00101 * @param button ボタンマップを取得するボタン 00102 * @return ボタンID 00103 */ 00104 virtual int getButtonMap(const Button button){ 00105 Assert((button >= 0) && (button < maxButtonCount)); 00106 return buttonMap_[button]; 00107 } 00108 00109 //-------------------------------------------------------------------------- 00110 // 軸データの取得 00111 //-------------------------------------------------------------------------- 00112 /** 00113 * 左軸の取得 00114 * @return 左軸 00115 */ 00116 virtual Point2f getLeftAxis() const{ 00117 return Point2f(getLeftXAxis(), getLeftYAxis()); 00118 } 00119 00120 /** 00121 * 左X軸の取得 00122 * @return 左X軸 00123 */ 00124 virtual float getLeftXAxis() const; 00125 00126 /** 00127 * 左Y軸の取得 00128 * @return 左Y軸 00129 */ 00130 virtual float getLeftYAxis() const; 00131 00132 //-------------------------------------------------------------------------- 00133 /** 00134 * 右軸の取得 00135 * @return 右軸 00136 */ 00137 virtual Point2f getRightAxis() const{ 00138 return Point2f(getRightXAxis(), getRightYAxis()); 00139 } 00140 00141 /** 00142 * 右X軸の取得 00143 * @return 右X軸 00144 */ 00145 virtual float getRightXAxis() const; 00146 00147 /** 00148 * 右Y軸の取得 00149 * @return 右Y軸 00150 */ 00151 virtual float getRightYAxis() const; 00152 00153 //-------------------------------------------------------------------------- 00154 // 十字キーデータの取得 00155 //-------------------------------------------------------------------------- 00156 /** 00157 * 上キーが押されているか 00158 * @return 上キーが押されていればtrue 00159 */ 00160 virtual bool upKeyPressed() const; 00161 00162 /** 00163 * 上キーが下がった 00164 * @return 上キーが下がったならばtrue 00165 */ 00166 virtual bool upKeyDown() const; 00167 00168 /** 00169 * 上キーが上がった 00170 * @return 上キーが上がったならばtrue 00171 */ 00172 virtual bool upKeyUp() const; 00173 00174 //-------------------------------------------------------------------------- 00175 /** 00176 * 下キーが押されているか 00177 * @return 下キーが押されていればtrue 00178 */ 00179 virtual bool downKeyPressed() const; 00180 00181 /** 00182 * 下キーが下がった 00183 * @return 下キーが下がったならばtrue 00184 */ 00185 virtual bool downKeyDown() const; 00186 00187 /** 00188 * 下キーが上がった 00189 * @return 下キーが上がったならばtrue 00190 */ 00191 virtual bool downKeyUp() const; 00192 00193 //-------------------------------------------------------------------------- 00194 /** 00195 * 左キーが押されているか 00196 * @return 左キーが押されていればtrue 00197 */ 00198 virtual bool leftKeyPressed() const; 00199 00200 /** 00201 * 左キーが下がった 00202 * @return 左キーが下がったならばtrue 00203 */ 00204 virtual bool leftKeyDown() const; 00205 00206 /** 00207 * 左キーが上がった 00208 * @return 左キーが上がったならばtrue 00209 */ 00210 virtual bool leftKeyUp() const; 00211 00212 //-------------------------------------------------------------------------- 00213 /** 00214 * 右キーが押されているか 00215 * @return 右キーが押されていればtrue 00216 */ 00217 virtual bool rightKeyPressed() const; 00218 00219 /** 00220 * 右キーが下がった 00221 * @return 右キーが下がったならばtrue 00222 */ 00223 virtual bool rightKeyDown() const; 00224 00225 /** 00226 * 右キーが上がった 00227 * @return 右キーが上がったならばtrue 00228 */ 00229 virtual bool rightKeyUp() const; 00230 00231 //-------------------------------------------------------------------------- 00232 // ボタンデータの取得 00233 //-------------------------------------------------------------------------- 00234 /** 00235 * ボタンが押されているか 00236 * @param button ボタン 00237 * @return ボタンが押されていればtrue 00238 */ 00239 virtual bool buttonPressed(Button button) const; 00240 00241 /** 00242 * ボタンが下がった 00243 * @param button ボタン 00244 * @return ボタンが下がったならばtrue 00245 */ 00246 virtual bool buttonDown(Button button) const; 00247 00248 /** 00249 * ボタンが上がった 00250 * @param button ボタン 00251 * @return ボタンが上がったならばtrue 00252 */ 00253 virtual bool buttonUp(Button button) const; 00254 00255 //-------------------------------------------------------------------------- 00256 // 文字列データ取得 00257 //-------------------------------------------------------------------------- 00258 /** 00259 * ボタン文字列の取得 00260 * @param button ボタン 00261 * @return ボタン文字列 00262 */ 00263 static String getButtonString(Button button); 00264 00265 /** 00266 * 文字列への変換 00267 * @return 文字列 00268 */ 00269 virtual String toString() const; 00270 00271 protected: 00272 //-------------------------------------------------------------------------- 00273 /** 00274 * 視点コントローラ値から上キーへの変換 00275 * @param pov 視点コントローラ値 00276 * @return 上キーが押されていればtrue 00277 */ 00278 inline bool povToUpKey(int pov) const{ 00279 if(((pov & 0xffff) == 0xffff)){ return false; } 00280 return ((pov >= (deg45 * 7)) && (pov <= (deg45 * 8))) || 00281 ((pov >= 0) && (pov <= deg45)); 00282 } 00283 00284 /** 00285 * 視点コントローラ値から下キーへの変換 00286 * @param pov 視点コントローラ値 00287 * @return 下キーが押されていればtrue 00288 */ 00289 inline bool povToDownKey(int pov) const{ 00290 if(((pov & 0xffff) == 0xffff)){ return false; } 00291 return ((pov >= (deg45 * 3)) && (pov <= (deg45 * 5))); 00292 } 00293 00294 /** 00295 * 視点コントローラ値から左キーへの変換 00296 * @param pov 視点コントローラ値 00297 * @return 左キーが押されていればtrue 00298 */ 00299 inline bool povToLeftKey(int pov) const{ 00300 if(((pov & 0xffff) == 0xffff)){ return false; } 00301 return ((pov >= (deg45 * 5)) && (pov <= (deg45 * 7))); 00302 } 00303 00304 /** 00305 * 視点コントローラ値から右キーへの変換 00306 * @param pov 視点コントローラ値 00307 * @return 右キーが押されていればtrue 00308 */ 00309 inline bool povToRightKey(int pov) const{ 00310 if(((pov & 0xffff) == 0xffff)){ return false; } 00311 return ((pov >= (deg45)) && (pov <= (deg45 * 3))); 00312 } 00313 00314 //-------------------------------------------------------------------------- 00315 /// ボタンマップ 00316 int buttonMap_[maxButtonCount]; 00317 /// スマートジョイパッドフラグ 00318 bool isSmartJoypad_; 00319 00320 /// 視点コントローラにおける45度 00321 static const int deg45 = 4500; 00322 00323 private: 00324 00325 }; 00326 00327 //------------------------------------------------------------------------------ 00328 } // End of namespace Lamp 00329 #endif // End of PS2_PAD_H_ 00330 //------------------------------------------------------------------------------