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

Joystick.cpp

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 #include "LampBasic.h"
00026 #include "Input/Joystick/Joystick.h"
00027 
00028 namespace Lamp{
00029 
00030 //------------------------------------------------------------------------------
00031 // コンストラクタ
00032 Joystick::Joystick(JoystickDevice* device) : device_(device){
00033 }
00034 //------------------------------------------------------------------------------
00035 // デストラクタ
00036 Joystick::~Joystick(){
00037 }
00038 //------------------------------------------------------------------------------
00039 // 次のステート設定
00040 void Joystick::setNextState(const JoystickState& state){
00041     preState_ = state_;
00042     state_ = state;
00043 }
00044 //------------------------------------------------------------------------------
00045 // 文字列への変換
00046 String Joystick::toString() const{
00047     String result, temp;
00048     result = getName();
00049     result += " (";
00050     if(isAttached()){ result += " Attached"; }
00051     if(isPolled()){ result += " NeedPolling"; }
00052     result += " )\n";
00053     // 軸
00054     temp.format("Axes %d ( Slider %d )\n", getAxisCount(), getSliderCount());
00055     result += temp;
00056     if(hasXAxis()){
00057         temp.format(" XAxis %.3f\n", getXAxis());
00058         result += temp;
00059     }
00060     if(hasYAxis()){
00061         temp.format(" YAxis %.3f\n", getYAxis());
00062         result += temp;
00063     }
00064     if(hasZAxis()){
00065         temp.format(" ZAxis %.3f\n", getZAxis());
00066         result += temp;
00067     }
00068     if(hasXRotation()){
00069         temp.format(" XRotation %.3f\n", getXRotation());
00070         result += temp;
00071     }
00072     if(hasYRotation()){
00073         temp.format(" YRotation %.3f\n", getYRotation());
00074         result += temp;
00075     }
00076     if(hasZRotation()){
00077         temp.format(" ZRotation %.3f\n", getZRotation());
00078         result += temp;
00079     }
00080     int sliderCount = getSliderCount();
00081     for(int i = 0; i < sliderCount; i++){
00082         temp.format(" Slider%d %.3f\n", i, getSlider(i)); 
00083         result += temp;
00084     }
00085 
00086     // POV
00087     int povCount = getPOVCount();
00088     temp.format("POVs %d", povCount);
00089     result += temp;
00090     if(povCount != 0){
00091         result += " (";
00092         for(int i = 0; i < povCount; i++){
00093             if(isPOVCenter(i)){
00094                 result += "     C";
00095             }else{
00096                 temp.format(" %5d", getPOV(i));
00097                 result += temp;
00098             }
00099         }
00100         result += " )";
00101     }
00102     result += "\n";
00103 
00104     // ボタン
00105     int buttonCount = getButtonCount();
00106     temp.format("Buttons %d\n", getButtonCount());
00107     result += temp;
00108     result += " Press";
00109     for(int i = 0; i < buttonCount; i++){
00110         if(buttonPressed(i)){ result += " O"; }
00111         else{ result += " X"; }
00112     }
00113     result += "\n";
00114     result += " Down ";
00115     for(int i = 0; i < buttonCount; i++){
00116         if(buttonDown(i)){ result += " O"; }
00117         else{ result += " X"; }
00118     }
00119     result += "\n";
00120     result += " Up   ";
00121     for(int i = 0; i < buttonCount; i++){
00122         if(buttonUp(i)){ result += " O"; }
00123         else{ result += " X"; }
00124     }
00125     result += "\n";
00126     return result;
00127 }
00128 
00129 //------------------------------------------------------------------------------
00130 } // End of namespace Lamp
00131 //------------------------------------------------------------------------------

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