00001 /******************************************************************** 00002 Description: mouse plug-in 00003 part of the 3Dsia project 00004 created: StonedBones, 24.4.2000 00005 00006 History: 00007 date, name, changes, in funtion 00008 080500 StonedBones created source 00009 00010 ********************************************************************/ 00011 00012 00013 00014 #include "deviceMouse.h" 00015 00016 #include <string.h> 00017 #include <iostream> 00018 #include <iomanip> 00019 00020 bool isPresent; 00021 int intAxes; 00022 int intButtons; 00023 long intAxis[MAXAXES]; 00024 bool intButton[MAXBUTTONS]; 00025 string intName; 00026 int intX, intY; 00027 00028 /*................................................................... 00029 Description: returns the actual plugin 00030 Args: <none> 00031 Returns: plug-in pointer 00032 Created: StonedBones, 26.2.2000 00033 [ToDo:] 00034 [Comments:] 00035 Changes: 00036 -------------------------------------------------------------------*/ 00037 00038 extern "C" {DevicePlugIn* GetDevicePlugIn (void); }; 00039 00040 DevicePlugIn* GetDevicePlugIn () { 00041 return &inputPlugIn; 00042 }; 00043 00044 /*................................................................... 00045 Description: opens a joystick device 00046 Args: char* device: device-filename 00047 Returns: true on succes 00048 Created: StonedBones, 26.2.2000 00049 [ToDo:] 00050 [Comments:] 00051 Changes: 00052 -------------------------------------------------------------------*/ 00053 00054 bool openDevice () { 00055 intAxes =2; 00056 intButtons=3; 00057 intName ="glut-mouse"; 00058 isPresent =true; 00059 00060 for (int i=0; i < intAxes; i++) { 00061 intAxis[i]=0; 00062 }; 00063 for (int i=0; i < intButtons; i++) { 00064 intButton[i]=false; 00065 }; 00066 00067 glutMouseFunc (mouse); 00068 glutPassiveMotionFunc (motion); 00069 00070 update (); 00071 00072 return true; 00073 }; 00074 00075 /*................................................................... 00076 Description: closes device if open 00077 Args: <none> 00078 Returns: <none> 00079 Created: StonedBones, 26.2.2000 00080 [ToDo:] 00081 [Comments:] 00082 Changes: 00083 -------------------------------------------------------------------*/ 00084 00085 void closeDevice () { 00086 return; 00087 }; 00088 00089 /*................................................................... 00090 Description: updates axis(int nr) and buttonPressed (int nr) 00091 Args: <none> 00092 Returns: true on success 00093 Created: StonedBones, 26.2.2000 00094 [ToDo:] 00095 [Comments:] 00096 Changes: 00097 -------------------------------------------------------------------*/ 00098 00099 bool update () { 00100 if (isPresent) { 00101 int WindowHeight = glutGet ((GLenum)GLUT_WINDOW_HEIGHT); 00102 int WindowWidth = glutGet ((GLenum)GLUT_WINDOW_WIDTH); 00103 00104 intAxis[0]= ( ( WindowHeight / 2) - intY) * 100; 00105 intAxis[1]= ( ( WindowWidth / 2) - intX) * 100; 00106 00107 if ( intY > ( WindowHeight - 1 ) ) 00108 { 00109 intY = WindowHeight - 1; 00110 glutWarpPointer ( intX, intY ); 00111 } 00112 else if ( intY < 0 ) 00113 { 00114 intY = 1; 00115 glutWarpPointer ( intX, intY ); 00116 } 00117 00118 if ( intX > ( WindowWidth - 1 ) ) 00119 { 00120 intX = WindowWidth - 1; 00121 glutWarpPointer ( intX, intY ); 00122 } 00123 else if ( intX < 0 ) 00124 { 00125 intX = 1; 00126 glutWarpPointer ( intX, intY ); 00127 } 00128 00129 return true; 00130 } else return false; 00131 }; 00132 00133 /*................................................................... 00134 Description: returns the joystick name (given by kernel-module) 00135 Args: <none> 00136 Returns: NULL if no joystick was opened 00137 Created: StonedBones, 26.2.2000 00138 [ToDo:] 00139 [Comments:] 00140 Changes: 00141 -------------------------------------------------------------------*/ 00142 00143 string name () { 00144 if (isPresent) { 00145 return intName; 00146 } else return "none found"; 00147 }; 00148 00149 /*................................................................... 00150 Description: returns the amount of axes 00151 Args: <none> 00152 Returns: 0 if no joystick present 00153 Created: StonedBones, 26.2.2000 00154 [ToDo:] 00155 [Comments:] 00156 Changes: 00157 -------------------------------------------------------------------*/ 00158 00159 int axes () { 00160 if (isPresent) { 00161 return intAxes; 00162 } else return 0; 00163 }; 00164 00165 /*................................................................... 00166 Description: returns the amount of buttons 00167 Args: <none> 00168 Returns: 0 if no joystick present 00169 Created: StonedBones, 26.2.2000 00170 [ToDo:] 00171 [Comments:] 00172 Changes: 00173 -------------------------------------------------------------------*/ 00174 00175 int buttons () { 00176 if (isPresent) { 00177 return intButtons; 00178 } else return 0; 00179 }; 00180 00181 /*................................................................... 00182 Description: returns the value of axis 'nr' 00183 Args: int nr: axis-number 00184 Returns: axis-value 00185 Created: StonedBones, 26.2.2000 00186 [ToDo:] 00187 [Comments:] 00188 Changes: 00189 -------------------------------------------------------------------*/ 00190 00191 long axis (int nr) { 00192 if (isPresent) { 00193 if (nr < intAxes) { 00194 return (intAxis[nr]); 00195 } else { 00196 return 0; 00197 }; 00198 } else { 00199 return 0; 00200 }; 00201 }; 00202 00203 /*................................................................... 00204 Description: returns if a certain button is pressed 00205 Args: int nr: button-number 00206 Returns: true if pressed 00207 Created: StonedBones, 26.2.2000 00208 [ToDo:] 00209 [Comments:] 00210 Changes: 00211 -------------------------------------------------------------------*/ 00212 00213 bool buttonPressed (int nr) { 00214 if (isPresent) { 00215 if (nr < intButtons) { 00216 return intButton[nr]; 00217 } else { 00218 return false; 00219 }; 00220 } else { 00221 return false; 00222 }; 00223 }; 00224 00225 00226 void mouse (int button, int state, int x, int y) { 00227 if (state == GLUT_DOWN) { 00228 intButton[button]=true; 00229 } else { 00230 intButton[button]=false; 00231 }; 00232 }; 00233 00234 void motion (int x, int y) { 00235 intX = x; 00236 intY = y; 00237 }; 00238