+\r
+void fgPlatformJoystickRawRead( SFG_Joystick* joy, int* buttons, float* axes )\r
+{\r
+ MMRESULT status;\r
+\r
+ status = joyGetPosEx( joy->pJoystick.js_id, &joy->pJoystick.js );\r
+\r
+ if ( status != JOYERR_NOERROR )\r
+ {\r
+ joy->error = GL_TRUE;\r
+ return;\r
+ }\r
+\r
+ if ( buttons )\r
+ *buttons = joy->pJoystick.js.dwButtons;\r
+\r
+ if ( axes )\r
+ {\r
+ /*\r
+ * WARNING - Fall through case clauses!!\r
+ */\r
+ switch ( joy->num_axes )\r
+ {\r
+ case 8:\r
+ /* Generate two POV axes from the POV hat angle.\r
+ * Low 16 bits of js.dwPOV gives heading (clockwise from ahead) in\r
+ * hundredths of a degree, or 0xFFFF when idle.\r
+ */\r
+ if ( ( joy->pJoystick.js.dwPOV & 0xFFFF ) == 0xFFFF )\r
+ {\r
+ axes [ 6 ] = 0.0;\r
+ axes [ 7 ] = 0.0;\r
+ }\r
+ else\r
+ {\r
+ /* This is the contentious bit: how to convert angle to X/Y.\r
+ * wk: I know of no define for PI that we could use here:\r
+ * SG_PI would pull in sg, M_PI is undefined for MSVC\r
+ * But the accuracy of the value of PI is very unimportant at\r
+ * this point.\r
+ */\r
+ float s = (float) sin ( ( joy->pJoystick.js.dwPOV & 0xFFFF ) * ( 0.01 * 3.1415926535f / 180.0f ) );\r
+ float c = (float) cos ( ( joy->pJoystick.js.dwPOV & 0xFFFF ) * ( 0.01 * 3.1415926535f / 180.0f ) );\r
+\r
+ /* Convert to coordinates on a square so that North-East\r
+ * is (1,1) not (.7,.7), etc.\r
+ * s and c cannot both be zero so we won't divide by zero.\r
+ */\r
+ if ( fabs ( s ) < fabs ( c ) )\r
+ {\r
+ axes [ 6 ] = ( c < 0.0 ) ? -s/c : s/c ;\r
+ axes [ 7 ] = ( c < 0.0 ) ? -1.0f : 1.0f;\r
+ }\r
+ else\r
+ {\r
+ axes [ 6 ] = ( s < 0.0 ) ? -1.0f : 1.0f;\r
+ axes [ 7 ] = ( s < 0.0 ) ? -c/s : c/s ;\r
+ }\r
+ }\r
+\r
+ case 6: axes[5] = (float) joy->pJoystick.js.dwVpos;\r
+ case 5: axes[4] = (float) joy->pJoystick.js.dwUpos;\r
+ case 4: axes[3] = (float) joy->pJoystick.js.dwRpos;\r
+ case 3: axes[2] = (float) joy->pJoystick.js.dwZpos;\r
+ case 2: axes[1] = (float) joy->pJoystick.js.dwYpos;\r
+ case 1: axes[0] = (float) joy->pJoystick.js.dwXpos;\r
+ }\r
+ }\r
+}\r
+\r
+\r
+\r