49 m_joystickEnabled =
false;
56 updateJoysticksState();
57 updateKeyboardState();
64 return getAnyTrueValInArray(m_keysDown, k_KEYS_LENGTH);
70 return getAnyTrueValInArray(m_keysUp, k_KEYS_LENGTH);
76 return m_keysDown[key_code];
82 return m_keysUp[key_code];
88 m_mouseWheelVelocity = wheel_velocity;
94 return m_mouseWheelVelocity;
100 m_mousePosition->
x = mouse_position.
x;
101 m_mousePosition->
y = mouse_position.
y;
107 return m_mousePosition;
113 return getAnyTrueValInArray(m_mouseButtonsDown, k_MBUTTONS_LENGTH);
119 return getAnyTrueValInArray(m_mouseButtonsUp, k_MBUTTONS_LENGTH);
125 return m_mouseButtonsDown[button_number];
131 return m_mouseButtonsUp[button_number];
136 void InputManager::clearBoolArray(
bool bool_array[],
int array_length) {
137 for (
int i = 0; i < array_length; i++) {
138 bool_array[i] =
false;
144 void InputManager::resetStates() {
145 for(
int i = 0; i < k_KEYS_LENGTH; i++) {
146 m_previousKeysDown[i] = m_keysDown[i];
148 clearBoolArray(m_keysDown, k_KEYS_LENGTH);
149 clearBoolArray(m_keysUp, k_KEYS_LENGTH);
150 clearBoolArray(m_mouseButtonsDown, k_MBUTTONS_LENGTH);
151 clearBoolArray(m_mouseButtonsUp, k_MBUTTONS_LENGTH);
152 clearBoolArray(m_joystickButtonsDown, k_JOYBUTTONS_LENGTH);
159 void InputManager::updateJoysticksState() {
160 if (!m_joystickEnabled) {
166 ZeroMemory(&joyinfo,
sizeof(joyinfo));
168 joyinfo.dwSize =
sizeof(joyinfo);
169 joyinfo.dwFlags = JOY_RETURNALL|JOY_RETURNPOVCTS;
170 joyGetPosEx(0, &joyinfo);
179 if (joyinfo.dwButtonNumber > 0) {
180 setJoystickPressedButtonsCount(joyinfo.dwButtonNumber);
182 std::bitset<32> ba((
int)joyinfo.dwButtons);
183 std::string bit_array_as_string = ba.to_string();
185 unsigned short current_button = 0;
187 for (
unsigned int i = bit_array_as_string.length() - 1; i > bit_array_as_string.length() - k_JOYBUTTONS_LENGTH; i--) {
188 if (bit_array_as_string[i] ==
'1') {
189 m_joystickButtonsDown[current_button] =
true;
198 void InputManager::updateKeyboardState() {
199 bool m_previousKeyState;
200 for (
unsigned int i = 0; i < k_KEYS_LENGTH; i++) {
201 m_previousKeyState = m_previousKeysDown[i];
202 m_keysDown[i] = (GetAsyncKeyState(i) & 0x8000) != 0;
204 if(m_previousKeyState ==
true && m_previousKeyState != m_keysDown[i]) {
208 clearBoolArray(m_previousKeysDown, k_KEYS_LENGTH);
213 void InputManager::updateMouseState() {
217 if (GetCursorPos(&point)) {
218 if(GetWindowRect(GetActiveWindow(), &rect)) {
219 if(PtInRect(&rect, point)) {
220 m_mousePosition->
x = point.x;
221 m_mousePosition->
y = point.y;
226 m_mouseButtonsDown[
LeftButton] = GetAsyncKeyState(VK_LBUTTON) < 0;
227 m_mouseButtonsDown[
MiddleButton] = GetAsyncKeyState(VK_MBUTTON) < 0;
228 m_mouseButtonsDown[
RightButton] = GetAsyncKeyState(VK_RBUTTON) < 0;
233 bool InputManager::getAnyTrueValInArray(
bool bool_array[],
int array_length) {
234 for (
int i = 0; i < array_length; i++) {
245 if (joySetCapture(handler, JOYSTICKID1, NULL, TRUE)) {
250 m_joystickEnabled =
true;
257 return getAnyTrueValInArray(m_joystickButtonsDown, k_JOYBUTTONS_LENGTH);
263 return m_joystickButtonsDown[button_number - 1];
276 return m_joystickPressedButtonsCount;
281 void InputManager::setJoystickPressedButtonsCount(
int buttons_count) {
282 m_joystickPressedButtonsCount = buttons_count;
290 float velocity = fabs((
float)(ushort_half_value - raw_value));
291 velocity /= ushort_half_value;
293 if (raw_value < ushort_half_value) {
303 return m_leftJoystick;
309 return m_rightJoystick;
static float roundCeil(float value, int decimal_places)