00001 /* 00002 $Id: inputbutton_to_axis_analog.h,v 1.1 2001/03/06 15:09:10 mbn Exp $ 00003 00004 ------------------------------------------------------------------------ 00005 ClanLib, the platform independent game SDK. 00006 00007 This library is distributed under the GNU LIBRARY GENERAL PUBLIC LICENSE 00008 version 2. See COPYING for details. 00009 00010 For a total list of contributers see CREDITS. 00011 00012 ------------------------------------------------------------------------ 00013 */ 00014 00016 00017 #ifndef header_inputbutton_to_axis_analog 00018 #define header_inputbutton_to_axis_analog 00019 00020 #include "../Input/inputbutton.h" 00021 #include "../Input/inputaxis.h" 00022 00023 class CL_InputButtonToAxis_Analog : public CL_InputAxis 00024 //: Converts two CL_InputButton's into one analog CL_InputAxis. 00025 { 00026 CL_InputButton *left; 00027 CL_InputButton *right; 00028 float cur_pos; 00029 00030 public: 00031 CL_InputButtonToAxis_Analog(CL_InputButton *left, CL_InputButton *right) 00032 { 00033 this->left = left; 00034 this->right = right; 00035 cur_pos = 0; 00036 } 00037 //: Constructs a button to axis converter using the two buttons 'left' 00038 //: and 'right'. 00039 00040 virtual float get_pos() 00041 { 00042 if (left->is_pressed() && cur_pos>-0.1) cur_pos=(float)-0.1; 00043 else if (right->is_pressed() && cur_pos<0.1) cur_pos=(float)0.1; 00044 00045 if (left->is_pressed() || right->is_pressed()) cur_pos*=(float)1.2; 00046 else cur_pos*=(float)0.8; 00047 00048 if (cur_pos>1) cur_pos=1; 00049 else if (cur_pos<-1) cur_pos=-1; 00050 00051 return cur_pos; 00052 } 00053 //: Returns the axis position. 00055 }; 00056 00057 #endif
1.2.6 written by Dimitri van Heesch,
© 1997-2001