00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "ArExport.h"
00028 #include "ariaOSDef.h"
00029 #include "ArJoyHandler.h"
00030 #include "ariaUtil.h"
00031
00040 ArJoyHandler::ArJoyHandler(bool useOSCal, bool useOld)
00041 {
00042 myInitialized = false;
00043 myUseOSCal = useOSCal;
00044 myUseOld = useOld;
00045 myHaveZ = false;
00046 myFirstData = true;
00047 }
00048
00049 ArJoyHandler::~ArJoyHandler()
00050 {
00051 }
00052
00053
00060 void ArJoyHandler::setUseOSCal(bool useOSCal)
00061 {
00062 myUseOSCal = useOSCal;
00063 }
00064
00071 bool ArJoyHandler::getUseOSCal(void)
00072 {
00073 return myUseOSCal;
00074 }
00075
00080 void ArJoyHandler::startCal(void)
00081 {
00082 int x, y;
00083 getUnfiltered(&x, &y);
00084 myMaxX = x;
00085 myMinX = x;
00086 myMaxY = y;
00087 myMinY = y;
00088 myCenX = x;
00089 myCenY = y;
00090 }
00091
00099 void ArJoyHandler::endCal(void)
00100 {
00101 int x, y;
00102
00103 getUnfiltered(&x, &y);
00104 myCenX = x;
00105 myCenY = y;
00106 }
00107
00108 void ArJoyHandler::getStats(int *maxX, int *minX, int *maxY,
00109 int *minY, int *cenX, int *cenY)
00110 {
00111 *maxX = myMaxX;
00112 *minX = myMinX;
00113 *maxY = myMaxY;
00114 *minY = myMinY;
00115 *cenX = myCenX;
00116 *cenY = myCenY;
00117 }
00118
00119 void ArJoyHandler::setStats(int maxX, int minX, int maxY, int minY,
00120 int cenX, int cenY)
00121 {
00122 myMaxX = maxX;
00123 myMinX = minX;
00124 myMaxY = maxY;
00125 myMinY = minY;
00126 myCenX = cenX;
00127 myCenY = cenY;
00128 }
00129
00130 void ArJoyHandler::getSpeeds(int *x, int *y, int *z)
00131 {
00132 *x = myTopX;
00133 *y = myTopY;
00134 if (z != NULL)
00135 *z = myTopZ;
00136 }
00137
00151 void ArJoyHandler::getAdjusted(int *x, int *y, int *z)
00152 {
00153 int curX, curY, curZ;
00154
00155 getUnfiltered(&curX, &curY, &curZ);
00156 if (myUseOSCal)
00157 {
00158 *x = ArMath::roundInt(((double)curX) / 128.0 * ((double)myTopX));
00159 *y = ArMath::roundInt(((double)curY) / 128.0 * ((double)myTopY));
00160 if (z != NULL)
00161 *z = ArMath::roundInt(((double)curZ) / 128.0 * ((double)myTopZ));
00162 return;
00163 }
00164
00165 if (curX > myCenX && myMaxX - myCenX != 0 ) {
00166 *x = (int)((double)(curX - myCenX)/(double)(myMaxX - myCenX)*
00167 (double)myTopX);
00168 } else if (curX <= myCenX && myCenX - myMinX != 0) {
00169 *x = (int)((double)(myCenX - curX)/(double)(myCenX - myMinX)*
00170 (double)-myTopX);
00171 } else
00172 *x = 0;
00173 if (curY > myCenY && myMaxY - myCenY != 0) {
00174 *y = (int)((double)(curY - myCenY)/(double)(myMaxY - myCenY)*
00175 (double)myTopY);
00176 } else if (curY <= myCenY && myCenY - myMinY != 0) {
00177 *y = (int)((double)(myCenY - curY)/(double)(myCenY - myMinY)*
00178 (double)-myTopY);
00179 } else
00180 *y = 0;
00181 if (z != NULL)
00182 *z = ArMath::roundInt(((double)curZ) / 128.0 * ((double)myTopZ));
00183
00184 }
00185
00201 void ArJoyHandler::getDoubles(double *x, double *y, double *z)
00202 {
00203 int curX, curY, curZ;
00204
00205 getUnfiltered(&curX, &curY, &curZ);
00206 if (myUseOSCal)
00207 {
00208 *x = ((double)curX) / 128.0;
00209 *y = ((double)curY) / 128.0;
00210 if (z != NULL)
00211 *z = ((double)curZ) / 128.0;
00212 return;
00213 }
00214
00215 if (curX > myCenX && myMaxX - myCenX != 0 ) {
00216 *x = (int)((double)(curX - myCenX)/(double)(myMaxX - myCenX));
00217 } else if (curX <= myCenX && myCenX - myMinX != 0) {
00218 *x = (int)((double)(myCenX - curX)/(double)(myCenX - myMinX));
00219 } else
00220 *x = 0;
00221 if (curY > myCenY && myMaxY - myCenY != 0) {
00222 *y = (int)((double)(curY - myCenY)/(double)(myMaxY - myCenY));
00223 } else if (curY <= myCenY && myCenY - myMinY != 0) {
00224 *y = (int)((double)(myCenY - curY)/(double)(myCenY - myMinY));
00225 } else
00226 *y = 0;
00227 if (z != NULL)
00228 *z = curZ;
00229 }
00230
00243 void ArJoyHandler::getUnfiltered(int *x, int* y, int *z)
00244 {
00245 getData();
00246 *x = myAxes[1];
00247 *y = myAxes[2];
00248 if (z != NULL)
00249 *z = myAxes[3];
00250 }
00251
00258 double ArJoyHandler::getAxis(unsigned int axis)
00259 {
00260
00261 if (axis < 1 || axis > myAxes.size())
00262 return 0;
00263
00264
00265 if (myAxes.find(axis) == myAxes.end())
00266 return 0;
00267
00268 return myAxes[axis]/128.0;
00269 }
00270
00278 bool ArJoyHandler::getButton(unsigned int button)
00279 {
00280 getData();
00281
00282 if (button < 1 || button > myButtons.size())
00283 return 0;
00284
00285
00286 if (myButtons.find(button) == myButtons.end())
00287 return 0;
00288
00289 return myButtons[button];
00290 }
00291
00296 unsigned int ArJoyHandler::getNumAxes(void)
00297 {
00298 return myAxes.size();
00299 }
00300
00305 unsigned int ArJoyHandler::getNumButtons(void)
00306 {
00307 return myButtons.size();
00308 }
00309