Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

JoystickState.h

Go to the documentation of this file.
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  * ジョイスティックステートヘッダ
00022  * @author Junpee
00023  */
00024 
00025 #ifndef JOYSTICK_STATE_H_
00026 #define JOYSTICK_STATE_H_
00027 
00028 namespace Lamp{
00029 
00030 class BinaryWriter;
00031 class BinaryReader;
00032 
00033 //------------------------------------------------------------------------------
00034 /**
00035  * ジョイスティックステート
00036  */
00037 class JoystickState{
00038 public:
00039     /// 最大視点コントローラ数
00040     static const int maxPOVCount = 4;
00041 
00042     /// 最大スライダ数
00043     static const int maxSliderCount = 2;
00044 
00045     /// 最大ボタン数
00046     static const int maxButtonCount = 32;
00047 
00048     /// 軸データ最大値
00049     static const int maxAxisValue = 10000;
00050 
00051     /// 軸データ最小値
00052     static const int minAxisValue = -10000;
00053 
00054     /// 視点コントローラ最大値
00055     static const int maxPOVValue = 36000;
00056 
00057     //--------------------------------------------------------------------------
00058     /**
00059      * コンストラクタ
00060      */
00061     JoystickState(){ clear(); }
00062 
00063     /**
00064      * デストラクタ
00065      */
00066     virtual ~JoystickState(){}
00067 
00068     /**
00069      * クリア
00070      */
00071     virtual void clear(){
00072         xAxis_ = yAxis_ = zAxis_ = 0;
00073         xRotation_ = yRotation_ = zRotation_ = 0;
00074         for(int i = 0; i < maxPOVCount; i++){ povs_[i] = -1; }
00075         for(int i = 0; i < maxSliderCount; i++){ sliders_[i] = 0; }
00076         for(int i = 0; i < maxButtonCount; i++){ buttons_[i] = false; }
00077     }
00078 
00079     //--------------------------------------------------------------------------
00080     /**
00081      * X軸の設定
00082      * @param xAxis X軸
00083      */
00084     virtual void setXAxis(int xAxis){ xAxis_ = xAxis; }
00085 
00086     /**
00087      * X軸の取得
00088      * @return X軸
00089      */
00090     virtual int getXAxis() const{ return xAxis_; }
00091 
00092     /**
00093      * Y軸の設定
00094      * @param yAxis Y軸
00095      */
00096     virtual void setYAxis(int yAxis){ yAxis_ = yAxis; }
00097 
00098     /**
00099      * Y軸の取得
00100      * @return Y軸
00101      */
00102     virtual int getYAxis() const{ return yAxis_; }
00103 
00104     /**
00105      * Z軸の設定
00106      * @param zAxis Z軸
00107      */
00108     virtual void setZAxis(int zAxis){ zAxis_ = zAxis; }
00109 
00110     /**
00111      * Z軸の取得
00112      * @return Z軸
00113      */
00114     virtual int getZAxis() const{ return zAxis_; }
00115 
00116     //--------------------------------------------------------------------------
00117     /**
00118      * X回転の設定
00119      * @param xRotation X回転
00120      */
00121     virtual void setXRotation(int xRotation){ xRotation_ = xRotation; }
00122 
00123     /**
00124      * X回転の取得
00125      * @return X回転
00126      */
00127     virtual int getXRotation() const{ return xRotation_; }
00128 
00129     /**
00130      * Y回転の設定
00131      * @param yRotation Y回転
00132      */
00133     virtual void setYRotation(int yRotation){ yRotation_ = yRotation; }
00134 
00135     /**
00136      * Y回転の取得
00137      * @return Y回転
00138      */
00139     virtual int getYRotation() const{ return yRotation_; }
00140 
00141     /**
00142      * Z回転の設定
00143      * @param zRotation Z回転
00144      */
00145     virtual void setZRotation(int zRotation){ zRotation_ = zRotation; }
00146 
00147     /**
00148      * Z回転の取得
00149      * @return Z回転
00150      */
00151     virtual int getZRotation() const{ return zRotation_; }
00152 
00153     //--------------------------------------------------------------------------
00154     /**
00155      * 視点コントローラ値の設定
00156      * @param id 視点コントローラID
00157      * @param pov 視点コントローラ値
00158      */
00159     virtual void setPOV(int id, int pov){
00160         Assert((id >= 0) && (id < maxPOVCount));
00161         povs_[id] = pov;
00162     }
00163 
00164     /**
00165      * 視点コントローラ値の取得
00166      * @param id 視点コントローラID
00167      * @return 視点コントローラ値
00168      */
00169     virtual int getPOV(int id) const{
00170         Assert((id >= 0) && (id < maxPOVCount));
00171         return povs_[id];
00172     }
00173 
00174     //--------------------------------------------------------------------------
00175     /**
00176      * スライダ値の設定
00177      * @param id スライダID
00178      * @param slider スライダ値
00179      */
00180     virtual void setSlider(int id, int slider){
00181         Assert((id >= 0) && (id < maxSliderCount));
00182         sliders_[id] = slider;
00183     }
00184 
00185     /**
00186      * スライダ値の取得
00187      * @param id スライダID
00188      * @return スライダ値
00189      */
00190     virtual int getSlider(int id) const{
00191         Assert((id >= 0) && (id < maxSliderCount));
00192         return sliders_[id];
00193     }
00194 
00195     //--------------------------------------------------------------------------
00196     /**
00197      * ボタンの設定
00198      * @param id 対象ボタンID
00199      * @param pressed trueなら押されている
00200      */
00201     virtual void setButtonPressed(int id, bool pressed){
00202         Assert((id >= 0) && (id < maxButtonCount));
00203         buttons_[id] = pressed;
00204     }
00205 
00206     /**
00207      * ボタンが押されているか
00208      * @param id 対象ボタンID
00209      * @return ボタンが押されていればtrue
00210      */
00211     virtual bool buttonPressed(int id) const{
00212         Assert((id >= 0) && (id < maxButtonCount));
00213         return buttons_[id];
00214     }
00215 
00216     //--------------------------------------------------------------------------
00217     /**
00218      * 文字列への変換
00219      * @return 文字列
00220      */
00221     virtual String toString() const{
00222         String result;
00223         result.format("( XAxis = %4d , YAxis = %4d , ZAxis = %4d )\n"
00224             "( XRot = %4d , YRot = %4d , ZRot = %4d )\n"
00225             "POV %d %d %d %d\n"
00226             "Slider %d %d\n"
00227             "Buttons %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d "
00228             "%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d\n",
00229             getXAxis(), getYAxis(), getZAxis(),
00230             getXRotation(), getYRotation(), getZRotation(),
00231             getPOV(0),getPOV(1),getPOV(2),getPOV(3),
00232             getSlider(0), getSlider(1),
00233             buttonPressed(0), buttonPressed(1), buttonPressed(2),
00234             buttonPressed(3), buttonPressed(4), buttonPressed(5), 
00235             buttonPressed(6), buttonPressed(7),
00236             buttonPressed(8), buttonPressed(9), buttonPressed(10),
00237             buttonPressed(11), buttonPressed(12), buttonPressed(13), 
00238             buttonPressed(14), buttonPressed(15),
00239             buttonPressed(16), buttonPressed(17), buttonPressed(18),
00240             buttonPressed(19), buttonPressed(20), buttonPressed(21), 
00241             buttonPressed(22), buttonPressed(23),
00242             buttonPressed(24), buttonPressed(25), buttonPressed(26),
00243             buttonPressed(27), buttonPressed(28), buttonPressed(29), 
00244             buttonPressed(30), buttonPressed(31));
00245         return result;
00246     }
00247 
00248     //--------------------------------------------------------------------------
00249     /**
00250      * バイナリ書き出し
00251      * @param binaryWriter バイナリライタ
00252      */
00253     virtual void writeBinary(BinaryWriter* binaryWriter) const;
00254 
00255     /**
00256      * バイナリ読み込み
00257      * @param binaryReader バイナリリーダ
00258      */
00259     virtual void readBinary(BinaryReader* binaryReader);
00260 
00261     //--------------------------------------------------------------------------
00262 private:
00263     // X軸
00264     int xAxis_;
00265     // Y軸
00266     int yAxis_;
00267     // Z軸
00268     int zAxis_;
00269     // X回転
00270     int xRotation_;
00271     // Y回転
00272     int yRotation_;
00273     // Z回転
00274     int zRotation_;
00275     // 視点コントローラ
00276     int povs_[maxPOVCount];
00277     // スライダ
00278     int sliders_[maxSliderCount];
00279     // ボタンデータ
00280     bool buttons_[maxButtonCount];
00281 
00282 };
00283 
00284 //------------------------------------------------------------------------------
00285 } // End of namespace Lamp
00286 #endif // End of JOYSTICK_STATE_H_
00287 //------------------------------------------------------------------------------

Generated on Wed Mar 16 10:29:31 2005 for Lamp by doxygen 1.3.2