Go to the documentation of this file.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
00028 #include "internal.h"
00029
00030 #include <stdlib.h>
00031
00032
00036
00037
00038
00039 static float normalizeAxis(DWORD pos, DWORD min, DWORD max)
00040 {
00041 float fpos = (float) pos;
00042 float fmin = (float) min;
00043 float fmax = (float) max;
00044
00045 return (2.f * (fpos - fmin) / (fmax - fmin)) - 1.f;
00046 }
00047
00048
00052
00053
00054
00055 void _glfwInitJoysticks(void)
00056 {
00057 }
00058
00059
00060
00061 void _glfwTerminateJoysticks(void)
00062 {
00063 int i;
00064
00065 for (i = 0; i < GLFW_JOYSTICK_LAST; i++)
00066 free(_glfw.winmm_js[i].name);
00067 }
00068
00069
00073
00074 int _glfwPlatformJoystickPresent(int joy)
00075 {
00076 JOYINFO ji;
00077
00078 if (_glfw_joyGetPos(joy, &ji) != JOYERR_NOERROR)
00079 return GL_FALSE;
00080
00081 return GL_TRUE;
00082 }
00083
00084 const float* _glfwPlatformGetJoystickAxes(int joy, int* count)
00085 {
00086 JOYCAPS jc;
00087 JOYINFOEX ji;
00088 float* axes = _glfw.winmm_js[joy].axes;
00089
00090 if (_glfw_joyGetDevCaps(joy, &jc, sizeof(JOYCAPS)) != JOYERR_NOERROR)
00091 return NULL;
00092
00093 ji.dwSize = sizeof(JOYINFOEX);
00094 ji.dwFlags = JOY_RETURNX | JOY_RETURNY | JOY_RETURNZ |
00095 JOY_RETURNR | JOY_RETURNU | JOY_RETURNV;
00096 if (_glfw_joyGetPosEx(joy, &ji) != JOYERR_NOERROR)
00097 return NULL;
00098
00099 axes[(*count)++] = normalizeAxis(ji.dwXpos, jc.wXmin, jc.wXmax);
00100 axes[(*count)++] = normalizeAxis(ji.dwYpos, jc.wYmin, jc.wYmax);
00101
00102 if (jc.wCaps & JOYCAPS_HASZ)
00103 axes[(*count)++] = normalizeAxis(ji.dwZpos, jc.wZmin, jc.wZmax);
00104
00105 if (jc.wCaps & JOYCAPS_HASR)
00106 axes[(*count)++] = normalizeAxis(ji.dwRpos, jc.wRmin, jc.wRmax);
00107
00108 if (jc.wCaps & JOYCAPS_HASU)
00109 axes[(*count)++] = normalizeAxis(ji.dwUpos, jc.wUmin, jc.wUmax);
00110
00111 if (jc.wCaps & JOYCAPS_HASV)
00112 axes[(*count)++] = normalizeAxis(ji.dwVpos, jc.wVmin, jc.wVmax);
00113
00114 return axes;
00115 }
00116
00117 const unsigned char* _glfwPlatformGetJoystickButtons(int joy, int* count)
00118 {
00119 JOYCAPS jc;
00120 JOYINFOEX ji;
00121 unsigned char* buttons = _glfw.winmm_js[joy].buttons;
00122
00123 if (_glfw_joyGetDevCaps(joy, &jc, sizeof(JOYCAPS)) != JOYERR_NOERROR)
00124 return NULL;
00125
00126 ji.dwSize = sizeof(JOYINFOEX);
00127 ji.dwFlags = JOY_RETURNBUTTONS | JOY_RETURNPOV;
00128 if (_glfw_joyGetPosEx(joy, &ji) != JOYERR_NOERROR)
00129 return NULL;
00130
00131 while (*count < (int) jc.wNumButtons)
00132 {
00133 buttons[*count] = (unsigned char)
00134 (ji.dwButtons & (1UL << *count) ? GLFW_PRESS : GLFW_RELEASE);
00135 (*count)++;
00136 }
00137
00138
00139
00140
00141
00142
00143 if ((jc.wCaps & JOYCAPS_HASPOV) && (jc.wCaps & JOYCAPS_POV4DIR))
00144 {
00145 int i, value = ji.dwPOV / 100 / 45;
00146
00147
00148 const int directions[9] = { 1, 3, 2, 6, 4, 12, 8, 9, 0 };
00149
00150 if (value < 0 || value > 8)
00151 value = 8;
00152
00153 for (i = 0; i < 4; i++)
00154 {
00155 if (directions[value] & (1 << i))
00156 buttons[(*count)++] = GLFW_PRESS;
00157 else
00158 buttons[(*count)++] = GLFW_RELEASE;
00159 }
00160 }
00161
00162 return buttons;
00163 }
00164
00165 const char* _glfwPlatformGetJoystickName(int joy)
00166 {
00167 JOYCAPS jc;
00168
00169 if (_glfw_joyGetDevCaps(joy, &jc, sizeof(JOYCAPS)) != JOYERR_NOERROR)
00170 return NULL;
00171
00172 free(_glfw.winmm_js[joy].name);
00173 _glfw.winmm_js[joy].name = _glfwCreateUTF8FromWideString(jc.szPname);
00174
00175 return _glfw.winmm_js[joy].name;
00176 }
00177